From 5c57689700147bb663143b3f3c867506d1a57f91 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Fri, 28 Mar 2025 10:51:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A8=A1=E5=9E=8B=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=A4=9A=E8=BD=AE=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E6=9C=80=E5=A4=9A=E5=8E=86=E5=8F=B2=E6=9D=A1=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=8E=86=E5=8F=B2=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E5=A4=AA=E5=A4=9A=E5=8D=A0=E7=94=A8=E8=BF=87=E5=A4=9Atoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/im.go | 7 ++++++- proto/status.go | 6 ++++++ service/doubao.go | 4 ++++ service/spark.go | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/proto/im.go b/proto/im.go index 0cabe7b..34247c2 100644 --- a/proto/im.go +++ b/proto/im.go @@ -33,7 +33,12 @@ type ModelParam struct { APPID string `json:"appid"` //应用id APISecret string `json:"apiSecret"` //应用密钥 APIKey string `json:"apiKey"` //应用key - System string `json:"system"` //系统参数 + System string `json:"system"` // + //其他参数 + Temperature float64 `json:"temperature"` //温度,默认0.5,核采样阈值。取值越高随机性越强,即相同的问题得到的不同答案的可能性越大 + MaxTokens int `json:"maxTokens"` //最大生成长度,默认4096 + TopK float64 `json:"topK"` //取概率最大的前k个词 + TopP float64 `json:"topP"` //取 } type SessionResponse struct { diff --git a/proto/status.go b/proto/status.go index 8f7a148..4327d56 100644 --- a/proto/status.go +++ b/proto/status.go @@ -124,3 +124,9 @@ const ( ModelTypeDouBao = "doubao" ModelTypeOllama = "ollama" ) + +// 其它 +const ( + SparkContextLength = 6 + DouBaoContextLength = 6 +) diff --git a/service/doubao.go b/service/doubao.go index 9a40975..9c19cba 100644 --- a/service/doubao.go +++ b/service/doubao.go @@ -116,6 +116,10 @@ func GetDouBaoSessionHistoryMsg(sessionID int, systemPrompt string, messages *[] } //获取该会话的历史消息 msgs := dao.FindMessageBySessionIDV2(sessionID) + if len(msgs) > proto.DouBaoContextLength { + //只取最后的 SparkContextLength 条消息 + msgs = msgs[len(msgs)-proto.DouBaoContextLength-1:] + } for _, v := range msgs { var message model.ChatCompletionMessage if v.Type == proto.UserToModelMsgType { diff --git a/service/spark.go b/service/spark.go index ef43442..65aabb2 100644 --- a/service/spark.go +++ b/service/spark.go @@ -290,6 +290,10 @@ func readResp(resp *http.Response) string { func GetSparkSessionHistoryMsg(sessionID int, systemPrompt string, messages *[]MessageContent, prompt string) error { //获取会话的历史消息 msgs := dao.FindMessageBySessionIDV2(sessionID) + if len(msgs) > proto.SparkContextLength { + //只取最后的 SparkContextLength 条消息 + msgs = msgs[len(msgs)-proto.SparkContextLength-1:] + } //添加系统消息 if systemPrompt != "" { var message MessageContent