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