fix(ai): 测试连接改为结构化结果,不再倾倒模型原始回复
返回 {model, latencyMs, tokensUsed, replyLength};前端提示「连接正常:模型 · 耗时 · tokens」。
模型原始回复不回传——测试要的是通没通/多快,不是看模型说了什么(ECHO 假模型下尤其明显)。
空回复时明确报错提示检查 baseURL 是否 OpenAI 兼容。
This commit is contained in:
1 parent
f1d9480caf
commit
5d898e3592
6 files changed
+30
-11
No files matched your search
@@ -83,7 +83,7 @@ export const aiApi = {
|
||||
getConfig: () => http.get<AIConfigResponse>('/ai/config'),
|
||||
saveConfig: (data: Partial<AIConfig>) => http.put<{ config: AIConfig }>('/ai/config', data),
|
||||
testConfig: (data: { baseUrl?: string; model?: string; apiKey?: string }) =>
|
||||
http.post<{ reply: string; model: string }>('/ai/config/test', data, { timeout: 45000 }),
|
||||
http.post<{ model: string; latencyMs: number; tokensUsed: number; replyLength: number }>('/ai/config/test', data, { timeout: 45000 }),
|
||||
analyze: (data: { sourceId: number; start: number; end: number; question?: string; app?: string }) =>
|
||||
http.post<AIAnalyzeResponse>('/ai/analyze', data, { timeout: 180000 }),
|
||||
runs: (page: number, pageSize: number) =>
|
||||
|
||||
@@ -93,7 +93,7 @@ export default {
|
||||
save: 'Save',
|
||||
test: 'Test connection',
|
||||
testing: 'Testing…',
|
||||
testOk: 'Connection OK, model replied: {{reply}}',
|
||||
testOk: 'Connected: {{model}} · {{latency}}s · {{tokens}} tokens',
|
||||
usedToday: '{{used}} tokens used today',
|
||||
},
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ export default {
|
||||
save: '保存配置',
|
||||
test: '测试连接',
|
||||
testing: '测试中…',
|
||||
testOk: '连接正常,模型回复:{{reply}}',
|
||||
testOk: '连接正常:{{model}} · {{latency}}s · {{tokens}} tokens',
|
||||
usedToday: '今日已用 {{used}} tokens',
|
||||
},
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ export default function AiopsPage() {
|
||||
model: config?.model,
|
||||
apiKey: apiKeyInput.trim() || undefined,
|
||||
})
|
||||
toast.success(t('config.testOk', { reply: res.reply || 'OK' }))
|
||||
toast.success(t('config.testOk', { model: res.model, latency: (res.latencyMs / 1000).toFixed(1), tokens: res.tokensUsed }))
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : '连接失败')
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user