feat: M0-08 admin AI Gateway status AAPI
Some checks failed
Deploy API Server / build-and-deploy (push) Has been cancelled
Some checks failed
Deploy API Server / build-and-deploy (push) Has been cancelled
This commit is contained in:
parent
2bd416c807
commit
5cd4e1ec5a
@ -1,45 +1,39 @@
|
||||
import { Controller, Post, Get, Body } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
||||
import { ActiveRecallAnalysisWorkflow } from './workflows/active-recall-analysis.workflow';
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
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')
|
||||
@Controller('ai')
|
||||
export class AiController {
|
||||
@ApiTags('admin-ai-gateway')
|
||||
@Controller('admin-api/ai-gateway')
|
||||
@UseGuards(AdminAuthGuard, AdminRolesGuard)
|
||||
@ApiBearerAuth()
|
||||
export class AdminAiGatewayController {
|
||||
constructor(
|
||||
private readonly workflow: ActiveRecallAnalysisWorkflow,
|
||||
private readonly modelRouter: ModelRouter,
|
||||
private readonly router: ModelRouter,
|
||||
private readonly prompts: PromptTemplateService,
|
||||
private readonly usage: AiUsageLogService,
|
||||
) {}
|
||||
|
||||
@Post('analyze-recall')
|
||||
@ApiOperation({ summary: '分析主动回忆回答' })
|
||||
async analyzeRecall(@Body() body: {
|
||||
questionText: string;
|
||||
knowledgeItemContent: string;
|
||||
userAnswer: string;
|
||||
userId?: string;
|
||||
}) {
|
||||
return this.workflow.execute({
|
||||
userId: body.userId || 'anonymous',
|
||||
questionText: body.questionText,
|
||||
knowledgeItemContent: body.knowledgeItemContent,
|
||||
userAnswer: body.userAnswer,
|
||||
});
|
||||
@Get('status')
|
||||
@AdminRoles('SUPER_ADMIN' as AdminRole)
|
||||
@ApiOperation({ summary: 'AI Gateway 状态' })
|
||||
async status() {
|
||||
return {
|
||||
providers: ['deepseek', 'minimax'],
|
||||
tiers: this.router['tiers'],
|
||||
prompts: this.prompts.list?.() || [],
|
||||
};
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Get('models')
|
||||
@ApiOperation({ summary: '查看可用模型与分流策略' })
|
||||
getModels() {
|
||||
return ['cheap', 'primary', 'strong'].map((tier) => {
|
||||
const config = this.modelRouter.resolve(tier as any);
|
||||
return {
|
||||
tier,
|
||||
preferred: config.preferred,
|
||||
fallback: config.fallback,
|
||||
maxRetries: config.maxRetries,
|
||||
};
|
||||
});
|
||||
@Get('usage')
|
||||
@AdminRoles('SUPER_ADMIN' as AdminRole)
|
||||
@ApiOperation({ summary: 'AI 调用日志' })
|
||||
async usageLog() {
|
||||
return this.usage['prisma']?.aiUsageLog?.findMany?.({ orderBy: { createdAt: 'desc' }, take: 50 }) || [];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user