fix:session
This commit is contained in:
parent
f9e32e3023
commit
e57997f51b
|
@ -2,11 +2,11 @@ package biz
|
|||
|
||||
import (
|
||||
"ai_scheduler/internal/data/constants"
|
||||
errorcode "ai_scheduler/internal/data/error"
|
||||
"ai_scheduler/internal/data/impl"
|
||||
"ai_scheduler/internal/data/model"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2/utils"
|
||||
"time"
|
||||
|
||||
|
@ -21,10 +21,11 @@ type SessionBiz struct {
|
|||
conf *config.Config
|
||||
}
|
||||
|
||||
func NewSessionBiz(conf *config.Config, sessionImpl *impl.SessionImpl, sysImpl *impl.SysImpl) *SessionBiz {
|
||||
func NewSessionBiz(conf *config.Config, sessionImpl *impl.SessionImpl, sysImpl *impl.SysImpl, chatImpl *impl.ChatImpl) *SessionBiz {
|
||||
return &SessionBiz{
|
||||
sessionRepo: sessionImpl,
|
||||
sysRepo: sysImpl,
|
||||
chatRepo: chatImpl,
|
||||
conf: conf,
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +38,7 @@ func (s *SessionBiz) SessionInit(ctx context.Context, req *entitys.SessionInitRe
|
|||
if err != nil {
|
||||
return
|
||||
} else if !has {
|
||||
err = fmt.Errorf("sys not found")
|
||||
err = errorcode.SysNotFound
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -72,6 +73,7 @@ func (s *SessionBiz) SessionInit(ctx context.Context, req *entitys.SessionInitRe
|
|||
Content: sysConfig.Prologue,
|
||||
}
|
||||
result.Chat = append(result.Chat, chat)
|
||||
result.SessionId = session.SessionID
|
||||
|
||||
// 开场白写入会话历史
|
||||
s.chatRepo.AsyncCreate(ctx, model.AiChatHi{
|
||||
|
@ -81,6 +83,7 @@ func (s *SessionBiz) SessionInit(ctx context.Context, req *entitys.SessionInitRe
|
|||
})
|
||||
|
||||
} else {
|
||||
result.SessionId = session.SessionID
|
||||
// 存在,返回会话历史
|
||||
var chatList []model.AiChatHi
|
||||
chatList, err = s.chatRepo.FindAll(
|
||||
|
|
|
@ -9,13 +9,13 @@ import (
|
|||
|
||||
type SysImpl struct {
|
||||
dataTemp.DataTemp
|
||||
BaseModel[model.AiSy]
|
||||
BaseRepository[model.AiSy]
|
||||
}
|
||||
|
||||
func NewSysImpl(db *utils.Db) *SysImpl {
|
||||
return &SysImpl{
|
||||
DataTemp: *dataTemp.NewDataTemp(db, new(model.AiSy)),
|
||||
BaseModel: BaseModel[model.AiSy]{},
|
||||
BaseRepository: NewBaseModel[model.AiSy](db.Client),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ type SessionInitRequest struct {
|
|||
}
|
||||
|
||||
type SessionInitResponse struct {
|
||||
SessionId string `json:"session_id"`
|
||||
Chat []ChatHistory `json:"chat"`
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ func handRes(c *fiber.Ctx, _err error, rsp interface{}) error {
|
|||
}
|
||||
|
||||
body := fiber.Map{
|
||||
"code": err.Code,
|
||||
"code": err.Code(),
|
||||
"msg": err.Error(),
|
||||
"data": rsp,
|
||||
}
|
||||
|
||||
log.Info(c.UserContext(), c.Path(), "请求参数=", c.BodyRaw(), "响应=", body)
|
||||
log.Info(c.UserContext(), c.Path(), "请求参数=", string(c.BodyRaw()), "响应=", body)
|
||||
return c.JSON(body)
|
||||
}
|
||||
|
|
|
@ -27,7 +27,11 @@ func (s *SessionService) SessionInit(c *fiber.Ctx) error {
|
|||
|
||||
result, err := s.sessionBiz.SessionInit(c.Context(), req)
|
||||
|
||||
return handRes(c, err, result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(result)
|
||||
}
|
||||
|
||||
// SessionList 获取会话列表
|
||||
|
@ -39,7 +43,11 @@ func (s *SessionService) SessionList(c *fiber.Ctx) error {
|
|||
|
||||
sessionList, err := s.sessionBiz.SessionList(c.Context(), req)
|
||||
|
||||
return handRes(c, err, fiber.Map{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"session_list": sessionList,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue