fix: show user-friendly error when model doesn't support images (#55)

When models like DeepSeek (deepseek-chat, deepseek-reasoner) receive image
inputs, they return a cryptic error about 'unknown variant image_url'.
This change detects such errors and shows a clear message asking users
to remove the image or switch to a vision-capable model.

Fixes #42
This commit is contained in:
Dayuan Jiang
2025-12-03 19:49:58 +09:00
committed by GitHub
parent 33fed6fa9f
commit 595f24857a

View File

@@ -331,15 +331,20 @@ IMPORTANT: Keep edits concise:
return 'unknown error';
}
if (typeof error === 'string') {
return error;
const errorString = typeof error === 'string'
? error
: error instanceof Error
? error.message
: JSON.stringify(error);
// Check for image not supported error (e.g., DeepSeek models)
if (errorString.includes('image_url') ||
errorString.includes('unknown variant') ||
(errorString.includes('image') && errorString.includes('not supported'))) {
return 'This model does not support image inputs. Please remove the image and try again, or switch to a vision-capable model.';
}
if (error instanceof Error) {
return error.message;
}
return JSON.stringify(error);
return errorString;
}
return result.toUIMessageStreamResponse({