2026-06-23 09:54:27 +00:00
|
|
|
package ai
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-06-23 16:55:10 +00:00
|
|
|
libprompt "haixun-backend/internal/library/prompt"
|
2026-06-23 09:54:27 +00:00
|
|
|
domai "haixun-backend/internal/model/ai/domain/usecase"
|
|
|
|
|
"haixun-backend/internal/svc"
|
|
|
|
|
"haixun-backend/internal/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ChatStreamLogic struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewChatStreamLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatStreamLogic {
|
|
|
|
|
return &ChatStreamLogic{ctx: ctx, svcCtx: svcCtx}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *ChatStreamLogic) ChatStream(req *types.AIChatReq, token string) (<-chan domai.StreamEvent, error) {
|
2026-06-23 16:55:10 +00:00
|
|
|
system, err := libprompt.AIChatSystem(req.System)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return l.svcCtx.AI.StreamText(l.ctx, toGenerateRequest(req, token, system))
|
2026-06-23 09:54:27 +00:00
|
|
|
}
|