ai_scheduler/internal/biz/chat_history.go

58 lines
1.5 KiB
Go

package biz
import (
"ai_scheduler/internal/data/impl"
"ai_scheduler/internal/data/model"
"ai_scheduler/internal/entitys"
"context"
"xorm.io/builder"
)
type ChatHistoryBiz struct {
chatRepo *impl.ChatImpl
}
func NewChatHistoryBiz(chatRepo *impl.ChatImpl) *ChatHistoryBiz {
s := &ChatHistoryBiz{
chatRepo: chatRepo,
}
//go s.AsyncProcess(context.Background())
return s
}
//func (s *ChatHistoryBiz) create(ctx context.Context, sessionID, role, content string) error {
// chat := model.AiChatHi{
// SessionID: sessionID,
// Role: role,
// Content: content,
// }
//
// return s.chatRepo.Create(&chat)
//}
//
//// 添加会话历史
//func (s *ChatHistoryBiz) Create(ctx context.Context, chat entitys.ChatHistory) error {
// return s.create(ctx, chat.SessionID, chat.Role.String(), chat.Content)
//}
// 异步添加会话历史
//func (s *ChatHistoryBiz) AsyncCreate(ctx context.Context, chat entitys.ChatHistory) {
// s.chatRepo.AsyncCreate(ctx, model.AiChatHi{
// SessionID: chat.SessionID,
// Role: chat.Role.String(),
// Content: chat.Content,
// })
//}
// 异步处理会话历史
//func (s *ChatHistoryBiz) AsyncProcess(ctx context.Context) {
// s.chatRepo.AsyncProcess(ctx)
//}
func (s *ChatHistoryBiz) Update(ctx context.Context, chat *entitys.UseFulRequest) error {
cond := builder.NewCond()
cond = cond.And(builder.Eq{"his_id": chat.HisId})
return s.chatRepo.UpdateByCond(&cond, &model.AiChatHi{HisID: chat.HisId, Useful: chat.Useful})
}