Improve AI filtering error handling and visibility

- Add listAvailableModels() and validateModel() to openai.ts
- Improve testOpenAIConnection() to test configured model
- Add checkAIStatus endpoint to filtering router
- Add pre-execution AI config check in executeRules
- Improve error messages in AI filtering service (rate limit, quota, etc.)
- Add AI status warning banner on round detail page for filtering rounds

Now admins get clear errors when AI is misconfigured instead of silent flags.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-03 10:46:38 +01:00
parent d45eccea47
commit d068d9b6f6
4 changed files with 214 additions and 8 deletions

View File

@@ -383,13 +383,40 @@ Return your evaluation as JSON.`
}
}
} catch (error) {
// OpenAI error — flag all for manual review
// OpenAI error — flag all for manual review with specific error info
console.error('[AI Filtering] OpenAI API error:', error)
// Extract meaningful error message
let errorType = 'unknown_error'
let errorDetail = 'Unknown error occurred'
if (error instanceof Error) {
const message = error.message.toLowerCase()
if (message.includes('rate_limit') || message.includes('rate limit')) {
errorType = 'rate_limit'
errorDetail = 'OpenAI rate limit exceeded. Try again in a few minutes.'
} else if (message.includes('model') && (message.includes('not found') || message.includes('does not exist'))) {
errorType = 'model_not_found'
errorDetail = 'The configured AI model is not available. Check Settings → AI.'
} else if (message.includes('insufficient_quota') || message.includes('quota')) {
errorType = 'quota_exceeded'
errorDetail = 'OpenAI API quota exceeded. Check your billing settings.'
} else if (message.includes('invalid_api_key') || message.includes('unauthorized')) {
errorType = 'invalid_api_key'
errorDetail = 'Invalid OpenAI API key. Check Settings → AI.'
} else if (message.includes('context_length') || message.includes('token')) {
errorType = 'context_length'
errorDetail = 'Request too large. Try with fewer projects or shorter descriptions.'
} else {
errorDetail = error.message
}
}
for (const p of projects) {
results.set(p.id, {
meetsCriteria: false,
confidence: 0,
reasoning: `AI screening error — flagged for manual review`,
reasoning: `AI screening error (${errorType}): ${errorDetail}`,
qualityScore: 5,
spamRisk: false,
})