1 Star 0 Fork 0

ghostelement/go-easy-llm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
session.go 698 Bytes
一键复制 编辑 原始数据 按行查看 历史
package service
import (
"context"
"crypto/rand"
"encoding/hex"
"sync"
)
var chatSessions = sync.Map{}
func GenerateSessionId() string {
b := make([]byte, 16)
_, err := rand.Read(b)
if err != nil {
return ""
}
// return fmt.Sprintf("%s%d", hex.EncodeToString(b), time.Now().UnixNano())
return hex.EncodeToString(b)
}
func SetChatSession(sessionId string, session context.CancelFunc) {
chatSessions.Store(sessionId, session)
}
func GetChatSession(sessionId string) context.CancelFunc {
cancelFunc, ok := chatSessions.Load(sessionId)
if ok {
return cancelFunc.(context.CancelFunc)
}
return nil
}
func RemoveChatSession(sessionId string) {
chatSessions.Delete(sessionId)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ghostelement/go-easy-llm.git
git@gitee.com:ghostelement/go-easy-llm.git
ghostelement
go-easy-llm
go-easy-llm
v0.0.304

搜索帮助