Files
sundynix-micro-be/app/plant/api/internal/logic/ai/aiChatLogic.go
T
2026-05-23 13:55:05 +08:00

36 lines
766 B
Go

// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package ai
import (
"context"
"fmt"
"sundynix-micro-go/app/plant/api/internal/svc"
"sundynix-micro-go/app/plant/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AiChatLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// AI问答
func NewAiChatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AiChatLogic {
return &AiChatLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AiChatLogic) AiChat(req *types.AiChatReq) (string, error) {
l.Logger.Infof("AI chat request: %s", req.Question)
userID := fmt.Sprintf("%v", l.ctx.Value("userId"))
return ChatCompletion(l.ctx, l.svcCtx, userID, req.Question)
}