mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-16 21:05:20 +02:00
feat(error-handling): implement LLM error adaptation and classification for chat streaming
- Introduced LLMErrorCategory and adapt_llm_exception to normalize LLM exceptions. - Updated llm_retryable_message and llm_permanent_message to utilize the new adaptation logic. - Enhanced classify_stream_exception to classify provider errors and return user-friendly messages. - Added tests for error classification and adaptation to ensure robustness. - Updated frontend error handling to display appropriate messages based on new classifications.
This commit is contained in:
parent
203ef78346
commit
8e8cf96faa
9 changed files with 533 additions and 38 deletions
|
|
@ -63,6 +63,21 @@ function normalizeFreeChatErrorMessage(error: unknown): string {
|
|||
if (code === "THREAD_BUSY") {
|
||||
return "A previous response is still stopping. Please try again in a moment.";
|
||||
}
|
||||
if (code === "MODEL_AUTH_FAILED") {
|
||||
return "This model’s API key is invalid or expired. Switch models, or update the API key.";
|
||||
}
|
||||
if (code === "MODEL_NOT_FOUND") {
|
||||
return "This model is unavailable or no longer exists. Please switch models.";
|
||||
}
|
||||
if (code === "MODEL_CONTEXT_LIMIT") {
|
||||
return "This request is too large for the selected model. Reduce the input or switch models.";
|
||||
}
|
||||
if (code === "MODEL_PROVIDER_UNAVAILABLE") {
|
||||
return "The selected model provider is temporarily unavailable. Please try again or switch models.";
|
||||
}
|
||||
if (code === "RATE_LIMITED") {
|
||||
return "This model is temporarily rate-limited. Please try again in a few seconds or switch models.";
|
||||
}
|
||||
return error.message || "An unexpected error occurred";
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +169,7 @@ export function FreeChatPage() {
|
|||
assistantMsgId: string,
|
||||
signal: AbortSignal,
|
||||
turnstileToken: string | null
|
||||
): Promise<"captcha" | void> => {
|
||||
): Promise<"captcha" | undefined> => {
|
||||
const reqBody: Record<string, unknown> = {
|
||||
model_slug: modelSlug,
|
||||
messages: messageHistory,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue