Skip to content

Commit 2489a6d

Browse files
committed
Log response ID and token usage of queries to be able to fetch additional data from the provider after evaluation
Part of #347
1 parent f0ace4d commit 2489a6d

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

model/llm/llm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (m *Model) query(logger *log.Logger, request string) (queryResult *provider
339339
return err
340340
}
341341
duration = time.Since(start)
342-
logger.Info("model responded", "model", m.ID(), "id", id, "duration", duration.Milliseconds(), "response", string(bytesutil.PrefixLines([]byte(queryResult.Message), []byte("\t"))))
342+
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"))))
343343

344344
return nil
345345
},

provider/openai-api/query.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func QueryOpenAIAPIModel(ctx context.Context, client *openai.Client, modelIdenti
3838
}
3939

4040
return &provider.QueryResult{
41-
Message: apiResponse.Choices[0].Message.Content,
42-
Usage: apiResponse.Usage,
41+
ResponseID: apiResponse.ID,
42+
Message: apiResponse.Choices[0].Message.Content,
43+
Usage: apiResponse.Usage,
4344
}, nil
4445
}

provider/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type InjectToken interface {
4646

4747
// QueryResult holds the result of a query.
4848
type QueryResult struct {
49+
// ResponseID holds the response ID.
50+
ResponseID string
4951
// Message holds the response message.
5052
Message string
5153
// Duration holds the duration of the result.

0 commit comments

Comments
 (0)