@@ -115,6 +115,9 @@ func (client Client) Chat(model string, messages []Message) (*Message, error) {
115
115
}
116
116
return nil , errors .New (errorMessage )
117
117
}
118
+ if len (res .Choices ) == 0 {
119
+ return & Message {}, nil
120
+ }
118
121
return & res .Choices [0 ].Message , nil
119
122
}
120
123
@@ -148,6 +151,9 @@ func (client Client) EasyChat(model string, prompt string, message string) (stri
148
151
}
149
152
return "" , errors .New (errorMessage )
150
153
}
154
+ if len (res .Choices ) == 0 {
155
+ return "" , nil
156
+ }
151
157
return res .Choices [0 ].Message .Content , nil
152
158
}
153
159
@@ -203,6 +209,9 @@ func (client Client) ChatStream(model string, messages []Message, during func(st
203
209
if e != nil {
204
210
return e
205
211
}
212
+ if len (_json .Choices ) == 0 {
213
+ continue
214
+ }
206
215
during (_json .Choices [0 ].Delta .Content )
207
216
}
208
217
return nil
@@ -231,6 +240,9 @@ func (client Client) ChatWithConfig(config ChatRequest) (*Message, error) {
231
240
}
232
241
return nil , errors .New (errorMessage )
233
242
}
243
+ if len (res .Choices ) == 0 {
244
+ return & Message {}, nil
245
+ }
234
246
return & res .Choices [0 ].Message , nil
235
247
}
236
248
@@ -274,6 +286,9 @@ func (client Client) ChatStreamWithConfig(config ChatRequest, during func(string
274
286
if e != nil {
275
287
return e
276
288
}
289
+ if len (_json .Choices ) == 0 {
290
+ continue
291
+ }
277
292
during (_json .Choices [0 ].Delta .Content )
278
293
}
279
294
return nil
@@ -331,6 +346,9 @@ func (client Client) ChatReasonStream(model string, messages []Message, think fu
331
346
if e != nil {
332
347
return e
333
348
}
349
+ if len (_json .Choices ) == 0 {
350
+ continue
351
+ }
334
352
if _json .Choices [0 ].Delta .ReasoningContent != "" {
335
353
think (_json .Choices [0 ].Delta .ReasoningContent )
336
354
}
0 commit comments