From 4d52f02b809b335a14553cfe4a0b8068bef2c41e Mon Sep 17 00:00:00 2001 From: RockYang Date: Fri, 31 Mar 2023 22:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=BD=E9=87=8F=E4=BD=BF=E7=94=A8=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E4=BB=A3=E7=90=86=E8=AE=BF=E9=97=AE=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8C=82=E4=BA=86=E5=86=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + server/chat_handler.go | 15 +++++++++------ server/config_handler.go | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 29f5fd80..11ccf6e1 100644 --- a/README.md +++ b/README.md @@ -15,5 +15,6 @@ * [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片 * [x] 点卡用完之后,提示加入知识星球 * [ ] 增加 Buffer 层,将相同的问题答案缓存起来,相同问题直接返回答案。 +* [ ] 界面改版,支持创建会话功能,支持发语音 * [x] 允许修改角色训练数据 diff --git a/server/chat_handler.go b/server/chat_handler.go index fbf65a6d..8e6f0782 100644 --- a/server/chat_handler.go +++ b/server/chat_handler.go @@ -134,7 +134,7 @@ func (s *Server) sendMessage(session types.ChatSession, role types.ChatRole, pro time.Sleep(time.Second) continue } - logger.Infof("Use API KEY: %s", apiKey) + logger.Infof("Use API KEY: %s, PROXY: %s", apiKey, proxyURL) request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey)) response, err = client.Do(request) if err == nil { @@ -222,11 +222,14 @@ func (s *Server) sendMessage(session types.ChatSession, role types.ChatRole, pro useMsg := types.Message{Role: "user", Content: prompt} context = append(context, useMsg) message.Content = strings.Join(contents, "") - context = append(context, message) + // 更新上下文消息 - s.ChatContexts[ctxKey] = types.ChatContext{ - Messages: context, - LastAccessTime: time.Now().Unix(), + if s.Config.Chat.EnableContext { + context = append(context, message) + s.ChatContexts[ctxKey] = types.ChatContext{ + Messages: context, + LastAccessTime: time.Now().Unix(), + } } // 追加历史消息 @@ -261,7 +264,7 @@ func (s *Server) getApiKey(failedKey string) string { keys = append(keys, v) } - rand.Seed(time.Now().UnixNano()) + rand.NewSource(time.Now().UnixNano()) if len(keys) > 0 { key := keys[rand.Intn(len(keys))] s.ApiKeyAccessStat[key] = time.Now().Unix() diff --git a/server/config_handler.go b/server/config_handler.go index 62d5bb7b..bc65ac6a 100644 --- a/server/config_handler.go +++ b/server/config_handler.go @@ -354,7 +354,7 @@ func (s *Server) SetChatRoleHandle(c *gin.Context) { return } - role, err := GetChatRole(data.Key) + _, err = GetChatRole(data.Key) if err != nil { c.JSON(http.StatusOK, types.BizVo{Code: types.Failed, Message: "Role key not exists"}) return