refactor: 重构模型测试错误解析逻辑并修复用量统计变量引用

- 将 ModelsTab 和 ModelAliasesTab 中重复的错误解析逻辑提取到 errorParser.ts
- 添加 parseTestModelError 函数统一处理测试响应错误
- 为 testModel API 添加 TypeScript 类型定义 (TestModelRequest/TestModelResponse)
- 修复 endpoint_checker.py 中 usage_data 变量引用错误
This commit is contained in:
fawney19
2025-12-25 19:36:29 +08:00
parent 26b4a37323
commit dddb327885
6 changed files with 76 additions and 68 deletions

View File

@@ -61,12 +61,34 @@ export async function deleteProvider(providerId: string): Promise<{ message: str
/**
* 测试模型连接性
*/
export async function testModel(data: {
export interface TestModelRequest {
provider_id: string
model_name: string
api_key_id?: string
message?: string
}): Promise<any> {
api_format?: string
}
export interface TestModelResponse {
success: boolean
error?: string
data?: {
response?: {
status_code?: number
error?: string | { message?: string }
choices?: Array<{ message?: { content?: string } }>
}
content_preview?: string
}
provider?: {
id: string
name: string
display_name: string
}
model?: string
}
export async function testModel(data: TestModelRequest): Promise<TestModelResponse> {
const response = await client.post('/api/admin/provider-query/test-model', data)
return response.data
}