feat: M0-08 admin AI Gateway status AAPI
Some checks failed
Deploy API Server / build-and-deploy (push) Has been cancelled

This commit is contained in:
WangDL 2026-05-23 09:34:55 +08:00
parent 2bd416c807
commit 5cd4e1ec5a

View File

@ -1,45 +1,39 @@
import { Controller, Post, Get, Body } from '@nestjs/common'; import { Controller, Get, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger'; import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { ActiveRecallAnalysisWorkflow } from './workflows/active-recall-analysis.workflow';
import { ModelRouter } from './model-router'; import { ModelRouter } from './model-router';
import { Public } from '../../common/decorators/public.decorator'; import { PromptTemplateService } from './prompts/prompt-template.service';
import { AiUsageLogService } from './usage/ai-usage-log.service';
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
import { AdminRolesGuard } from '../../common/guards/admin-roles.guard';
import { AdminRoles } from '../../common/decorators/admin-roles.decorator';
import type { AdminRole } from '../../common/types/admin-role.enum';
@ApiTags('ai') @ApiTags('admin-ai-gateway')
@Controller('ai') @Controller('admin-api/ai-gateway')
export class AiController { @UseGuards(AdminAuthGuard, AdminRolesGuard)
@ApiBearerAuth()
export class AdminAiGatewayController {
constructor( constructor(
private readonly workflow: ActiveRecallAnalysisWorkflow, private readonly router: ModelRouter,
private readonly modelRouter: ModelRouter, private readonly prompts: PromptTemplateService,
private readonly usage: AiUsageLogService,
) {} ) {}
@Post('analyze-recall') @Get('status')
@ApiOperation({ summary: '分析主动回忆回答' }) @AdminRoles('SUPER_ADMIN' as AdminRole)
async analyzeRecall(@Body() body: { @ApiOperation({ summary: 'AI Gateway 状态' })
questionText: string; async status() {
knowledgeItemContent: string; return {
userAnswer: string; providers: ['deepseek', 'minimax'],
userId?: string; tiers: this.router['tiers'],
}) { prompts: this.prompts.list?.() || [],
return this.workflow.execute({ };
userId: body.userId || 'anonymous',
questionText: body.questionText,
knowledgeItemContent: body.knowledgeItemContent,
userAnswer: body.userAnswer,
});
} }
@Public() @Get('usage')
@Get('models') @AdminRoles('SUPER_ADMIN' as AdminRole)
@ApiOperation({ summary: '查看可用模型与分流策略' }) @ApiOperation({ summary: 'AI 调用日志' })
getModels() { async usageLog() {
return ['cheap', 'primary', 'strong'].map((tier) => { return this.usage['prisma']?.aiUsageLog?.findMany?.({ orderBy: { createdAt: 'desc' }, take: 50 }) || [];
const config = this.modelRouter.resolve(tier as any);
return {
tier,
preferred: config.preferred,
fallback: config.fallback,
maxRetries: config.maxRetries,
};
});
} }
} }