update at 2025-10-14 21:52:11
This commit is contained in:
218
web/public/debug-modelstore.html
Normal file
218
web/public/debug-modelstore.html
Normal file
@@ -0,0 +1,218 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ModelStore Debug</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
h1 { color: #333; }
|
||||
.section {
|
||||
background: #f5f5f5;
|
||||
padding: 15px;
|
||||
margin: 15px 0;
|
||||
border-radius: 5px;
|
||||
}
|
||||
pre {
|
||||
background: white;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 3px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
button {
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin: 5px;
|
||||
}
|
||||
button:hover {
|
||||
background: #45a049;
|
||||
}
|
||||
.error { color: red; }
|
||||
.success { color: green; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ModelStore 调试工具</h1>
|
||||
|
||||
<div class="section">
|
||||
<h2>LocalStorage 数据</h2>
|
||||
<button onclick="checkLocalStorage()">检查 LocalStorage</button>
|
||||
<button onclick="clearLocalStorage()">清空 model-providers</button>
|
||||
<pre id="localStorage-data">点击"检查 LocalStorage"查看数据</pre>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>测试添加模型服务</h2>
|
||||
<button onclick="addTestProvider()">添加测试 OpenAI 服务</button>
|
||||
<button onclick="addTestOllama()">添加测试 Ollama 服务</button>
|
||||
<pre id="add-result"></pre>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>当前配置</h2>
|
||||
<button onclick="showCurrentConfig()">显示当前配置</button>
|
||||
<pre id="current-config"></pre>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function checkLocalStorage() {
|
||||
const data = {
|
||||
'model-providers': localStorage.getItem('model-providers'),
|
||||
'global-model-settings': localStorage.getItem('global-model-settings'),
|
||||
'all-keys': Object.keys(localStorage)
|
||||
}
|
||||
|
||||
document.getElementById('localStorage-data').textContent = JSON.stringify(data, null, 2)
|
||||
|
||||
if (data['model-providers']) {
|
||||
try {
|
||||
const providers = JSON.parse(data['model-providers'])
|
||||
console.log('Parsed providers:', providers)
|
||||
} catch (e) {
|
||||
console.error('Parse error:', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearLocalStorage() {
|
||||
localStorage.removeItem('model-providers')
|
||||
document.getElementById('localStorage-data').textContent = 'model-providers 已清空'
|
||||
setTimeout(checkLocalStorage, 500)
|
||||
}
|
||||
|
||||
function addTestProvider() {
|
||||
const providers = []
|
||||
|
||||
// 添加 OpenAI 测试配置
|
||||
const openaiProvider = {
|
||||
id: 'openai-test-' + Date.now(),
|
||||
name: 'OpenAI 测试',
|
||||
type: 'openai',
|
||||
enabled: true,
|
||||
apiKey: 'sk-test-key',
|
||||
baseUrl: 'https://api.openai.com/v1',
|
||||
models: [
|
||||
{
|
||||
id: 'gpt-4',
|
||||
name: 'GPT-4',
|
||||
maxTokens: 8192,
|
||||
temperature: 0.7
|
||||
},
|
||||
{
|
||||
id: 'gpt-3.5-turbo',
|
||||
name: 'GPT-3.5 Turbo',
|
||||
maxTokens: 4096,
|
||||
temperature: 0.7
|
||||
}
|
||||
],
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString()
|
||||
}
|
||||
|
||||
// 读取现有配置
|
||||
const existing = localStorage.getItem('model-providers')
|
||||
if (existing) {
|
||||
try {
|
||||
const existingProviders = JSON.parse(existing)
|
||||
providers.push(...existingProviders)
|
||||
} catch (e) {
|
||||
console.error('Parse existing error:', e)
|
||||
}
|
||||
}
|
||||
|
||||
providers.push(openaiProvider)
|
||||
|
||||
localStorage.setItem('model-providers', JSON.stringify(providers))
|
||||
document.getElementById('add-result').innerHTML = '<span class="success">✓ 已添加 OpenAI 测试服务</span>'
|
||||
setTimeout(checkLocalStorage, 500)
|
||||
}
|
||||
|
||||
function addTestOllama() {
|
||||
const providers = []
|
||||
|
||||
// 添加 Ollama 测试配置
|
||||
const ollamaProvider = {
|
||||
id: 'ollama-test-' + Date.now(),
|
||||
name: 'Ollama 本地',
|
||||
type: 'ollama',
|
||||
enabled: true,
|
||||
baseUrl: 'http://localhost:11434',
|
||||
models: [
|
||||
{
|
||||
id: 'llama2',
|
||||
name: 'Llama 2',
|
||||
maxTokens: 4096,
|
||||
temperature: 0.7
|
||||
},
|
||||
{
|
||||
id: 'mistral',
|
||||
name: 'Mistral',
|
||||
maxTokens: 8192,
|
||||
temperature: 0.7
|
||||
}
|
||||
],
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString()
|
||||
}
|
||||
|
||||
// 读取现有配置
|
||||
const existing = localStorage.getItem('model-providers')
|
||||
if (existing) {
|
||||
try {
|
||||
const existingProviders = JSON.parse(existing)
|
||||
providers.push(...existingProviders)
|
||||
} catch (e) {
|
||||
console.error('Parse existing error:', e)
|
||||
}
|
||||
}
|
||||
|
||||
providers.push(ollamaProvider)
|
||||
|
||||
localStorage.setItem('model-providers', JSON.stringify(providers))
|
||||
document.getElementById('add-result').innerHTML = '<span class="success">✓ 已添加 Ollama 测试服务</span>'
|
||||
setTimeout(checkLocalStorage, 500)
|
||||
}
|
||||
|
||||
function showCurrentConfig() {
|
||||
const providers = localStorage.getItem('model-providers')
|
||||
if (providers) {
|
||||
try {
|
||||
const parsed = JSON.parse(providers)
|
||||
const summary = {
|
||||
总数: parsed.length,
|
||||
已启用: parsed.filter(p => p.enabled).length,
|
||||
服务列表: parsed.map(p => ({
|
||||
名称: p.name,
|
||||
类型: p.type,
|
||||
启用: p.enabled,
|
||||
模型数: p.models?.length || 0,
|
||||
模型列表: p.models?.map(m => m.name) || []
|
||||
}))
|
||||
}
|
||||
document.getElementById('current-config').textContent = JSON.stringify(summary, null, 2)
|
||||
} catch (e) {
|
||||
document.getElementById('current-config').innerHTML = '<span class="error">解析错误: ' + e.message + '</span>'
|
||||
}
|
||||
} else {
|
||||
document.getElementById('current-config').textContent = '暂无配置'
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时自动检查
|
||||
window.onload = function() {
|
||||
checkLocalStorage()
|
||||
showCurrentConfig()
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user