From 62e6ef7eb0ae7dcd6d7236c72dcd8c21a2505318 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Tue, 13 May 2025 13:26:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BD=E5=A4=96=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E4=B8=AD=E8=BD=ACai=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=95=B0=E6=8D=AE,=E6=B7=BB=E5=8A=A0gemini?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/generalModel/openai.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/service/generalModel/openai.go b/service/generalModel/openai.go index 6e61ab4..f5f53f2 100644 --- a/service/generalModel/openai.go +++ b/service/generalModel/openai.go @@ -141,7 +141,7 @@ func OpenAIToGeneralMassageAndSendMsgQueue(data *openai.ChatCompletionChunk, cha var apiMsg api.GenerateResponse apiMsg.Model = proto.ModelTypeSpark apiMsg.Response = data.Choices[0].Delta.Content - if data.Created < 0 { //这里由于没有返回结束标志,所以用该字段来判断 + if data.Created < 0 || data.Choices[0].FinishReason != "" { //这里由于没有返回结束标志,所以用该字段来判断 apiMsg.Done = true } else { apiMsg.Done = false @@ -286,6 +286,10 @@ func DoOpenAIForeignAICallBack(chunk openai.ChatCompletionChunk, modelParam prot // 处理国外服务器返回的模型消息 func OpenAIForeignAIResponseToGeneralMassageAndSendMsgQueue(data *proto.ReceiveMessageForeignAIRRequest) { + chunk := data.ChatCompletionChunk + imCtx := &data.IMParamContext + msgStr, _ := json.Marshal(chunk) + go dao.InsertAIStreamMsgToDB(imCtx.UserID, imCtx.SessionID, uint(imCtx.ModelID), string(msgStr), data.ModelParam.Model) //存入数据库 //转入队列 OpenAIToGeneralMassageAndSendMsgQueue(&data.ChatCompletionChunk, data.IMParamContext.Channel, data.IMParamContext.SessionID, data.IMParamContext.UserID) //保存消息,流式需要暂存消息使用redis @@ -300,7 +304,7 @@ func OpenAIForeignAIResponseToGeneralMassageAndSendMsgQueue(data *proto.ReceiveM //if PromptTokensStr != "" { // PromptTokens, _ = strconv.ParseInt(PromptTokensStr, 10, 64) //} - chunk := data.ChatCompletionChunk + if len(chunk.Choices) > 0 { if proto.Config.LOG_OUTPUT { log.Printf("openai_%s stream msg:%s\n", data.PlatForm, chunk.Choices[0].Delta.Content)