Files
chatgpt-dingtalk/pkg/cache/user_context.go
2023-04-11 10:34:53 +08:00

23 lines
740 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cache
import "github.com/patrickmn/go-cache"
// SetUserSessionContext 设置用户会话上下文文本question用户提问内容GPT回复内容
func (s *UserService) SetUserSessionContext(userId string, content string) {
s.cache.Set(userId+"_content", content, cache.DefaultExpiration)
}
// GetUserSessionContext 获取用户会话上下文文本
func (s *UserService) GetUserSessionContext(userId string) string {
sessionContext, ok := s.cache.Get(userId + "_content")
if !ok {
return ""
}
return sessionContext.(string)
}
// ClearUserSessionContext 清空GPT上下文接收文本中包含 SessionClearToken
func (s *UserService) ClearUserSessionContext(userId string) {
s.cache.Delete(userId + "_content")
}