From 419e2eea49286eec238f3496a484284361028ec3 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 22 Mar 2025 15:44:19 +0800 Subject: [PATCH] =?UTF-8?q?websocket=E6=8E=A5=E5=8F=A3=E4=B8=8E=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AF=E8=BF=9B=E8=A1=8C=E8=BF=9E=E6=8E=A5,?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E5=9E=8B=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/im.go | 4 ++++ service/imService.go | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/proto/im.go b/proto/im.go index 7542a9e..6751861 100644 --- a/proto/im.go +++ b/proto/im.go @@ -12,3 +12,7 @@ type WSMessage struct { SessionID int `json:"session_id"` //应用层会话id ToID int `json:"to_id"` //接收者id } + +type ModelParam struct { + Model string `json:"model"` //模型名称 +} diff --git a/service/imService.go b/service/imService.go index 4036353..55a8dd4 100644 --- a/service/imService.go +++ b/service/imService.go @@ -77,6 +77,7 @@ func CreateGeneralMessageService(fromID, toID, msgType, sessionID int, msg strin } var client *api.Client +var actxMap map[int][]int func WSReceiveMessageService(userID, sessionID int, channel string, msg proto.WSMessage) (error, uint) { var resErr error @@ -91,9 +92,9 @@ func WSReceiveMessageService(userID, sessionID int, channel string, msg proto.WS log.Println("get ollama client error:", err) } prompt := msg.Msg - var actx []int + actx, _ := actxMap[sessionID] req := &api.GenerateRequest{ - Model: "qwen2.5-coder:latest", + Model: "qwen2.5:0.5b", Context: actx, Prompt: prompt, } @@ -107,6 +108,7 @@ func WSReceiveMessageService(userID, sessionID int, channel string, msg proto.WS robotMsg += resp.Response if resp.Done { //该消息完成 actx = resp.Context + actxMap[sessionID] = actx //创建消息 err2, msgID := CreateMessage(2, sessionID, 2, userID, robotMsg, 1) //机器人id为2,消息类型为2,状态为1 if err2 != nil {