Files
llm-proxy/templates/auto-profiles.html
T
hz4th_coder 178968ba1a v2.1.0: 能力路由体系 + 模型管理 + 生图/语音/视频端点 + 大量修复
- 提供商重构: Local Qwen(文本+视觉) / SiliconFlow LLM(文本) / Autodl(文本+视觉) / Autodl Image(生图)
- 能力标签: text/vision/audio_out/audio_in/image_gen/video_gen,模型级可配
- AUTO配置绑定能力: auto/auto-text/auto-vision/auto-image/auto-voice-out/auto-voice-in/auto-video
- 新端点: /v1/images/generations /v1/audio/speech /v1/audio/transcriptions /v1/video/generations
- 模型管理页: 能力切换/增删改/设默认/别名管理
- 修复: 失败切换不再替换用户模型; 熔断冷却后自动恢复; 重试不再白等; embeddings按模型路由
- 修复: 后台模板API路径(/api/admin); 删除v1旧admin目录与双端口混乱
- 修复: run.sh硬编码路径; 死配置RETRY/LOG接线; engine_completions空body防护
- 端口: 16003(16001-16100白名单区间); debug关闭; start.sh部署脚本
2026-08-28 11:41:17 +08:00

449 lines
23 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Auto配置管理 - LLM Proxy</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
<style>
.gradient-bg { background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); }
.dragging { opacity: 0.5; transform: scale(1.02); }
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="flex">
<aside class="w-64 bg-slate-800 min-h-screen fixed left-0 top-0">
<div class="p-6">
<h1 class="text-white text-xl font-bold flex items-center gap-2">
<i class="ri-route-line text-2xl text-purple-400"></i>
LLM Proxy
</h1>
<p class="text-slate-400 text-sm mt-1">后台管理</p>
</div>
<nav class="mt-6">
<a href="/admin" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/admin/providers" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-server-line"></i><span>提供商管理</span>
</a>
<a href="/admin/models" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-cpu-line"></i><span>模型管理</span>
</a>
<a href="/admin/auto-profiles" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-shuffle-line"></i><span>Auto配置</span>
</a>
<a href="/admin/chat" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-chat-3-line"></i><span>对话</span>
</a>
<a href="/admin/logs" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-file-list-line"></i><span>日志查看</span>
</a>
<a href="/admin/config" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-settings-3-line"></i><span>系统配置</span>
</a>
</nav>
</aside>
<main class="ml-64 flex-1 p-8">
<!-- 顶部操作栏 -->
<div class="flex justify-between items-center mb-6">
<div>
<h1 class="text-2xl font-bold text-gray-800">Auto配置管理</h1>
<p class="text-gray-500 text-sm mt-1">每个Auto配置固定一个功能类型,并从模型管理中挑选具备该能力的模型</p>
</div>
<button onclick="showCreateModal()" class="px-4 py-2 gradient-bg text-white rounded-lg hover:opacity-90 transition">
<i class="ri-add-line mr-1"></i> 创建Auto配置
</button>
</div>
<!-- 说明卡片 -->
<div class="mb-6 p-4 bg-indigo-50 rounded-lg text-sm text-indigo-600">
<i class="ri-information-line mr-1"></i>
<strong>Auto配置:</strong>例如 <code>model="auto-vision"</code> 只选择具备<strong>视觉能力</strong>的模型,<code>model="auto-image"</code> 只选择<strong>图片生成</strong>模型。调用时使用 <code>model="配置名称"</code>
</div>
<!-- 配置列表 -->
<div id="profilesList" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<p class="text-gray-500 col-span-full text-center py-8">加载中...</p>
</div>
</main>
</div>
<!-- 创建/编辑弹窗 -->
<div id="editModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50 p-4">
<div class="bg-white rounded-xl w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col">
<div class="p-6 border-b flex justify-between items-center">
<h2 class="text-xl font-bold text-gray-800" id="modalTitle">创建Auto配置</h2>
<button onclick="closeModal()" class="text-gray-400 hover:text-gray-600">
<i class="ri-close-line text-2xl"></i>
</button>
</div>
<div class="p-6 overflow-y-auto flex-1">
<form id="profileForm">
<input type="hidden" id="profileId">
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">配置名称</label>
<input type="text" id="profileName" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="例如: auto-text, auto-fast">
<p class="text-xs text-gray-500 mt-1">调用时使用 model="此名称"</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">显示名称</label>
<input type="text" id="displayName" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="例如: 快速文本">
</div>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-1">功能类型(固定此Auto的功能)*</label>
<select id="profileCapability" onchange="onCapabilityChange()" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<option value="">请选择功能类型...</option>
</select>
<p class="text-xs text-gray-500 mt-1">文本推理 / 视觉能力 / 语音输出 / 语音输入 / 图片生成 / 视频生成</p>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-1">描述</label>
<textarea id="profileDesc" rows="2" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="描述这个配置的用途"></textarea>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-1">选择策略</label>
<select id="profileStrategy" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<option value="priority">按优先级选择(推荐)</option>
<option value="random">随机选择</option>
</select>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-2">候选提供商(仅列出具备所选能力模型的提供商,可拖拽调整优先级)</label>
<div id="providerList" class="border border-gray-200 rounded-lg p-3 space-y-2 min-h-[100px] bg-gray-50">
<p class="text-gray-400 text-sm text-center py-4">请先选择功能类型</p>
</div>
<p class="text-xs text-gray-500 mt-1">勾选参与自动选择的提供商,拖拽调整优先级</p>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-2">将匹配到以下模型(该能力下各提供商将选择的模型)</label>
<div id="matchedModels" class="flex flex-wrap gap-1">
<span class="text-gray-400 text-xs">请先选择功能类型</span>
</div>
</div>
</form>
</div>
<div class="p-6 border-t bg-gray-50 flex justify-end gap-3">
<button onclick="closeModal()" class="px-4 py-2 text-gray-600 hover:text-gray-800 transition">取消</button>
<button onclick="saveProfile()" class="px-4 py-2 gradient-bg text-white rounded-lg hover:opacity-90 transition">
<i class="ri-save-line mr-1"></i> 保存
</button>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
<script>
let providers = [];
let profiles = [];
let capabilityDefs = {};
// 加载数据
async function loadData() {
const [providersRes, profilesRes, capsRes] = await Promise.all([
fetch('/api/admin/providers'),
fetch('/api/admin/auto-profiles'),
fetch('/api/admin/capabilities')
]);
providers = await providersRes.json();
profiles = await profilesRes.json();
capabilityDefs = await capsRes.json();
fillCapabilitySelect();
renderProfiles();
}
function fillCapabilitySelect() {
const sel = document.getElementById('profileCapability');
sel.innerHTML = '<option value="">请选择功能类型...</option>' +
Object.entries(capabilityDefs).map(([key, label]) => `<option value="${key}">${label}</option>`).join('');
}
// 渲染配置列表
function renderProfiles() {
const container = document.getElementById('profilesList');
if (profiles.length === 0) {
container.innerHTML = `
<div class="col-span-full text-center py-12">
<i class="ri-inbox-line text-4xl text-gray-300"></i>
<p class="text-gray-500 mt-2">暂无Auto配置</p>
<button onclick="showCreateModal()" class="mt-4 px-4 py-2 gradient-bg text-white rounded-lg">
<i class="ri-add-line mr-1"></i> 创建第一个配置
</button>
</div>
`;
return;
}
container.innerHTML = profiles.map(profile => `
<div class="bg-white rounded-xl border border-gray-200 hover:shadow-md transition">
<div class="p-4 border-b flex justify-between items-center">
<div>
<code class="text-indigo-600 font-semibold">${profile.name}</code>
${profile.name === 'auto' ? '<span class="ml-2 px-2 py-0.5 bg-gray-100 text-gray-600 text-xs rounded">默认</span>' : ''}
</div>
<div class="flex gap-1">
<button onclick="editProfile('${profile.name}')" class="p-2 text-gray-400 hover:text-indigo-600 hover:bg-indigo-50 rounded-lg transition">
<i class="ri-pencil-line"></i>
</button>
${profile.name !== 'auto' ? `
<button onclick="deleteProfile('${profile.name}')" class="p-2 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition">
<i class="ri-delete-bin-line"></i>
</button>
` : ''}
</div>
</div>
<div class="p-4">
<h3 class="font-medium text-gray-800">${profile.display_name || profile.name}</h3>
<p class="text-sm text-gray-500 mt-1">${profile.description || '暂无描述'}</p>
<div class="flex gap-2 mt-3 flex-wrap">
<span class="px-2 py-1 bg-indigo-50 text-indigo-600 text-xs rounded font-medium">
<i class="ri-focus-3-line mr-1"></i>${profile.capability_label || profile.capability || 'text'}
</span>
<span class="px-2 py-1 bg-gray-100 text-gray-600 text-xs rounded">
${profile.strategy === 'priority' ? '按优先级' : '随机'}
</span>
<span class="px-2 py-1 bg-gray-100 text-gray-600 text-xs rounded">
${profile.provider_details?.length || 0} 个提供商
</span>
<span class="px-2 py-1 bg-green-50 text-green-600 text-xs rounded">
${profile.matched_models?.length || 0} 个匹配模型
</span>
</div>
<div class="mt-3 flex flex-wrap gap-1">
${(profile.matched_models || []).slice(0, 5).map(m =>
`<span class="px-2 py-0.5 bg-slate-100 text-slate-600 text-xs rounded">${m}</span>`
).join('') || ''}
${(profile.matched_models?.length || 0) > 5 ?
`<span class="text-xs text-gray-400">+${profile.matched_models.length - 5}</span>` : ''}
</div>
</div>
</div>
`).join('');
}
// 显示创建弹窗
function showCreateModal() {
document.getElementById('modalTitle').textContent = '创建Auto配置';
document.getElementById('profileId').value = '';
document.getElementById('profileForm').reset();
document.getElementById('profileName').disabled = false;
document.getElementById('profileCapability').value = '';
document.getElementById('providerList').innerHTML = '<p class="text-gray-400 text-sm text-center py-4">请先选择功能类型</p>';
document.getElementById('matchedModels').innerHTML = '<span class="text-gray-400 text-xs">请先选择功能类型</span>';
document.getElementById('editModal').classList.remove('hidden');
document.getElementById('editModal').classList.add('flex');
}
// 编辑配置
async function editProfile(profileName) {
const res = await fetch(`/api/admin/auto-profiles/${profileName}`);
const profile = await res.json();
document.getElementById('modalTitle').textContent = '编辑Auto配置';
document.getElementById('profileId').value = profileName;
document.getElementById('profileName').value = profileName;
document.getElementById('profileName').disabled = true;
document.getElementById('displayName').value = profile.display_name || '';
document.getElementById('profileDesc').value = profile.description || '';
document.getElementById('profileStrategy').value = profile.strategy;
document.getElementById('profileCapability').value = profile.capability || 'text';
renderProviderList(profile.provider_details || [], profile.capability || 'text');
renderMatchedModels(profile.matched_models || []);
document.getElementById('editModal').classList.remove('hidden');
document.getElementById('editModal').classList.add('flex');
}
// 关闭弹窗
function closeModal() {
document.getElementById('editModal').classList.add('hidden');
document.getElementById('editModal').classList.remove('flex');
}
// 能力切换时重新渲染提供商列表
function onCapabilityChange() {
const capability = document.getElementById('profileCapability').value;
if (!capability) {
document.getElementById('providerList').innerHTML = '<p class="text-gray-400 text-sm text-center py-4">请先选择功能类型</p>';
document.getElementById('matchedModels').innerHTML = '<span class="text-gray-400 text-xs">请先选择功能类型</span>';
return;
}
renderProviderList([], capability);
renderMatchedModels([]);
}
// 提供商是否具备该能力
function providerHasCapability(provider, capability) {
if (!provider.models) return false;
return provider.models.some(m => (m.capabilities || []).includes(capability));
}
function providerMatchedModels(provider, capability) {
return (provider.models || [])
.filter(m => (m.capabilities || []).includes(capability))
.map(m => m.name);
}
// 渲染提供商列表(只展示具备所选能力的提供商)
function renderProviderList(selectedProviders, capability) {
const container = document.getElementById('providerList');
const selectedIds = selectedProviders.map(p => p.id);
const sortedProviders = [...providers].sort((a, b) => a.priority - b.priority);
const capable = sortedProviders.filter(p => providerHasCapability(p, capability));
if (capable.length === 0) {
container.innerHTML = `
<div class="text-center py-4">
<p class="text-gray-500 text-sm">暂无提供商具备该能力</p>
<p class="text-xs text-gray-400 mt-1">请先在 <a href="/admin/providers" class="text-indigo-500 underline">提供商管理</a> 中配置,或在 <a href="/admin/models" class="text-indigo-500 underline">模型管理</a> 中为模型添加能力标签</p>
</div>
`;
return;
}
container.innerHTML = capable.map(p => {
const isSelected = selectedIds.includes(p.id) || (selectedIds.includes('*') && p.id !== '*');
const matched = providerMatchedModels(p, capability);
const allSelected = selectedIds.includes('*');
return `
<div class="flex items-center gap-3 p-3 bg-white rounded-lg border ${isSelected || allSelected ? 'border-indigo-500 bg-indigo-50' : 'border-gray-200'} hover:border-indigo-300 transition cursor-move"
data-id="${p.id}" data-priority="${p.priority}">
<i class="ri-drag-move-2 text-gray-400 cursor-grab"></i>
<input type="checkbox" class="provider-check w-4 h-4 text-indigo-600 rounded"
id="provider-${p.id}" ${isSelected || allSelected ? 'checked' : ''}
onchange="this.closest('[data-id]').classList.toggle('border-indigo-500', this.checked);this.closest('[data-id]').classList.toggle('bg-indigo-50', this.checked)">
<div class="flex-1 min-w-0">
<div class="font-medium text-gray-800 truncate">${p.name}</div>
<div class="text-xs text-gray-500">
优先级 ${p.priority} · 匹配模型: ${matched.join(', ') || '无'}
</div>
</div>
${p.available ?
'<span class="px-2 py-0.5 bg-green-100 text-green-700 text-xs rounded">可用</span>' :
'<span class="px-2 py-0.5 bg-red-100 text-red-700 text-xs rounded">不可用</span>'}
</div>
`;
}).join('');
// 初始化拖拽排序
new Sortable(container, {
animation: 150,
handle: '.ri-drag-move-2',
ghostClass: 'dragging',
});
}
// 渲染匹配模型预览
function renderMatchedModels(models) {
const container = document.getElementById('matchedModels');
if (!models || models.length === 0) {
container.innerHTML = '<span class="text-gray-400 text-xs">当前选择下暂无匹配模型</span>';
return;
}
container.innerHTML = models.map(m =>
`<span class="px-2 py-0.5 bg-green-50 text-green-700 rounded text-xs">${m}</span>`
).join('');
}
// 保存配置
async function saveProfile() {
const profileName = document.getElementById('profileName').value.trim();
const displayName = document.getElementById('displayName').value.trim();
const description = document.getElementById('profileDesc').value.trim();
const strategy = document.getElementById('profileStrategy').value;
const capability = document.getElementById('profileCapability').value;
if (!profileName) {
alert('请输入配置名称');
return;
}
if (!capability) {
alert('请选择功能类型(此Auto配置将固定为该功能)');
return;
}
const selectedProviders = [];
document.querySelectorAll('.provider-check:checked').forEach(c => {
selectedProviders.push(c.id.replace('provider-', ''));
});
const data = {
name: profileName,
display_name: displayName || profileName,
description: description,
strategy: strategy,
capability: capability,
providers: selectedProviders.length > 0 ? selectedProviders : ['*']
};
const profileId = document.getElementById('profileId').value;
const url = profileId ? `/api/admin/auto-profiles/${profileId}` : '/api/admin/auto-profiles';
const method = profileId ? 'PUT' : 'POST';
try {
const res = await fetch(url, {
method: method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const result = await res.json();
if (result.success) {
closeModal();
loadData();
} else {
alert('保存失败: ' + (result.error || '未知错误'));
}
} catch (e) {
alert('保存失败: ' + e.message);
}
}
// 删除配置
async function deleteProfile(profileName) {
if (!confirm(`确定删除配置 "${profileName}" 吗?`)) return;
try {
const res = await fetch(`/api/admin/auto-profiles/${profileName}`, { method: 'DELETE' });
const result = await res.json();
if (result.success) {
loadData();
} else {
alert('删除失败: ' + (result.error || '未知错误'));
}
} catch (e) {
alert('删除失败: ' + e.message);
}
}
// 初始化
loadData();
</script>
</body>
</html>