File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import (
1313 "github.com/coder/aibridge/recorder"
1414 "github.com/google/uuid"
1515 "github.com/openai/openai-go/v3/responses"
16+ oaiconst "github.com/openai/openai-go/v3/shared/constant"
1617 "go.opentelemetry.io/otel/attribute"
1718)
1819
@@ -96,14 +97,16 @@ func (i *StreamingResponsesInterceptor) ProcessRequest(w http.ResponseWriter, r
9697 for stream .Next () {
9798 ev := stream .Current ()
9899
99- // not every event has response.id set (eg: fixtures/openai/responses/streaming/simple.txtar).
100- // first event should be of 'response.created' type and have response.id set.
101- // set responseID to response.id of first event that has this field set.
100+ // Not every event has response.id set (eg: fixtures/openai/responses/streaming/simple.txtar).
101+ // First event should be of 'response.created' type and have response.id set.
102+ // Set responseID to the first response.id that is set.
102103 if responseID == "" && ev .Response .ID != "" {
103104 responseID = ev .Response .ID
104105 }
105- // capture the final response from the response.completed event
106- if ev .Type == "response.completed" {
106+
107+ // Capture the response from the response.completed event.
108+ // Only response.completed event type have 'usage' field set.
109+ if ev .Type == string (oaiconst .ValueOf [oaiconst.ResponseCompleted ]()) {
107110 completedEvent := ev .AsResponseCompleted ()
108111 completedResponse = & completedEvent .Response
109112 }
You can’t perform that action at this time.
0 commit comments