Skip to content

Commit

Permalink
Fix finish reason string formatting in NRCreateChatCompletionSummary (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mirackara committed Mar 27, 2024
1 parent 6bf0dab commit b6e465e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion v3/integrations/nropenai/nropenai.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,24 @@ func NRCreateChatCompletionSummary(txn *newrelic.Transaction, app *newrelic.Appl

if len(resp.Choices) > 0 {
finishReason, err := resp.Choices[0].FinishReason.MarshalJSON()

if err != nil {
ChatCompletionSummaryData["error"] = true
txn.NoticeError(newrelic.Error{
Message: err.Error(),
Class: "OpenAIError",
})
} else {
ChatCompletionSummaryData["response.choices.finish_reason"] = string(finishReason)
s := string(finishReason)
if len(s) > 0 && s[0] == '"' {
s = s[1:]
}
if len(s) > 0 && s[len(s)-1] == '"' {
s = s[:len(s)-1]
}

// strip quotes from the finish reason before setting it
ChatCompletionSummaryData["response.choices.finish_reason"] = s
}
}

Expand Down

0 comments on commit b6e465e

Please sign in to comment.