fix: treat 400 errors as successful connection in model check (parameter mismatch is not a connectivity issue)
This commit is contained in:
@@ -1672,15 +1672,20 @@ func (h *InitializationHandler) checkRemoteModelConnection(ctx context.Context,
|
||||
// 使用聊天实例进行测试
|
||||
_, err = chatInstance.Chat(ctx, testMessages, testOptions)
|
||||
if err != nil {
|
||||
errMsg := err.Error()
|
||||
// 根据错误类型返回不同的错误信息
|
||||
if strings.Contains(err.Error(), "401") || strings.Contains(err.Error(), "unauthorized") {
|
||||
if strings.Contains(errMsg, "401") || strings.Contains(errMsg, "unauthorized") {
|
||||
return false, "认证失败,请检查API Key"
|
||||
} else if strings.Contains(err.Error(), "403") || strings.Contains(err.Error(), "forbidden") {
|
||||
return false, "权限不足,请检查API Key权限:" + err.Error()
|
||||
} else if strings.Contains(err.Error(), "404") || strings.Contains(err.Error(), "not found") {
|
||||
} else if strings.Contains(errMsg, "403") || strings.Contains(errMsg, "forbidden") {
|
||||
return false, "权限不足,请检查API Key权限:" + errMsg
|
||||
} else if strings.Contains(errMsg, "404") || strings.Contains(errMsg, "not found") {
|
||||
return false, "API端点不存在,请检查Base URL"
|
||||
} else if strings.Contains(err.Error(), "timeout") {
|
||||
} else if strings.Contains(errMsg, "timeout") {
|
||||
return false, "连接超时,请检查网络连接"
|
||||
} else if strings.Contains(errMsg, "status code: 400") {
|
||||
// 400 错误说明 API 端点可达、认证通过,只是请求参数不兼容(如 max_tokens vs max_completion_tokens)
|
||||
// 视为连接成功
|
||||
return true, "连接正常,模型可用"
|
||||
} else {
|
||||
return false, fmt.Sprintf("连接失败: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user