log duration of llm
Build and Push Docker Image / build-and-push (push) Successful in 3m42s

Signed-off-by: kaedwen <kaedwen@heinrich.blue>
This commit is contained in:
kaedwen
2026-07-09 23:11:33 +02:00
parent 4fc977a680
commit f02b6d0c40
+16 -4
View File
@@ -8,6 +8,7 @@ import (
"io"
"log/slog"
"net/http"
"time"
"github.com/pheinrich/aitrade/pkg/config"
"github.com/pheinrich/aitrade/pkg/model"
@@ -167,7 +168,16 @@ JSON Response:`, article.Title, article.Content)
}
// callOllamaAPI sends request to Ollama API and parses response
func (l *LLMScorer) callOllamaAPI(ctx context.Context, prompt string) (*SentimentResponse, error) {
func (l *LLMScorer) callOllamaAPI(ctx context.Context, prompt string) (sentiment *SentimentResponse, err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
l.logger.Info("LLM request completed",
slog.Duration("duration", duration),
slog.String("model", l.cfg.ModelName),
slog.Bool("success", err == nil))
}()
// Build request
reqBody := LLMRequest{
Model: l.cfg.ModelName,
@@ -197,7 +207,8 @@ func (l *LLMScorer) callOllamaAPI(ctx context.Context, prompt string) (*Sentimen
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("Ollama API returned status %d: %s", resp.StatusCode, string(body))
err = fmt.Errorf("Ollama API returned status %d: %s", resp.StatusCode, string(body))
return nil, err
}
// Read response
@@ -207,12 +218,13 @@ func (l *LLMScorer) callOllamaAPI(ctx context.Context, prompt string) (*Sentimen
}
var llmResp LLMResponse
if err := json.Unmarshal(body, &llmResp); err != nil {
if err = json.Unmarshal(body, &llmResp); err != nil {
return nil, fmt.Errorf("failed to parse Ollama response: %w", err)
}
// Parse sentiment from LLM response
return l.parseSentiment(llmResp.Response)
sentiment, err = l.parseSentiment(llmResp.Response)
return
}
// parseSentiment extracts structured sentiment from LLM text response