Skip to content

Commit

Permalink
Add request model to chat completion message (newrelic#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirackara committed Mar 27, 2024
1 parent 3ecd852 commit 8bfcbfc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions v3/integrations/nropenai/nropenai.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func NRCreateChatCompletionSummary(txn *newrelic.Transaction, app *newrelic.Appl
// Capture request message, returns a sequence of the messages already sent in the request. We will use that during the response message counting
sequence := NRCreateChatCompletionMessageInput(txn, app, req, uuid, cw)
// Capture completion messages
NRCreateChatCompletionMessage(txn, app, resp, uuid, cw, sequence)
NRCreateChatCompletionMessage(txn, app, resp, uuid, cw, sequence, req)
chatCompletionSpan.End()

txn.End()
Expand Down Expand Up @@ -349,7 +349,7 @@ func NRCreateChatCompletionMessageInput(txn *newrelic.Transaction, app *newrelic
}

// NRCreateChatCompletionMessage captures the completion response messages and records a custom event in New Relic for each message
func NRCreateChatCompletionMessage(txn *newrelic.Transaction, app *newrelic.Application, resp openai.ChatCompletionResponse, uuid uuid.UUID, cw *ClientWrapper, sequence int) {
func NRCreateChatCompletionMessage(txn *newrelic.Transaction, app *newrelic.Application, resp openai.ChatCompletionResponse, uuid uuid.UUID, cw *ClientWrapper, sequence int, req openai.ChatCompletionRequest) {
spanID := txn.GetTraceMetadata().SpanID
traceID := txn.GetTraceMetadata().TraceID
appCfg, _ := app.Config()
Expand All @@ -365,6 +365,9 @@ func NRCreateChatCompletionMessage(txn *newrelic.Transaction, app *newrelic.Appl
ChatCompletionMessageData["id"] = resp.ID
}

// Request Data
ChatCompletionMessageData["request.model"] = req.Model

// Response Data
ChatCompletionMessageData["response.model"] = resp.Model

Expand Down

0 comments on commit 8bfcbfc

Please sign in to comment.