api-server/src/modules/ai/workflows/active-recall-analysis.workflow.ts
WangDL 007b56dad5
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 1m0s
feat: AI三层架构 + 全局JwtAuthGuard + 12个Repository迁Prisma
- AI: 新三层架构 Provider→Gateway→Workflow(15文件,DeepSeek+MiniMax)
- Auth: 全局JwtAuthGuard + @Public()装饰器白名单路由
- DB: 12个Repository从Map/Array迁到Prisma
- Schema: 新增AiUsageLog、WaitlistEntry模型
- API: /api-docs-json加Basic Auth保护
- 清理: 删除infrastructure/ai、docs/旧文档

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-17 00:39:46 +08:00

43 lines
1.3 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { AiGatewayService } from '../gateway/ai-gateway.service';
import { ActiveRecallAnalysisResultSchema } from '../prompts/schemas/active-recall-analysis.schema';
import type { ActiveRecallAnalysisResult } from '../prompts/schemas/active-recall-analysis.schema';
export interface ActiveRecallAnalysisInput {
userId: string;
questionText: string;
knowledgeItemContent: string;
userAnswer: string;
}
@Injectable()
export class ActiveRecallAnalysisWorkflow {
constructor(private readonly gateway: AiGatewayService) {}
async execute(input: ActiveRecallAnalysisInput): Promise<ActiveRecallAnalysisResult> {
const userMessage = [
`【知识点原文】`,
input.knowledgeItemContent,
'',
`【用户的主动回忆回答】`,
input.userAnswer,
'',
`请根据以上内容进行分析。`,
].join('\n');
const response = await this.gateway.generate({
feature: 'active-recall-analysis',
userId: input.userId,
tier: 'primary',
promptKey: 'active-recall-analysis',
promptVersion: '1.0.0',
messages: [
{ role: 'user', content: userMessage },
],
outputSchema: ActiveRecallAnalysisResultSchema,
});
return response.parsed as unknown as ActiveRecallAnalysisResult;
}
}