From 13bcffa72d18f9afb882345e8ab84efa60cee666 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Tue, 1 Apr 2025 14:28:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0doubao=20=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/im.go | 15 ++++++++------- service/doubao.go | 8 +++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/proto/im.go b/proto/im.go index 0b3edbe..00179b7 100644 --- a/proto/im.go +++ b/proto/im.go @@ -68,13 +68,14 @@ type SessionResponse struct { } type IMParamContext struct { - UserID int `json:"user_id"` //用户id - SessionID int `json:"session_id"` //会话id - FunctionID int `json:"function_id"` //功能id - ModelID int `json:"model_id"` //模型id - ModelType string `json:"model_type"` //模型类型 - Question string `json:"question"` //问题 - Channel string `json:"channel"` //消息队列 + UserID int `json:"user_id"` //用户id + SessionID int `json:"session_id"` //会话id + FunctionID int `json:"function_id"` //功能id + ModelID int `json:"model_id"` //模型id + ModelType string `json:"model_type"` //模型类型 + Question string `json:"question"` //问题 + Channel string `json:"channel"` //消息队列 + IsHasImage bool `json:"is_has_image"` //是否有图片 } // 用户向模型发送图片的消息结构 diff --git a/service/doubao.go b/service/doubao.go index 3df3cf4..93cea47 100644 --- a/service/doubao.go +++ b/service/doubao.go @@ -90,8 +90,8 @@ func DouBaoV2(modelParam proto.ModelParam, imCtx *proto.IMParamContext) { if err != nil { log.Println("get doubao session history message error:", err) } - //messagesStr, _ := json.Marshal(messages) - //log.Println("doubao messages:", string(messagesStr)) + messagesStr, _ := json.Marshal(messages) + log.Println("doubao messages:", string(messagesStr)) req := model.CreateChatCompletionRequest{ Model: modelParam.Model, @@ -137,7 +137,9 @@ func DouBaoV2(modelParam proto.ModelParam, imCtx *proto.IMParamContext) { choices := recv.Choices[0] if choices.FinishReason == proto.FinishReasonStop { answer += choices.Delta.Content - tokens += recv.Usage.TotalTokens + if recv.Usage != nil { + tokens += recv.Usage.TotalTokens + } break } else { answer += choices.Delta.Content