import { useState, useEffect } from 'react' import { Copy, Check, Save, Link2, Loader, AlertCircle, ChevronDown, ChevronRight, RefreshCw, BookOpen, ExternalLink, FileText } from 'lucide-react' import { wanchuanLogin, getWanchuanKnowledgeBases, uploadToKnowledgeBase, clearWanchuanToken } from '../api/wanchuan' const CONFIG_ITEMS = [ { group: 'chatlog 底层服务', items: [ { label: 'chatlog 地址', value: 'http://127.0.0.1:5030', desc: 'Go 后端,负责读取微信数据库' }, { label: 'API 前缀', value: '/api/v1', desc: '所有 chatlog 接口均在此前缀下' }, ], }, { group: 'chatlog_fastAPI 业务层', items: [ { label: 'FastAPI 地址', value: 'http://127.0.0.1:8000', desc: 'Python 后端,负责 AI 分析和知识库' }, { label: '搜索接口', value: '/api/search', desc: '聊天记录搜索' }, { label: '话题接口', value: '/api/topics', desc: 'AI 话题分析管理' }, { label: '报告库接口', value: '/api/knowledge', desc: '售后报告管理' }, ], }, { group: '桌面应用服务', items: [ { label: '本地应用入口', value: '/', desc: '桌面应用内置界面,由本地业务服务托管' }, ], }, ] const AI_FIELDS = [ { key: 'ai_base_url', label: 'AI 接口地址', placeholder: 'https://dashscope.aliyuncs.com/compatible-mode/v1', desc: '兼容 OpenAI 格式的 API 地址' }, { key: 'ai_api_key', label: 'AI API Key', placeholder: 'sk-...', desc: '留空则 AI 功能不可用', type: 'password' }, { key: 'ai_model', label: '话题分析模型', placeholder: 'qwen-plus', desc: '用于消息分类的模型' }, { key: 'summary_model', label: '报告生成模型', placeholder: 'qwen-max', desc: '用于生成售后报告的模型' }, { key: 'vision_model', label: '视觉模型', placeholder: 'qwen-vl-plus', desc: '用于图片/视频描述' }, { key: 'voice_model', label: '语音模型', placeholder: 'paraformer-v2', desc: '用于语音转文字' }, ] const TOPIC_PROMPT_PLACEHOLDER = '例如:本群主要是某类设备售后群,请优先按设备部件、故障现象、处理进度来拆分话题;不要按客户名或日期拆分。' function CopyButton({ text }) { const [copied, setCopied] = useState(false) const handleCopy = () => { navigator.clipboard.writeText(text).then(() => { setCopied(true) setTimeout(() => setCopied(false), 1500) }) } return ( ) } function AISettingsForm() { const [form, setForm] = useState({}) const [saving, setSaving] = useState(false) const [msg, setMsg] = useState('') useEffect(() => { fetch('/api/settings') .then(r => r.json()) .then(data => setForm(data)) .catch(() => {}) }, []) const handleChange = (key, value) => { setForm(prev => ({ ...prev, [key]: value })) } const handleSave = async () => { setSaving(true) setMsg('') try { const res = await fetch('/api/settings', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(form), }) if (res.ok) { setMsg('已保存') setTimeout(() => setMsg(''), 2000) const updated = await fetch('/api/settings').then(r => r.json()) setForm(updated) } else { setMsg('保存失败') } } catch { setMsg('保存失败') } setSaving(false) } return (
AI 模型配置
首次使用请填入你的 API Key 和接口地址,保存后立即生效,无需重启服务。
{/* 未配置 API Key 时显示橙色警告横条 */} {!form.ai_api_key && (
⚠️ 未配置 AI API Key,所有 AI 功能不可用。请填入您自己的 API Key 并保存。
)}
{AI_FIELDS.map((field, i) => (
{field.label}
{field.desc}
handleChange(field.key, e.target.value)} style={{ flex: 1, fontSize: 13, padding: '7px 12px', border: '1px solid var(--border)', borderRadius: 6, background: 'var(--surface-2)', color: 'var(--text)', outline: 'none', }} /> {/* 配置状态指示点:绿色=已配置,红色=未配置 */}
))}
AI 话题分析提示词
作为全局默认分析口径;单个群聊可在 AI 话题分析里单独覆盖。