Improve AI assignment error messages for invalid models
Build and Push Docker Image / build (push) Has been cancelled
Details
Build and Push Docker Image / build (push) Has been cancelled
Details
- Add try-catch around OpenAI API call to catch model errors - Provide clearer error messages when model name is invalid - Handle empty response cases with helpful feedback - Suggest checking AI Configuration settings when model fails Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c82406abcf
commit
bf187e4b9a
|
|
@ -136,7 +136,18 @@ async function processAssignmentBatch(
|
|||
maxTokens: 4000,
|
||||
})
|
||||
|
||||
const response = await openai.chat.completions.create(params)
|
||||
let response
|
||||
try {
|
||||
response = await openai.chat.completions.create(params)
|
||||
} catch (apiError) {
|
||||
// Provide clearer error for model-related issues
|
||||
const errorMsg = apiError instanceof Error ? apiError.message : String(apiError)
|
||||
if (errorMsg.includes('model') || errorMsg.includes('does not exist')) {
|
||||
throw new Error(`Invalid AI model "${model}". Please check the model name in Settings > AI Configuration.`)
|
||||
}
|
||||
throw apiError
|
||||
}
|
||||
|
||||
const usage = extractTokenUsage(response)
|
||||
tokensUsed = usage.totalTokens
|
||||
|
||||
|
|
@ -157,7 +168,15 @@ async function processAssignmentBatch(
|
|||
|
||||
const content = response.choices[0]?.message?.content
|
||||
if (!content) {
|
||||
throw new Error('No response from AI')
|
||||
// Check if response indicates an issue
|
||||
const finishReason = response.choices[0]?.finish_reason
|
||||
if (finishReason === 'content_filter') {
|
||||
throw new Error('AI response was filtered. Try a different model or simplify the project descriptions.')
|
||||
}
|
||||
if (!response.choices || response.choices.length === 0) {
|
||||
throw new Error(`No response from model "${model}". This model may not exist or may not be available. Please verify the model name.`)
|
||||
}
|
||||
throw new Error(`Empty response from AI model "${model}". The model may not support this type of request.`)
|
||||
}
|
||||
|
||||
const parsed = JSON.parse(content) as {
|
||||
|
|
|
|||
Loading…
Reference in New Issue