add config api for setting the ChatContextExpireTime

This commit is contained in:
RockYang 2023-03-28 18:16:05 +08:00
parent cb2b01127b
commit eb562ea3c9
2 changed files with 2 additions and 2 deletions

View File

@ -6,7 +6,7 @@
* [x] 使用 level DB 保存用户聊天记录
* [x] 用户聊天鉴权,设置口令模式
* [ ] 定期清理不在线的会话 sessionID 和聊天上下文记录
* [x] 定期清理不在线的会话 sessionID 和聊天上下文记录
* [x] 给 Token 设置调用次数
* [x] OpenAI API 负载均衡,限制每个 API Key 每分钟之内调用次数不超过 15次防止被封
* [x] 角色设定,预设一些角色,比如程序员,客服,作家,老师,艺术家...

View File

@ -117,7 +117,7 @@ func (s *Server) Run(webRoot embed.FS, path string, debug bool) {
for {
for key, context := range s.ChatContexts {
// 清理超过 60min 没有更新,则表示为过期会话
if time.Now().Unix()-context.LastAccessTime > 3600 {
if time.Now().Unix()-context.LastAccessTime > int64(s.Config.Chat.ChatContextExpireTime) {
logger.Infof("清理会话上下文: %s", key)
delete(s.ChatContexts, key)
}