Skip to content

Commit

Permalink
Log response ID and token usage of queries to be able to fetch additi…
Browse files Browse the repository at this point in the history
…onal data from the provider after evaluation

Part of #347
  • Loading branch information
ahumenberger committed Mar 5, 2025
1 parent f0ace4d commit 2489a6d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion model/llm/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (m *Model) query(logger *log.Logger, request string) (queryResult *provider
return err
}
duration = time.Since(start)
logger.Info("model responded", "model", m.ID(), "id", id, "duration", duration.Milliseconds(), "response", string(bytesutil.PrefixLines([]byte(queryResult.Message), []byte("\t"))))
logger.Info("model responded", "model", m.ID(), "id", id, "duration", duration.Milliseconds(), "response-id", queryResult.ResponseID, "token-input", queryResult.Usage.PromptTokens, "token-output", queryResult.Usage.CompletionTokens, "response", string(bytesutil.PrefixLines([]byte(queryResult.Message), []byte("\t"))))

return nil
},
Expand Down
5 changes: 3 additions & 2 deletions provider/openai-api/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func QueryOpenAIAPIModel(ctx context.Context, client *openai.Client, modelIdenti
}

return &provider.QueryResult{
Message: apiResponse.Choices[0].Message.Content,
Usage: apiResponse.Usage,
ResponseID: apiResponse.ID,
Message: apiResponse.Choices[0].Message.Content,
Usage: apiResponse.Usage,
}, nil
}
2 changes: 2 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type InjectToken interface {

// QueryResult holds the result of a query.
type QueryResult struct {
// ResponseID holds the response ID.
ResponseID string
// Message holds the response message.
Message string
// Duration holds the duration of the result.
Expand Down

0 comments on commit 2489a6d

Please sign in to comment.