@@ -195,7 +195,7 @@ func (r *OpenAIRecorder) convertStreamingResponse(streamingBody string) string {
195
195
lines := strings .Split (streamingBody , "\n " )
196
196
var contentBuilder strings.Builder
197
197
var reasoningContentBuilder strings.Builder
198
- var lastChunk map [string ]interface {}
198
+ var lastChoice , lastChunk map [string ]interface {}
199
199
200
200
for _ , line := range lines {
201
201
if strings .HasPrefix (line , "data: " ) {
@@ -213,6 +213,7 @@ func (r *OpenAIRecorder) convertStreamingResponse(streamingBody string) string {
213
213
214
214
if choices , ok := chunk ["choices" ].([]interface {}); ok && len (choices ) > 0 {
215
215
if choice , ok := choices [0 ].(map [string ]interface {}); ok {
216
+ lastChoice = choice
216
217
if delta , ok := choice ["delta" ].(map [string ]interface {}); ok {
217
218
if content , ok := delta ["content" ].(string ); ok {
218
219
contentBuilder .WriteString (content )
@@ -235,6 +236,7 @@ func (r *OpenAIRecorder) convertStreamingResponse(streamingBody string) string {
235
236
for key , value := range lastChunk {
236
237
finalResponse [key ] = value
237
238
}
239
+ finalResponse ["choices" ] = []interface {}{lastChoice }
238
240
239
241
if choices , ok := finalResponse ["choices" ].([]interface {}); ok && len (choices ) > 0 {
240
242
if choice , ok := choices [0 ].(map [string ]interface {}); ok {
0 commit comments