'use client' import { useState, useEffect } from 'react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card' import { Button } from '@/components/ui/Button' import { Input } from '@/components/ui/Input' import { Select } from '@/components/ui/Select' import { SuccessTag, ErrorTag, PendingTag } from '@/components/ui/Tag' import { Bot, Eye, Mic, Settings, CheckCircle, XCircle, Loader2, Info, Shield, AlertTriangle, RefreshCw, Clock } from 'lucide-react' // AI 服务状态类型 type ServiceStatus = 'healthy' | 'degraded' | 'error' | 'unknown' interface AIServiceHealth { status: ServiceStatus lastChecked: string | null lastError: string | null failedCount: number // 连续失败次数 queuedTasks: number // 队列中等待的任务数 } // AI 提供商选项 const providerOptions = [ { value: 'oneapi', label: 'OneAPI 中转服务' }, { value: 'anthropic', label: 'Anthropic Claude' }, { value: 'openai', label: 'OpenAI' }, { value: 'deepseek', label: 'DeepSeek' }, { value: 'custom', label: '自定义' }, ] // 模拟可用模型列表 const availableModels = { llm: [ { value: 'claude-opus-4-5-20251101', label: 'Claude Opus 4.5', tags: ['推荐', '高性能'] }, { value: 'claude-sonnet-4-20250514', label: 'Claude Sonnet 4', tags: ['性价比'] }, { value: 'gpt-4o', label: 'GPT-4o', tags: ['文字', '视觉'] }, { value: 'deepseek-chat', label: 'DeepSeek Chat', tags: ['高性价比'] }, ], vision: [ { value: 'claude-opus-4-5-20251101', label: 'Claude Opus 4.5', tags: ['推荐'] }, { value: 'gpt-4o', label: 'GPT-4o', tags: ['视觉'] }, { value: 'doubao-seed-1.6-thinking-vision', label: '豆包 Vision', tags: ['中文优化'] }, ], asr: [ { value: 'whisper-large-v3', label: 'Whisper Large V3', tags: ['推荐'] }, { value: 'whisper-medium', label: 'Whisper Medium', tags: ['快速'] }, { value: 'paraformer-zh', label: '达摩院 Paraformer', tags: ['中文优化'] }, ], } type TestResult = { llm: 'idle' | 'testing' | 'success' | 'failed' vision: 'idle' | 'testing' | 'success' | 'failed' asr: 'idle' | 'testing' | 'success' | 'failed' } export default function AIConfigPage() { const [provider, setProvider] = useState('oneapi') const [baseUrl, setBaseUrl] = useState('https://oneapi.intelligrow.cn') const [apiKey, setApiKey] = useState('') const [showApiKey, setShowApiKey] = useState(false) const [llmModel, setLlmModel] = useState('claude-opus-4-5-20251101') const [visionModel, setVisionModel] = useState('claude-opus-4-5-20251101') const [asrModel, setAsrModel] = useState('whisper-large-v3') const [temperature, setTemperature] = useState(0.7) const [maxTokens, setMaxTokens] = useState(2000) const [testResults, setTestResults] = useState({ llm: 'idle', vision: 'idle', asr: 'idle', }) // AI 服务健康状态(模拟数据,实际从后端获取) const [serviceHealth, setServiceHealth] = useState({ status: 'healthy', lastChecked: '2026-02-06 16:30:00', lastError: null, failedCount: 0, queuedTasks: 0, }) // 模拟检查服务状态 const checkServiceHealth = async () => { // 实际应该调用后端 API // const response = await fetch('/api/v1/ai-config/health') // setServiceHealth(await response.json()) // 模拟:随机返回不同状态用于演示 const now = new Date().toLocaleString('zh-CN') setServiceHealth({ status: 'healthy', lastChecked: now, lastError: null, failedCount: 0, queuedTasks: 0, }) } // 页面加载时检查服务状态 useEffect(() => { checkServiceHealth() }, []) const handleTestConnection = async () => { // 模拟测试连接 setTestResults({ llm: 'testing', vision: 'testing', asr: 'testing' }) // 模拟延迟 await new Promise(resolve => setTimeout(resolve, 1500)) setTestResults(prev => ({ ...prev, llm: 'success' })) await new Promise(resolve => setTimeout(resolve, 1000)) setTestResults(prev => ({ ...prev, vision: 'success' })) await new Promise(resolve => setTimeout(resolve, 800)) setTestResults(prev => ({ ...prev, asr: 'success' })) } const handleSave = () => { alert('配置已保存') } const getTestStatusIcon = (status: string) => { switch (status) { case 'testing': return case 'success': return case 'failed': return default: return null } } // 获取服务状态配置 const getServiceStatusConfig = (status: ServiceStatus) => { switch (status) { case 'healthy': return { label: '服务正常', color: 'text-accent-green', bgColor: 'bg-accent-green/15', borderColor: 'border-accent-green/30', icon: CheckCircle, } case 'degraded': return { label: '服务降级', color: 'text-accent-amber', bgColor: 'bg-accent-amber/15', borderColor: 'border-accent-amber/30', icon: AlertTriangle, } case 'error': return { label: '服务异常', color: 'text-accent-coral', bgColor: 'bg-accent-coral/15', borderColor: 'border-accent-coral/30', icon: XCircle, } default: return { label: '状态未知', color: 'text-text-tertiary', bgColor: 'bg-bg-elevated', borderColor: 'border-border-subtle', icon: Info, } } } const statusConfig = getServiceStatusConfig(serviceHealth.status) const StatusIcon = statusConfig.icon return (

