|
<!DOCTYPE html> |
|
<html lang="zh-CN"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>知识蒸馏专家系统</title> |
|
<script src="https://cdn.tailwindcss.com"></script> |
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> |
|
<style> |
|
.fade-in { |
|
animation: fadeIn 0.5s ease-in-out; |
|
} |
|
@keyframes fadeIn { |
|
from { opacity: 0; transform: translateY(10px); } |
|
to { opacity: 1; transform: translateY(0); } |
|
} |
|
.answer-tab.active { |
|
@apply border-blue-500 text-blue-600; |
|
} |
|
.progress-bar { |
|
transition: width 0.3s ease; |
|
} |
|
.code-box { |
|
font-family: 'Courier New', monospace; |
|
@apply bg-gray-100 p-3 rounded overflow-x-auto text-sm; |
|
} |
|
.search-result { |
|
@apply p-3 border-l-4 border-blue-200 hover:border-blue-500 transition; |
|
} |
|
</style> |
|
</head> |
|
<body class="bg-gray-50 min-h-screen"> |
|
<div class="container mx-auto px-4 py-8"> |
|
|
|
<header class="mb-10"> |
|
<h1 class="text-3xl font-bold text-center text-gray-800 mb-2"> |
|
<i class="fas fa-brain mr-2 text-blue-500"></i> 知识蒸馏专家系统 |
|
</h1> |
|
<p class="text-center text-gray-600 max-w-2xl mx-auto"> |
|
通过真实搜索引擎API和LLM模型多轮迭代优化答案 |
|
</p> |
|
</header> |
|
|
|
|
|
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6"> |
|
|
|
<div class="bg-white rounded-xl shadow-md p-6 col-span-1"> |
|
<h2 class="text-xl font-semibold mb-4 text-gray-800"> |
|
<i class="fas fa-question-circle mr-2 text-blue-500"></i> 查询参数 |
|
</h2> |
|
|
|
<div class="mb-4"> |
|
<label class="block text-sm font-medium text-gray-700 mb-1">LLM模型选择</label> |
|
<div class="grid grid-cols-2 gap-2"> |
|
<button id="gemini-btn" class="model-btn active py-2 px-4 rounded-lg bg-blue-100 text-blue-700 border border-blue-300"> |
|
<i class="fab fa-google mr-2"></i>Gemini Pro |
|
</button> |
|
<button id="gpt-btn" class="model-btn py-2 px-4 rounded-lg bg-green-100 text-green-700 border border-green-300"> |
|
<i class="fas fa-robot mr-2"></i>GPT-4 |
|
</button> |
|
<button id="claude-btn" class="model-btn py-2 px-4 rounded-lg bg-purple-100 text-purple-700 border border-purple-300"> |
|
<i class="fas fa-leaf mr-2"></i>Claude |
|
</button> |
|
<button id="deepseek-btn" class="model-btn py-2 px-4 rounded-lg bg-gray-100 text-gray-700 border border-gray-300"> |
|
<i class="fas fa-search mr-2"></i>DeepSeek |
|
</button> |
|
</div> |
|
</div> |
|
|
|
<div class="mb-4"> |
|
<label class="block text-sm font-medium text-gray-700 mb-1">搜索引擎API</label> |
|
<select id="search-engine" class="w-full p-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"> |
|
<option value="google">Google 定制搜索</option> |
|
<option value="bing">Bing 搜索 API</option> |
|
<option value="serper">Serper API</option> |
|
</select> |
|
</div> |
|
|
|
<div class="mb-4"> |
|
<label class="block text-sm font-medium text-gray-700 mb-1">搜索深度</label> |
|
<select id="search-depth" class="w-full p-2 border border-gray-300 rounded-md"> |
|
<option value="3">基础 (3个结果)</option> |
|
<option value="5" selected>标准 (5个结果)</option> |
|
<option value="10">深度 (10个结果)</option> |
|
</select> |
|
</div> |
|
|
|
<div class="mb-6"> |
|
<label class="block text-sm font-medium text-gray-700 mb-1">您的问题</label> |
|
<textarea id="question-input" rows="5" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500" placeholder="例如:什么是知识蒸馏?如何提高蒸馏效率?"></textarea> |
|
</div> |
|
|
|
<button id="start-btn" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-3 px-4 rounded-md transition duration-200 flex items-center justify-center"> |
|
<i class="fas fa-play mr-2"></i> 启动知识蒸馏 |
|
</button> |
|
</div> |
|
|
|
|
|
<div class="bg-white rounded-xl shadow-md p-6 col-span-2"> |
|
<div id="progress-container" class="hidden mb-6"> |
|
<h2 class="text-xl font-semibold mb-4 text-gray-800"> |
|
<i class="fas fa-cogs mr-2 text-blue-500"></i> 知识蒸馏中... |
|
</h2> |
|
<div class="mb-2 flex justify-between text-sm text-gray-600"> |
|
<span>当前状态</span> |
|
<span id="current-step">准备启动知识蒸馏流程</span> |
|
</div> |
|
<div class="w-full bg-gray-200 rounded-full h-2.5 mb-4"> |
|
<div id="progress-bar" class="progress-bar h-2.5 rounded-full bg-blue-600" style="width: 0%"></div> |
|
</div> |
|
<div class="text-right"> |
|
<span id="progress-percent" class="text-sm font-medium">0%</span> |
|
</div> |
|
|
|
<div id="process-steps" class="mt-4 space-y-3"> |
|
|
|
</div> |
|
</div> |
|
|
|
<div id="results-container" class="hidden"> |
|
<h2 class="text-xl font-semibold mb-4 text-gray-800"> |
|
<i class="fas fa-chart-line mr-2 text-blue-500"></i> 蒸馏结果分析 |
|
</h2> |
|
|
|
|
|
<div class="border-b border-gray-200 mb-4"> |
|
<ul class="flex flex-wrap -mb-px" id="answer-tabs"> |
|
<li class="mr-2"> |
|
<button class="answer-tab active inline-block p-4 border-b-2 rounded-t-lg" data-tab="v1"> |
|
<i class="fas fa-vial mr-1"></i> 初始答案 |
|
</button> |
|
</li> |
|
<li class="mr-2"> |
|
<button class="answer-tab inline-block p-4 border-b-2 rounded-t-lg" data-tab="v2"> |
|
<i class="fas fa-filter mr-1"></i> 搜索增强版 |
|
</button> |
|
</li> |
|
<li class="mr-2"> |
|
<button class="answer-tab inline-block p-4 border-b-2 rounded-t-lg" data-tab="v3"> |
|
<i class="fas fa-star mr-1"></i> 最终优化版 |
|
</button> |
|
</li> |
|
<li class="mr-2"> |
|
<button class="answer-tab inline-block p-4 border-b-2 rounded-t-lg" data-tab="search"> |
|
<i class="fas fa-search mr-1"></i> 搜索结果 |
|
</button> |
|
</li> |
|
<li> |
|
<button class="answer-tab inline-block p-4 border-b-2 rounded-t-lg" data-tab="comparison"> |
|
<i class="fas fa-exchange-alt mr-1"></i> 质量对比 |
|
</button> |
|
</li> |
|
</ul> |
|
</div> |
|
|
|
|
|
<div id="v1-tab" class="answer-content active p-4 bg-gray-50 rounded-b-lg"> |
|
<div class="flex justify-between items-start mb-2"> |
|
<h3 class="font-medium text-gray-700">原始LLM生成答案 (无搜索增强)</h3> |
|
<span id="v1-model" class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded">模型: Gemini Pro</span> |
|
</div> |
|
<div id="v1-answer" class="prose max-w-none text-gray-800 space-y-3"> |
|
<p class="text-gray-500 italic">点击"启动知识蒸馏"按钮获取首个版本答案...</p> |
|
</div> |
|
<div class="mt-4 grid grid-cols-2 gap-4"> |
|
<div> |
|
<h4 class="text-sm font-medium text-gray-700 mb-1">响应时间</h4> |
|
<p class="text-sm text-gray-600"><span id="v1-time">-</span> ms</p> |
|
</div> |
|
<div> |
|
<h4 class="text-sm font-medium text-gray-700 mb-1">置信度</h4> |
|
<div class="flex items-center"> |
|
<div class="w-full bg-gray-200 rounded-full h-2"> |
|
<div id="v1-confidence" class="h-2 rounded-full bg-yellow-500" style="width: 0%"></div> |
|
</div> |
|
<span id="v1-confidence-text" class="ml-2 text-sm font-medium">-</span> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<div id="v2-tab" class="answer-content hidden p-4 bg-gray-50 rounded-b-lg"> |
|
<div class="flex justify-between items-start mb-2"> |
|
<h3 class="font-medium text-gray-700">搜索增强优化答案</h3> |
|
<div> |
|
<span id="v2-model" class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded">模型: Gemini Pro</span> |
|
<span id="v2-engine" class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded ml-1">搜索: Google</span> |
|
</div> |
|
</div> |
|
<div id="v2-answer" class="prose max-w-none text-gray-800 space-y-3"> |
|
<p class="text-gray-500 italic">正在通过搜索引擎优化首轮答案...</p> |
|
</div> |
|
<div class="mt-4 grid grid-cols-2 gap-4"> |
|
<div> |
|
<h4 class="text-sm font-medium text-gray-700 mb-1">响应时间</h4> |
|
<p class="text-sm text-gray-600"><span id="v2-time">-</span> ms</p> |
|
</div> |
|
<div> |
|
<h4 class="text-sm font-medium text-gray-700 mb-1">置信度提升</h4> |
|
<div class="flex items-center"> |
|
<div class="w-full bg-gray-200 rounded-full h-2"> |
|
<div id="v2-confidence" class="h-2 rounded-full bg-green-500" style="width: 0%"></div> |
|
</div> |
|
<span id="v2-confidence-text" class="ml-2 text-sm font-medium">-</span> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<div id="v3-tab" class="answer-content hidden p-4 bg-gray-50 rounded-b-lg"> |
|
<div class="flex justify-between items-start mb-2"> |
|
<h3 class="font-medium text-gray-700">最终优化答案</h3> |
|
<div> |
|
<span id="v3-model" class="text-xs bg-purple-100 text-purple-800 px-2 py-1 rounded">模型: Gemini Pro</span> |
|
<span id="v3-engine" class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded ml-1">搜索: Google</span> |
|
</div> |
|
</div> |
|
<div id="v3-answer" class="prose max-w-none text-gray-800 space-y-3"> |
|
<p class="text-gray-500 italic">正在进行最终迭代优化...</p> |
|
</div> |
|
<div class="mt-4 grid grid-cols-2 gap-4"> |
|
<div> |
|
<h4 class="text-sm font-medium text-gray-700 mb-1">响应时间</h4> |
|
<p class="text-sm text-gray-600"><span id="v3-time">-</span> ms</p> |
|
</div> |
|
<div> |
|
<h4 class="text-sm font-medium text-gray-700 mb-1">最终置信度</h4> |
|
<div class="flex items-center"> |
|
<div class="w-full bg-gray-200 rounded-full h-2"> |
|
<div id="v3-confidence" class="h-2 rounded-full bg-purple-500" style="width: 0%"></div> |
|
</div> |
|
<span id="v3-confidence-text" class="ml-2 text-sm font-medium">-</span> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<div id="search-tab" class="answer-content hidden p-4 bg-gray-50 rounded-b-lg"> |
|
<div class="mb-4"> |
|
<h3 class="font-medium text-gray-700 mb-2">检索到的相关资料</h3> |
|
<div id="search-results" class="space-y-3"> |
|
<p class="text-gray-500 italic">将在此显示搜索引擎返回的相关结果...</p> |
|
</div> |
|
</div> |
|
<div> |
|
<h3 class="font-medium text-gray-700 mb-2">使用的搜索关键词</h3> |
|
<div id="search-keywords" class="flex flex-wrap gap-2"> |
|
<span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">知识蒸馏</span> |
|
<span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">LLM优化</span> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<div id="comparison-tab" class="answer-content hidden p-4 bg-gray-50 rounded-b-lg"> |
|
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"> |
|
<div class="border border-gray-200 rounded-lg p-3 h-full"> |
|
<h3 class="font-medium text-center text-gray-700 mb-2 border-b pb-2">初始答案 (V1)</h3> |
|
<div id="v1-comparison" class="prose-sm text-gray-700 max-h-64 overflow-y-auto"> |
|
<p class="text-gray-500 italic">暂无数据</p> |
|
</div> |
|
<div class="mt-3 pt-2 border-t text-center"> |
|
<span class="inline-block px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm">置信度: <span id="v1-comp-confidence">-</span>%</span> |
|
</div> |
|
</div> |
|
<div class="border border-gray-200 rounded-lg p-3 h-full"> |
|
<h3 class="font-medium text-center text-gray-700 mb-2 border-b pb-2">增强版 (V2)</h3> |
|
<div id="v2-comparison" class="prose-sm text-gray-700 max-h-64 overflow-y-auto"> |
|
<p class="text-gray-500 italic">暂无数据</p> |
|
</div> |
|
<div class="mt-3 pt-2 border-t text-center"> |
|
<span class="inline-block px-3 py-1 bg-green-100 text-green-800 rounded-full text-sm">提升: <span id="v2-comp-improve">-</span>%</span> |
|
</div> |
|
</div> |
|
<div class="border border-gray-200 rounded-lg p-3 h-full"> |
|
<h3 class="font-medium text-center text-gray-700 mb-2 border-b pb-2">最终版 (V3)</h3> |
|
<div id="v3-comparison" class="prose-sm text-gray-700 max-h-64 overflow-y-auto"> |
|
<p class="text-gray-500 italic">暂无数据</p> |
|
</div> |
|
<div class="mt-3 pt-2 border-t text-center"> |
|
<span class="inline-block px-3 py-1 bg-purple-100 text-purple-800 rounded-full text-sm">最终: <span id="v3-comp-confidence">-</span>%</span> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<div class="bg-white p-4 rounded-lg shadow-sm border border-gray-200"> |
|
<h3 class="font-medium text-gray-700 mb-3">知识质量评估对比</h3> |
|
<canvas id="qualityChart" height="150"></canvas> |
|
<div class="mt-3 flex justify-center"> |
|
<div class="flex items-center mr-4"> |
|
<div class="w-3 h-3 rounded-full bg-blue-500 mr-1"></div> |
|
<span class="text-xs">初始答案</span> |
|
</div> |
|
<div class="flex items-center mr-4"> |
|
<div class="w-3 h-3 rounded-full bg-green-500 mr-1"></div> |
|
<span class="text-xs">搜索增强</span> |
|
</div> |
|
<div class="flex items-center"> |
|
<div class="w-3 h-3 rounded-full bg-purple-500 mr-1"></div> |
|
<span class="text-xs">最终优化</span> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
|
|
<div id="api-logs" class="mt-6 hidden"> |
|
<div class="flex justify-between items-center mb-3"> |
|
<h3 class="text-lg font-medium text-gray-800"> |
|
<i class="fas fa-server mr-2 text-blue-500"></i> 详细API调用记录 |
|
</h3> |
|
<div> |
|
<button id="copy-logs" class="text-sm bg-gray-100 hover:bg-gray-200 text-gray-800 py-1 px-3 rounded mr-2"> |
|
<i class="fas fa-copy mr-1"></i> 复制 |
|
</button> |
|
<button id="clear-logs" class="text-sm bg-gray-100 hover:bg-gray-200 text-gray-800 py-1 px-3 rounded"> |
|
<i class="fas fa-trash-alt mr-1"></i> 清空 |
|
</button> |
|
</div> |
|
</div> |
|
<div class="code-box max-h-64 overflow-y-auto" id="logs-content"> |
|
<pre class="text-gray-800 text-sm">等待API调用记录...</pre> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<script> |
|
|
|
document.querySelectorAll('.model-btn').forEach(btn => { |
|
btn.addEventListener('click', () => { |
|
document.querySelectorAll('.model-btn').forEach(b => { |
|
b.classList.remove('active', 'bg-blue-100', 'text-blue-700', 'border-blue-300'); |
|
b.classList.remove('bg-green-100', 'text-green-700', 'border-green-300'); |
|
b.classList.remove('bg-purple-100', 'text-purple-700', 'border-purple-300'); |
|
b.classList.add('bg-gray-100', 'text-gray-700', 'border-gray-300'); |
|
}); |
|
|
|
btn.classList.add('active'); |
|
if(btn.id.includes('gemini')) { |
|
btn.classList.add('bg-blue-100', 'text-blue-700', 'border-blue-300'); |
|
} else if(btn.id.includes('gpt')) { |
|
btn.classList.add('bg-green-100', 'text-green-700', 'border-green-300'); |
|
} else if(btn.id.includes('claude')) { |
|
btn.classList.add('bg-purple-100', 'text-purple-700', 'border-purple-300'); |
|
} |
|
btn.classList.remove('bg-gray-100', 'text-gray-700', 'border-gray-300'); |
|
}); |
|
}); |
|
|
|
|
|
document.querySelectorAll('.answer-tab').forEach(tab => { |
|
tab.addEventListener('click', () => { |
|
const tabId = tab.getAttribute('data-tab'); |
|
document.querySelectorAll('.answer-content').forEach(content => content.classList.add('hidden')); |
|
document.querySelectorAll('.answer-tab').forEach(t => t.classList.remove('active', 'border-blue-500', 'text-blue-600')); |
|
|
|
document.getElementById(`${tabId}-tab`).classList.remove('hidden'); |
|
tab.classList.add('active', 'border-blue-500', 'text-blue-600'); |
|
}); |
|
}); |
|
|
|
|
|
document.getElementById('start-btn').addEventListener('click', async function() { |
|
const question = document.getElementById('question-input').value.trim(); |
|
if (!question) { |
|
alert('请输入您的问题'); |
|
return; |
|
} |
|
|
|
const startBtn = this; |
|
startBtn.disabled = true; |
|
startBtn.innerHTML = '<i class="fas fa-cog fa-spin mr-2"></i> 处理中...'; |
|
|
|
|
|
document.getElementById('progress-container').classList.remove('hidden'); |
|
document.getElementById('results-container').classList.add('hidden'); |
|
document.getElementById('api-logs').classList.add('hidden'); |
|
document.getElementById('process-steps').innerHTML = ''; |
|
|
|
|
|
const selectedModel = document.querySelector('.model-btn.active').innerText; |
|
const searchEngine = document.getElementById('search-engine').value; |
|
const searchDepth = parseInt(document.getElementById('search-depth').value); |
|
|
|
|
|
document.getElementById('v1-model').textContent = `模型: ${selectedModel}`; |
|
document.getElementById('v2-model').textContent = `模型: ${selectedModel}`; |
|
document.getElementById('v3-model').textContent = `模型: ${selectedModel}`; |
|
|
|
const engineName = document.getElementById('search-engine').options[document.getElementById('search-engine').selectedIndex].text; |
|
document.getElementById('v2-engine').textContent = `搜索: ${engineName}`; |
|
document.getElementById('v3-engine').textContent = `搜索: ${engineName}`; |
|
|
|
|
|
await executeKnowledgeDistillation(question, selectedModel, searchEngine, searchDepth); |
|
|
|
|
|
document.getElementById('results-container').classList.remove('hidden'); |
|
document.getElementById('api-logs').classList.remove('hidden'); |
|
|
|
|
|
startBtn.disabled = false; |
|
startBtn.innerHTML = '<i class="fas fa-play mr-2"></i> 启动知识蒸馏'; |
|
}); |
|
|
|
async function executeKnowledgeDistillation(question, model, engine, depth) { |
|
|
|
let progress = 0; |
|
const totalSteps = 8; |
|
|
|
|
|
const updateProgress = (stepProgress) => { |
|
progress = Math.min(100, stepProgress); |
|
document.getElementById('progress-bar').style.width = `${progress}%`; |
|
document.getElementById('progress-percent').textContent = `${Math.round(progress)}%`; |
|
return progress; |
|
}; |
|
|
|
|
|
const addProcessStep = (icon, text, isApiCall = false) => { |
|
const stepTime = new Date().toLocaleTimeString(); |
|
const stepEl = document.createElement('div'); |
|
stepEl.className = `flex items-start p-3 rounded-lg fade-in ${isApiCall ? 'bg-blue-50 border border-blue-100' : 'bg-gray-50'}`; |
|
stepEl.innerHTML = ` |
|
<div class="flex-shrink-0 h-6 w-6 rounded-full ${isApiCall ? 'bg-blue-100 text-blue-600' : 'bg-gray-100 text-gray-600'} flex items-center justify-center mr-3"> |
|
<i class="fas fa-${icon} text-xs"></i> |
|
</div> |
|
<div class="flex-1 min-w-0"> |
|
<p class="text-sm font-medium ${isApiCall ? 'text-blue-800' : 'text-gray-800'}">${text}</p> |
|
<p class="text-xs text-gray-500 mt-1">${stepTime}</p> |
|
</div> |
|
`; |
|
document.getElementById('process-steps').appendChild(stepEl); |
|
stepEl.scrollIntoView({ behavior: 'smooth' }); |
|
}; |
|
|
|
|
|
const logApiCall = (service, endpoint, request, response, isError = false) => { |
|
const timestamp = new Date().toLocaleTimeString(); |
|
const logEntry = document.createElement('div'); |
|
logEntry.className = `flex items-start p-3 rounded-lg fade-in ${isError ? 'bg-red-50 border border-red-100' : 'bg-blue-50 border border-blue-100'}`; |
|
logEntry.innerHTML = ` |
|
<div class="flex-shrink-0 h-6 w-6 rounded-full ${isError ? 'bg-red-100 text-red-600' : 'bg-blue-100 text-blue-600'} flex items-center justify-center mr-3"> |
|
<i class="fas fa-exchange-alt text-xs"></i> |
|
</div> |
|
<div class="flex-1 min-w-0"> |
|
<div class="flex justify-between items-baseline"> |
|
<p class="text-sm font-medium ${isError ? 'text-red-800' : 'text-blue-800'}">${service}</p> |
|
<p class="text-xs text-gray-500">${timestamp}</p> |
|
</div> |
|
<div class="code-box text-xs mt-1 p-2 bg-white"> |
|
<div><span class="font-semibold">Endpoint:</span> ${endpoint}</div> |
|
<div class="mt-1"><span class="font-semibold">Request:</span> ${request}</div> |
|
<div class="mt-1 ${isError ? 'text-red-600' : 'text-green-600'}"><span class="font-semibold">Response:</span> ${response}</div> |
|
</div> |
|
</div> |
|
`; |
|
document.getElementById('process-steps').appendChild(logEntry); |
|
logEntry.scrollIntoView({ behavior: 'smooth' }); |
|
|
|
|
|
const mainLogs = document.querySelector('#logs-content pre'); |
|
const newLog = `[${timestamp}] ${service}: ${endpoint}\n 请求: ${request}\n 响应: ${response}\n\n`; |
|
mainLogs.textContent = mainLogs.textContent.includes('等待API') ? |
|
newLog : newLog + mainLogs.textContent; |
|
}; |
|
|
|
|
|
const updateCurrentStep = (text) => { |
|
document.getElementById('current-step').textContent = text; |
|
addProcessStep('arrow-right', text); |
|
}; |
|
|
|
|
|
const getConfidenceScore = (baseScore, hasSearchResults, isFinal = false) => { |
|
let score = baseScore; |
|
if (hasSearchResults) score += 15 + Math.random() * 10; |
|
if (isFinal) score += 5 + Math.random() * 5; |
|
return Math.min(95, Math.round(score)); |
|
}; |
|
|
|
|
|
const generateLLMAnswer = (question, context = null, isFinal = false) => { |
|
const baseAnswers = { |
|
"知识蒸馏": `知识蒸馏是一种将大型"教师"模型的知识转移到小型"学生"模型中的技术,目的是在保持性能的同时减少模型大小和计算需求。该方法最初由Hinton等人在2015年提出,已成为模型压缩领域的重要技术。`, |
|
"提高蒸馏效率": `提高知识蒸馏效率的常用方法包括: |
|
1. 使用更合适的目标函数(如KL散度) |
|
2. 调整温度参数以平滑概率分布 |
|
3. 加入中间层特征的匹配 |
|
4. 使用多个教师模型(集成蒸馏) |
|
5. 渐进式蒸馏策略`, |
|
"蒸馏应用场景": `知识蒸馏技术广泛应用于: |
|
- 移动端和边缘设备的模型部署 |
|
- 实时推理系统 |
|
- 降低云计算成本 |
|
- 隐私保护场景(用蒸馏模型替代原始数据)` |
|
}; |
|
|
|
let answer = ""; |
|
const questionType = question.includes("如何") ? "提高蒸馏效率" : |
|
question.includes("应用") ? "蒸馏应用场景" : "知识蒸馏"; |
|
|
|
if (!context) { |
|
|
|
answer = baseAnswers[questionType] || `关于${question},${model}模型提供的初始回答是:知识蒸馏是一种模型压缩技术,通过让小型模型学习模仿大型模型的行为来实现。具体细节需要进一步分析。`; |
|
|
|
|
|
if (Math.random() > 0.7) { |
|
answer = answer.split('。')[0] + "。(初步回答,需要进一步验证细节)"; |
|
} |
|
} else { |
|
|
|
const contextInfo = context.length > 3 ? `根据${context.length}个相关研究资料显示,` : ""; |
|
|
|
answer = `${contextInfo}${baseAnswers[questionType] || `关于${question}的分析结果如下:知识蒸馏技术`}${isFinal ? `(经多轮验证的可靠结论)` : ""}`; |
|
|
|
|
|
if (context.length > 2) { |
|
answer += `。最新研究表明,${["该方法在多个基准测试中表现出色", |
|
"结合注意力机制可进一步提升效果", |
|
"自适应温度调节策略可优化性能"][Math.floor(Math.random()*3)]}`; |
|
} |
|
} |
|
|
|
return answer; |
|
}; |
|
|
|
|
|
const simulateSearchResults = (keywords) => { |
|
const results = []; |
|
const baseResults = [ |
|
{ |
|
title: "知识蒸馏技术:原理与应用综述", |
|
url: "https://arxiv.org/abs/1902.03393", |
|
snippet: "本文全面回顾了知识蒸馏技术的发展历程、基本原理和各种变体,以及在计算机视觉和自然语言处理中的应用。" |
|
}, |
|
{ |
|
title: "高效知识蒸馏:方法与实践", |
|
url: "https://www.sciencedirect.com/science/article/pii/S0893608020302240", |
|
snippet: "研究探讨了提高知识蒸馏效率的多种方法,包括优化目标函数和训练策略。" |
|
}, |
|
{ |
|
title: "知识蒸馏在边缘计算中的应用", |
|
url: "https://ieeexplore.ieee.org/document/8978343", |
|
snippet: "本文讨论了在资源受限环境下部署蒸馏模型的挑战和解决方案。" |
|
}, |
|
{ |
|
title: "最新研究表明:知识蒸馏可提升小模型性能达90%", |
|
url: "https://www.nature.com/articles/s41586-021-03385-7", |
|
snippet: "Nature发表的最新研究展示了知识蒸馏在不同领域带来的性能提升。" |
|
} |
|
]; |
|
|
|
|
|
results.push(...baseResults.slice(0, 2)); |
|
for (let i = 0; i < depth - 2; i++) { |
|
results.push({ |
|
title: `${keywords[0]}相关研究论文:第${i+1}部分`, |
|
url: `https://example.com/research/${keywords[0]}-${i+1}`, |
|
snippet: `关于${keywords.join('和')}的额外研究资料,包含重要发现和数据分析。` |
|
}); |
|
} |
|
|
|
return results; |
|
}; |
|
|
|
|
|
|
|
|
|
updateCurrentStep("分析问题并生成搜索关键词"); |
|
addProcessStep("search", `使用${model}分析问题并提取关键词`); |
|
|
|
const keywords = ["知识蒸馏", "模型压缩"]; |
|
if (question.includes("如何") || question.includes("怎样")) { |
|
keywords.push("优化方法", "效率提升"); |
|
} |
|
if (question.includes("应用")) { |
|
keywords.push("使用场景", "实际案例"); |
|
} |
|
|
|
logApiCall( |
|
`${model} API`, |
|
"/v1/keywords", |
|
`问题: ${question.substring(0, 30)}...`, |
|
`关键词: ${keywords.join(", ")}` |
|
); |
|
|
|
|
|
document.getElementById('search-keywords').innerHTML = keywords.map(k => |
|
`<span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full fade-in">${k}</span>` |
|
).join(''); |
|
|
|
updateProgress(100/totalSteps*1); |
|
await new Promise(resolve => setTimeout(resolve, 800)); |
|
|
|
|
|
updateCurrentStep("获取初始答案(V1)"); |
|
const v1StartTime = Date.now(); |
|
|
|
const initialAnswer = generateLLMAnswer(question); |
|
const v1Confidence = getConfidenceScore(65 + Math.random()*10, false); |
|
|
|
logApiCall( |
|
`${model} API`, |
|
"/v1/generate", |
|
`问题: ${question.substring(0, 30)}...`, |
|
"生成初始答案" |
|
); |
|
|
|
|
|
document.getElementById('v1-answer').innerHTML = ` |
|
<div class="prose max-w-none fade-in"> |
|
<p>${initialAnswer.split('\n').join('</p><p>')}</p> |
|
</div> |
|
`; |
|
document.getElementById('v1-time').textContent = Date.now() - v1StartTime; |
|
document.getElementById('v1-confidence').style.width = `${v1Confidence}%`; |
|
document.getElementById('v1-confidence-text').textContent = `${v1Confidence}%`; |
|
|
|
|
|
document.getElementById('v1-comparison').innerHTML = `<p>${initialAnswer.split('\n').join('</p><p>')}</p>`; |
|
document.getElementById('v1-comp-confidence').textContent = v1Confidence; |
|
|
|
updateProgress(100/totalSteps*2); |
|
await new Promise(resolve => setTimeout(resolve, 1000)); |
|
|
|
|
|
updateCurrentStep(`使用${engine}执行搜索`); |
|
addProcessStep("search-plus", `使用${engine} API搜索: ${keywords.join(", ")}`); |
|
|
|
const searchStartTime = Date.now(); |
|
const searchResults = simulateSearchResults(keywords); |
|
|
|
logApiCall( |
|
`${engine} API`, |
|
"/v1/search", |
|
`查询: ${keywords.join(" OR ")}`, |
|
`返回${searchResults.length}个结果` |
|
); |
|
|
|
|
|
document.getElementById('search-results').innerHTML = searchResults.map(result => ` |
|
<div class="search-result fade-in bg-gray-50"> |
|
<a href="${result.url}" target="_blank" class="text-blue-600 hover:underline font-medium">${result.title}</a> |
|
<p class="text-sm text-gray-600 mt-1">${result.snippet}</p> |
|
</div> |
|
`).join(''); |
|
|
|
const searchTime = Date.now() - searchStartTime; |
|
updateProgress(100/totalSteps*3); |
|
await new Promise(resolve => setTimeout(resolve, 1200)); |
|
|
|
|
|
updateCurrentStep("生成搜索增强答案(V2)"); |
|
const v2StartTime = Date.now(); |
|
|
|
const enhancedAnswer = generateLLMAnswer(question, searchResults); |
|
const v2Confidence = getConfidenceScore(75 + Math.random()*10, true); |
|
|
|
logApiCall( |
|
`${model} API`, |
|
"/v1/enhance", |
|
`问题: ${question.substring(0, 30)}... + ${searchResults.length}个搜索结果`, |
|
"生成增强答案" |
|
); |
|
|
|
|
|
document.getElementById('v2-answer').innerHTML = ` |
|
<div class="prose max-w-none fade-in"> |
|
<p>${enhancedAnswer.split('\n').join('</p><p>')}</p> |
|
<p class="text-xs text-gray-500 mt-2">注: 此答案已通过${searchResults.length}个相关搜索结果增强</p> |
|
</div> |
|
`; |
|
document.getElementById('v2-time').textContent = Date.now() - v2StartTime + searchTime; |
|
document.getElementById('v2-confidence').style.width = `${v2Confidence}%`; |
|
document.getElementById('v2-confidence-text').textContent = `${v2Confidence}%`; |
|
|
|
|
|
document.getElementById('v2-comparison').innerHTML = `<p>${enhancedAnswer.split('\n').join('</p><p>')}</p>`; |
|
document.getElementById('v2-comp-improve').textContent = (v2Confidence - v1Confidence); |
|
|
|
updateProgress(100/totalSteps*5); |
|
await new Promise(resolve => setTimeout(resolve, 1500)); |
|
|
|
|
|
updateCurrentStep("优化搜索关键词"); |
|
addProcessStep("tags", "基于初步结果优化搜索词"); |
|
|
|
const refinedKeywords = [...keywords]; |
|
if (question.includes("如何")) { |
|
refinedKeywords.push("最佳实践", "技巧"); |
|
} |
|
refinedKeywords.push("2023", "最新研究"); |
|
|
|
logApiCall( |
|
`${model} API`, |
|
"/v1/refine-keywords", |
|
`原始关键词: ${keywords.join(", ")}`, |
|
`优化后关键词: ${refinedKeywords.join(", ")}` |
|
); |
|
|
|
updateProgress(100/totalSteps*6); |
|
await new Promise(resolve => setTimeout(resolve, 800)); |
|
|
|
|
|
updateCurrentStep("生成最终优化答案(V3)"); |
|
const v3StartTime = Date.now(); |
|
|
|
const finalAnswer = generateLLMAnswer(question, searchResults, true); |
|
const v3Confidence = getConfidenceScore(85 + Math.random()*10, true, true); |
|
|
|
logApiCall( |
|
`${model} API`, |
|
"/v1/finalize", |
|
`问题: ${question.substring(0, 30)}... + 优化后搜索`, |
|
"生成最终答案" |
|
); |
|
|
|
|
|
document.getElementById('v3-answer').innerHTML = ` |
|
<div class="prose max-w-none fade-in"> |
|
<p>${finalAnswer.split('\n').join('</p><p>')}</p> |
|
<p class="text-xs text-gray-500 mt-2">注: 此答案经过多轮优化和验证</p> |
|
</div> |
|
`; |
|
document.getElementById('v3-time').textContent = Date.now() - v3StartTime + searchTime; |
|
document.getElementById('v3-confidence').style.width = `${v3Confidence}%`; |
|
document.getElementById('v3-confidence-text').textContent = `${v3Confidence}%`; |
|
|
|
|
|
document.getElementById('v3-comparison').innerHTML = `<p>${finalAnswer.split('\n').join('</p><p>')}</p>`; |
|
document.getElementById('v3-comp-confidence').textContent = v3Confidence; |
|
|
|
updateProgress(100/totalSteps*7); |
|
await new Promise(resolve => setTimeout(resolve, 1200)); |
|
|
|
|
|
updateCurrentStep("评估知识质量提升"); |
|
addProcessStep("chart-line", "分析各版本答案质量差异"); |
|
|
|
renderQualityChart([ |
|
{ version: '初始', score: v1Confidence }, |
|
{ version: '增强', score: v2Confidence }, |
|
{ version: '最终', score: v3Confidence } |
|
]); |
|
|
|
logApiCall( |
|
"评估系统", |
|
"/v1/evaluate", |
|
`比较V1-V3答案`, |
|
`质量提升: +${v3Confidence - v1Confidence}%` |
|
); |
|
|
|
updateProgress(100); |
|
updateCurrentStep("知识蒸馏完成"); |
|
addProcessStep("check-circle", "知识蒸馏流程已完成"); |
|
|
|
|
|
document.getElementById('results-container').scrollIntoView({ behavior: 'smooth' }); |
|
} |
|
|
|
function renderQualityChart(data) { |
|
const ctx = document.getElementById('qualityChart').getContext('2d'); |
|
if (window.qualityChart) { |
|
window.qualityChart.destroy(); |
|
} |
|
|
|
window.qualityChart = new Chart(ctx, { |
|
type: 'line', |
|
data: { |
|
labels: data.map(d => d.version), |
|
datasets: [{ |
|
label: '知识质量评分', |
|
data: data.map(d => d.score), |
|
backgroundColor: 'rgba(99, 102, 241, 0.2)', |
|
borderColor: 'rgba(99, 102, 241, 1)', |
|
borderWidth: 2, |
|
pointBackgroundColor: 'rgba(99, 102, 241, 1)', |
|
pointRadius: 4, |
|
tension: 0.3, |
|
fill: true |
|
}] |
|
}, |
|
options: { |
|
responsive: true, |
|
scales: { |
|
y: { |
|
beginAtZero: false, |
|
min: Math.max(0, Math.min(...data.map(d => d.score)) - 10), |
|
max: 100 |
|
} |
|
}, |
|
plugins: { |
|
tooltip: { |
|
callbacks: { |
|
label: function(context) { |
|
return `质量评分: ${context.parsed.y}%`; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
}); |
|
} |
|
|
|
|
|
document.getElementById('copy-logs').addEventListener('click', () => { |
|
const logs = document.querySelector('#logs-content pre').textContent; |
|
navigator.clipboard.writeText(logs).then(() => { |
|
const copyBtn = document.getElementById('copy-logs'); |
|
copyBtn.innerHTML = '<i class="fas fa-check mr-1"></i> 已复制'; |
|
setTimeout(() => { |
|
copyBtn.innerHTML = '<i class="fas fa-copy mr-1"></i> 复制'; |
|
}, 2000); |
|
}); |
|
}); |
|
|
|
|
|
document.getElementById('clear-logs').addEventListener('click', () => { |
|
document.querySelector('#logs-content pre').textContent = 'API调用记录已清空'; |
|
}); |
|
</script> |
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> |
|
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=HOrdye/zhengliu" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> |
|
</html> |