fix(stage-ui): auto fallback with LLM model listing when validating (#643)

This commit is contained in:
Iro
2025-10-09 02:31:14 +08:00
committed by GitHub
parent e700a60418
commit 6995aba8a1
@@ -110,6 +110,25 @@ export function buildOpenAICompatibleProvider(
}
const validationChecks = validation || []
// Auto-detect first available model for validation
let model = 'test' // fallback to `test` if fails
try {
const models = await listModels({
apiKey,
baseURL: baseUrl,
headers: {
...additionalHeaders,
Authorization: `Bearer ${apiKey}`,
},
})
if (models && models.length > 0)
model = models[0].id
}
catch (e) {
console.warn(`Model auto-detection failed: ${(e as Error).message}`)
}
// Health check = try generating text (was: fetch(`${baseUrl}chat/completions`))
if (validationChecks.includes('health')) {
@@ -121,7 +140,7 @@ export function buildOpenAICompatibleProvider(
...additionalHeaders,
Authorization: `Bearer ${apiKey}`,
},
model: 'test',
model: model,
messages: message.messages(message.user('ping')),
max_tokens: 1,
})
@@ -161,7 +180,7 @@ export function buildOpenAICompatibleProvider(
...additionalHeaders,
Authorization: `Bearer ${apiKey}`,
},
model: 'test',
model: model,
messages: message.messages(message.user('ping')),
max_tokens: 1,
})