user_context.go 740 B

12345678910111213141516171819202122
  1. package cache
  2. import "github.com/patrickmn/go-cache"
  3. // SetUserSessionContext 设置用户会话上下文文本,question用户提问内容,GPT回复内容
  4. func (s *UserService) SetUserSessionContext(userId string, content string) {
  5. s.cache.Set(userId+"_content", content, cache.DefaultExpiration)
  6. }
  7. // GetUserSessionContext 获取用户会话上下文文本
  8. func (s *UserService) GetUserSessionContext(userId string) string {
  9. sessionContext, ok := s.cache.Get(userId + "_content")
  10. if !ok {
  11. return ""
  12. }
  13. return sessionContext.(string)
  14. }
  15. // ClearUserSessionContext 清空GPT上下文,接收文本中包含 SessionClearToken
  16. func (s *UserService) ClearUserSessionContext(userId string) {
  17. s.cache.Delete(userId + "_content")
  18. }