You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.5 KiB
59 lines
1.5 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package ai
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AiConversationListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取对话列表
|
|
func NewAiConversationListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AiConversationListLogic {
|
|
return &AiConversationListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *AiConversationListLogic) AiConversationList(req *types.AIConversationListRequest) (resp *types.AIConversationListResponse, err error) {
|
|
userId, _ := l.ctx.Value("userId").(int64)
|
|
if userId == 0 {
|
|
return nil, errors.New("unauthorized")
|
|
}
|
|
|
|
conversations, total, err := model.AIConversationFindByUser(l.ctx, l.svcCtx.DB, userId, req.Page, req.PageSize)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
list := make([]types.AIConversationInfo, len(conversations))
|
|
for i, c := range conversations {
|
|
list[i] = types.AIConversationInfo{
|
|
Id: c.Id,
|
|
Title: c.Title,
|
|
ModelId: c.ModelId,
|
|
ProviderId: c.ProviderId,
|
|
TotalTokens: c.TotalTokens,
|
|
TotalCost: c.TotalCost,
|
|
IsArchived: c.IsArchived,
|
|
CreatedAt: c.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: c.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}
|
|
}
|
|
|
|
return &types.AIConversationListResponse{List: list, Total: total}, nil
|
|
}
|
|
|