尽量使用同一个代理访问,如果挂了再使用下一个

This commit is contained in:
RockYang
2023-03-31 22:35:05 +08:00
parent a4469b23df
commit 4d52f02b80
3 changed files with 11 additions and 7 deletions

View File

@@ -15,5 +15,6 @@
* [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片
* [x] 点卡用完之后,提示加入知识星球
* [ ] 增加 Buffer 层,将相同的问题答案缓存起来,相同问题直接返回答案。
* [ ] 界面改版,支持创建会话功能,支持发语音
* [x] 允许修改角色训练数据

View File

@@ -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,12 +222,15 @@ 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)
// 更新上下文消息
if s.Config.Chat.EnableContext {
context = append(context, message)
s.ChatContexts[ctxKey] = types.ChatContext{
Messages: context,
LastAccessTime: time.Now().Unix(),
}
}
// 追加历史消息
if user.EnableHistory {
@@ -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()

View File

@@ -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