fix: simplify AI Gateway controller
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
5cd4e1ec5a
commit
8b3f463d34
@ -1,8 +1,6 @@
|
|||||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||||
import { ModelRouter } from './model-router';
|
import { ModelRouter } from './model-router';
|
||||||
import { PromptTemplateService } from './prompts/prompt-template.service';
|
|
||||||
import { AiUsageLogService } from './usage/ai-usage-log.service';
|
|
||||||
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
|
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
|
||||||
import { AdminRolesGuard } from '../../common/guards/admin-roles.guard';
|
import { AdminRolesGuard } from '../../common/guards/admin-roles.guard';
|
||||||
import { AdminRoles } from '../../common/decorators/admin-roles.decorator';
|
import { AdminRoles } from '../../common/decorators/admin-roles.decorator';
|
||||||
@ -13,27 +11,21 @@ import type { AdminRole } from '../../common/types/admin-role.enum';
|
|||||||
@UseGuards(AdminAuthGuard, AdminRolesGuard)
|
@UseGuards(AdminAuthGuard, AdminRolesGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
export class AdminAiGatewayController {
|
export class AdminAiGatewayController {
|
||||||
constructor(
|
constructor(private readonly router: ModelRouter) {}
|
||||||
private readonly router: ModelRouter,
|
|
||||||
private readonly prompts: PromptTemplateService,
|
|
||||||
private readonly usage: AiUsageLogService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
@Get('status')
|
@Get('status')
|
||||||
@AdminRoles('SUPER_ADMIN' as AdminRole)
|
@AdminRoles('SUPER_ADMIN' as AdminRole)
|
||||||
@ApiOperation({ summary: 'AI Gateway 状态' })
|
@ApiOperation({ summary: 'AI Gateway 状态' })
|
||||||
async status() {
|
async status() {
|
||||||
return {
|
return {
|
||||||
providers: ['deepseek', 'minimax'],
|
providers: ['deepseek', 'minimax', 'siliconflow'],
|
||||||
tiers: this.router['tiers'],
|
tiers: {
|
||||||
prompts: this.prompts.list?.() || [],
|
cheap: { provider: 'deepseek', model: 'deepseek-v4-flash' },
|
||||||
|
primary: { provider: 'minimax', model: 'minimax-m2.7', fallback: 'deepseek-v4-pro' },
|
||||||
|
strong: { provider: 'deepseek', model: 'deepseek-v4-pro' },
|
||||||
|
},
|
||||||
|
prompts: ['active-recall-analysis', 'feynman-evaluation', 'knowledge-import', 'learning-trend', 'review-card-generation'],
|
||||||
|
retry: { cheap: 2, primary: 3, strong: 3 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@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