feat: add centralized retry mechanism for LLM providers #13793
Open
tdakanalis wants to merge 1 commit intoinfiniflow:mainfrom
Open
feat: add centralized retry mechanism for LLM providers #13793tdakanalis wants to merge 1 commit intoinfiniflow:mainfrom
tdakanalis wants to merge 1 commit intoinfiniflow:mainfrom
Conversation
Extract duplicated retry logic from chat_model.py into a new rag/llm/retry.py module with decorators (@Retry, @retry_or_fallback) for consistent error handling across all LLM providers (embedding, CV, rerank, TTS, OCR, speech2text). Key changes: - New rag/llm/retry.py module with: - @Retry: decorator for sync methods that retries on transient errors - @retry_or_fallback: decorator that returns fallback value on failure - is_retryable(): check if exception is transient - classify_error(): categorize exceptions into LLMErrorCode - async_handle_exception(): shared async error handler - Updated all LLM model classes to use centralized retry decorators - Added exception handling to caller sites (parser.py, conversation_app.py) - Fixed LLMErrorCode.ERROR_MAX_ROUNDS value for consistency - Added comprehensive unit tests in test/unit_test/rag/llm/test_retry.py Behavior preserved: - Same default retry settings (max_retries=5, base_delay=2.0) - Same retryable error signals (rate limits, 5xx server errors) - Same backoff jitter formula (base_delay * uniform(10, 150))
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13793 +/- ##
=======================================
Coverage 96.72% 96.72%
=======================================
Files 10 10
Lines 702 702
Branches 112 112
=======================================
Hits 679 679
Misses 5 5
Partials 18 18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
This PR solves the problem of duplicated and inconsistent retry logic across LLM model implementations.
Background:
Previously, each LLM model class (embedding, CV, rerank, TTS, OCR, speech2text) had its own ad-hoc retry implementation, leading to:
Solution:
Behavior preserved:
Type of change