@@ -251,18 +251,19 @@ func chatCompletionsLLM(c *gin.Context, param ChatCompletionRequest) {
251251 }
252252
253253 resWg .Wait ()
254+
255+ if err != nil {
256+ c .SSEvent ("" , map [string ]any {"error" : err .Error (), "code" : nexa_sdk .SDKErrorCode (err )})
257+ return false
258+ }
259+
254260 if param .StreamOptions .IncludeUsage .Value {
255261 c .SSEvent ("" , openai.ChatCompletionChunk {
256262 Choices : []openai.ChatCompletionChunkChoice {},
257263 Usage : profile2Usage (res .ProfileData ),
258264 })
259265 }
260-
261- if err != nil {
262- c .SSEvent ("" , map [string ]any {"error" : err .Error (), "code" : nexa_sdk .SDKErrorCode (err )})
263- } else {
264- c .SSEvent ("" , "[DONE]" )
265- }
266+ c .SSEvent ("" , "[DONE]" )
266267
267268 return false
268269 })
@@ -540,18 +541,19 @@ func chatCompletionsVLM(c *gin.Context, param ChatCompletionRequest) {
540541 }
541542
542543 resWg .Wait ()
544+
545+ if err != nil {
546+ c .SSEvent ("" , map [string ]any {"error" : err .Error (), "code" : nexa_sdk .SDKErrorCode (err )})
547+ return false
548+ }
549+
543550 if param .StreamOptions .IncludeUsage .Value {
544551 c .SSEvent ("" , openai.ChatCompletionChunk {
545552 Choices : []openai.ChatCompletionChunkChoice {},
546553 Usage : profile2Usage (res .ProfileData ),
547554 })
548555 }
549-
550- if err != nil {
551- c .SSEvent ("" , map [string ]any {"error" : err .Error (), "code" : nexa_sdk .SDKErrorCode (err )})
552- } else {
553- c .SSEvent ("" , "[DONE]" )
554- }
556+ c .SSEvent ("" , "[DONE]" )
555557
556558 return false
557559 })
0 commit comments