AI 服务配置

配置 AI 服务提供商和模型参数

{/* 服务状态标签 */}
{statusConfig.label}
{/* 服务异常警告 */} {(serviceHealth.status === 'error' || serviceHealth.status === 'degraded') && (

{serviceHealth.status === 'error' ? 'AI 服务异常' : 'AI 服务降级'}

{serviceHealth.lastError || '部分 AI 功能可能不可用,系统已自动将任务加入重试队列。'}

{serviceHealth.queuedTasks > 0 && (

当前有 {serviceHealth.queuedTasks} 个任务在队列中等待重试

)} {serviceHealth.failedCount > 0 && (

连续失败 {serviceHealth.failedCount}

)}
)} {/* 最后检查时间 */} {serviceHealth.lastChecked && (
最后检查时间: {serviceHealth.lastChecked}
)} {/* 配置继承提示 */}

配置继承说明

品牌方配置后,所属代理商和达人将自动使用此配置。代理商和达人端不可见此配置项。

{/* AI 提供商 */} AI 提供商

支持 OneAPI、Anthropic Claude、OpenAI、DeepSeek 等提供商

{/* 模型配置 */} 模型配置 {/* 文字处理模型 */}
文字处理模型 (LLM) {getTestStatusIcon(testResults.llm)}

用于 Brief 解析、语义分析、报告生成

{/* 视频分析模型 */}
视频分析模型 (Vision) {getTestStatusIcon(testResults.vision)}

用于画面语义分析、场景/风险识别(Logo 检测由系统内置 CV 完成)

{/* 音频解析模型 */}
音频解析模型 (ASR) {getTestStatusIcon(testResults.asr)}

用于语音转文字、口播内容提取

{/* 连接配置 */} 连接配置
setBaseUrl(e.target.value)} placeholder="https://api.openai.com/v1" />
setApiKey(e.target.value)} placeholder="sk-..." />
{/* 生成参数 */} 生成参数
{temperature}
setTemperature(parseFloat(e.target.value))} className="w-full h-2 bg-bg-elevated rounded-lg appearance-none cursor-pointer accent-accent-indigo" />
精确 (0) 创意 (1)
setMaxTokens(parseInt(e.target.value))} min="100" max="8000" />
{/* 安全说明 */}

安全说明

  • • API Key 使用 AES-256-GCM 加密存储
  • • 所有 API 请求强制使用 HTTPS
  • • 仅品牌方管理员可查看/修改此配置
  • • 配置变更将被记录
{/* 操作按钮 */}
) }