From ed8c0b15dd90d00af3d70ed9cba8355b918c7050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:01:26 +0800 Subject: [PATCH] Add files via upload --- web/static/i18n/en-US.json | 8 +++++- web/static/i18n/zh-CN.json | 8 +++++- web/static/js/settings.js | 51 ++++++++++++++++++++++++++++++++++++++ web/templates/index.html | 4 +++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/web/static/i18n/en-US.json b/web/static/i18n/en-US.json index 30037fe7..ab0bab61 100644 --- a/web/static/i18n/en-US.json +++ b/web/static/i18n/en-US.json @@ -1302,7 +1302,13 @@ "maxRetriesHint": "Retries on rate limit or server error", "retryDelay": "Retry delay (ms)", "retryDelayPlaceholder": "1000", - "retryDelayHint": "Delay between retries (ms)" + "retryDelayHint": "Delay between retries (ms)", + "testConnection": "Test Connection", + "testFillRequired": "Please fill in API Key and Model first", + "testing": "Testing connection...", + "testSuccess": "Connection successful", + "testFailed": "Connection failed", + "testError": "Test error" }, "settingsTerminal": { "title": "Terminal", diff --git a/web/static/i18n/zh-CN.json b/web/static/i18n/zh-CN.json index a17969c9..b485d5d6 100644 --- a/web/static/i18n/zh-CN.json +++ b/web/static/i18n/zh-CN.json @@ -1302,7 +1302,13 @@ "maxRetriesHint": "最大重试次数(默认 3),遇到速率限制或服务器错误时自动重试", "retryDelay": "重试间隔(毫秒)", "retryDelayPlaceholder": "1000", - "retryDelayHint": "重试间隔毫秒数(默认 1000),每次重试会递增延迟" + "retryDelayHint": "重试间隔毫秒数(默认 1000),每次重试会递增延迟", + "testConnection": "测试连接", + "testFillRequired": "请先填写 API Key 和模型", + "testing": "测试中...", + "testSuccess": "连接成功", + "testFailed": "连接失败", + "testError": "测试出错" }, "settingsTerminal": { "title": "终端", diff --git a/web/static/js/settings.js b/web/static/js/settings.js index 97ff4272..c8873b03 100644 --- a/web/static/js/settings.js +++ b/web/static/js/settings.js @@ -959,6 +959,57 @@ async function applySettings() { } } +// 测试OpenAI连接 +async function testOpenAIConnection() { + const btn = document.getElementById('test-openai-btn'); + const resultEl = document.getElementById('test-openai-result'); + + const baseUrl = document.getElementById('openai-base-url').value.trim(); + const apiKey = document.getElementById('openai-api-key').value.trim(); + const model = document.getElementById('openai-model').value.trim(); + + if (!apiKey || !model) { + resultEl.style.color = 'var(--danger-color, #e53e3e)'; + resultEl.textContent = typeof window.t === 'function' ? window.t('settingsBasic.testFillRequired') : '请先填写 API Key 和模型'; + return; + } + + btn.style.pointerEvents = 'none'; + btn.style.opacity = '0.5'; + resultEl.style.color = 'var(--text-muted, #888)'; + resultEl.textContent = typeof window.t === 'function' ? window.t('settingsBasic.testing') : '测试中...'; + + try { + const response = await apiFetch('/api/config/test-openai', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + base_url: baseUrl, + api_key: apiKey, + model: model + }) + }); + + const result = await response.json(); + + if (result.success) { + resultEl.style.color = 'var(--success-color, #38a169)'; + const latency = result.latency_ms ? ` (${result.latency_ms}ms)` : ''; + const modelInfo = result.model ? ` [${result.model}]` : ''; + resultEl.textContent = (typeof window.t === 'function' ? window.t('settingsBasic.testSuccess') : '连接成功') + modelInfo + latency; + } else { + resultEl.style.color = 'var(--danger-color, #e53e3e)'; + resultEl.textContent = (typeof window.t === 'function' ? window.t('settingsBasic.testFailed') : '连接失败') + ': ' + (result.error || '未知错误'); + } + } catch (error) { + resultEl.style.color = 'var(--danger-color, #e53e3e)'; + resultEl.textContent = (typeof window.t === 'function' ? window.t('settingsBasic.testError') : '测试出错') + ': ' + error.message; + } finally { + btn.style.pointerEvents = ''; + btn.style.opacity = ''; + } +} + // 保存工具配置(独立函数,用于MCP管理页面) async function saveToolsConfig() { try { diff --git a/web/templates/index.html b/web/templates/index.html index 26dc42b5..ceea3a4c 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -1371,6 +1371,10 @@ +
+ 测试连接 + +