From 6918b8215ca9a2728d3623af806d22a7f6e047a4 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 10 May 2025 15:34:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=83=E5=B8=86=E5=A4=A7?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=B3=BB=E7=BB=9F=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=A7=E6=A8=A1=E5=9E=8B=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=8F=90=E9=97=AE=E6=B6=88=E6=81=AF=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/conf.go | 1 + service/doubao.go | 6 ++++-- service/qianfan.go | 19 ++++++++++++------- service/spark.go | 15 +++++++++------ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/proto/conf.go b/proto/conf.go index 98c2d07..d8dffff 100644 --- a/proto/conf.go +++ b/proto/conf.go @@ -77,6 +77,7 @@ type ConfigStruct struct { TOKEN_SECRET string `json:"token_secret"` CID_BASE_DIR string `json:"cid_base_dir"` FILE_BASE_DIR string `json:"file_base_dir"` + LOG_OUTPUT bool `json:"log_output"` MONITOR bool `json:"monitor"` // 状态监控及邮件通知 SERVER_SQL_LOG bool `json:"server_sql_log"` // 服务器sql日志 SERVER_PORT string `json:"server_port"` // 服务端口 diff --git a/service/doubao.go b/service/doubao.go index 4dec8ac..de6483d 100644 --- a/service/doubao.go +++ b/service/doubao.go @@ -102,8 +102,10 @@ func DouBaoV2(modelParam proto.ModelParam, imCtx *proto.IMParamContext) { IncludeUsage: true, }, } - messagesStr, _ := json.Marshal(req) - log.Println("doubao req messages:", string(messagesStr)) + if proto.Config.LOG_OUTPUT { + messagesStr, _ := json.Marshal(req) + log.Println("doubao req messages:", string(messagesStr)) + } stream, err := doubaoClient.CreateChatCompletionStream(ctx, req) if err != nil { diff --git a/service/qianfan.go b/service/qianfan.go index 774a90b..ad453ad 100644 --- a/service/qianfan.go +++ b/service/qianfan.go @@ -30,6 +30,11 @@ func Qianfan(modelParam proto.ModelParam, imCtx *proto.IMParamContext) { log.Println("GetQianfanHistoryMessages error:", err) return } + if proto.Config.LOG_OUTPUT { + messagesBytes, _ := json.Marshal(messages) + log.Println("qianfan messages:", string(messagesBytes)) + } + answer := "" tokens := 0 @@ -81,13 +86,13 @@ func GetQianfanHistoryMessages(sessionID int, systemPrompt string, messages *[]q //只取最后的 SparkContextLength 条消息 msgs = msgs[len(msgs)-proto.SparkContextLength-1:] } - //添加系统消息 - if systemPrompt != "" { - var message qianfan.ChatCompletionMessage - message.Role = "system" - message.Content = systemPrompt - *messages = append(*messages, message) - } + //添加系统消息,千帆不支持系统参数 + //if systemPrompt != "" { + // var message qianfan.ChatCompletionMessage + // message.Role = "system" + // message.Content = systemPrompt + // *messages = append(*messages, message) + //} for _, msg := range msgs { var message qianfan.ChatCompletionMessage if msg.Type == proto.UserToModelMsgType { diff --git a/service/spark.go b/service/spark.go index 0bca572..0397b53 100644 --- a/service/spark.go +++ b/service/spark.go @@ -201,12 +201,15 @@ func SparkV2(modelParam proto.ModelParam, imCtx *proto.IMParamContext) { go func() { data := genSparkParamsV2(imCtx.UserID, modelParam.APPID, modelParam.Domain, imCtx.SessionID, modelParam.System, float64(modelParam.Temperature)) //将数据转换为json - //dataByte, err3 := json.Marshal(data) - //if err3 != nil { - // fmt.Println("Error parsing JSON:", err) - // return - //} - //log.Println("spark send message:", string(dataByte)) + if proto.Config.LOG_OUTPUT { + dataByte, err3 := json.Marshal(data) + if err3 != nil { + fmt.Println("Error parsing JSON:", err) + return + } + log.Println("spark send message:", string(dataByte)) + } + err2 := conn.WriteJSON(data) if err != nil { fmt.Println("write message error:", err2)