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