fix(clients): pass num_retries and retry_strategy to streaming LLM calls#9507
Open
abdelhadi703 wants to merge 1 commit intostanfordnlp:mainfrom
Open
fix(clients): pass num_retries and retry_strategy to streaming LLM calls#9507abdelhadi703 wants to merge 1 commit intostanfordnlp:mainfrom
abdelhadi703 wants to merge 1 commit intostanfordnlp:mainfrom
Conversation
The streaming path via _get_stream_completion_fn() was calling litellm.acompletion(stream=True) without num_retries or retry_strategy, causing rate limit errors (429) to crash immediately instead of retrying with exponential backoff. Fix: pass num_retries and retry_strategy="exponential_backoff_retry" to _get_stream_completion_fn() and forward them to litellm.acompletion() in the stream_completion closure. Additionally, alitellm_completion() was not passing headers to _get_stream_completion_fn() — fixed alongside. Fixes stanfordnlp#9459
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.
Summary
Fix streaming LLM calls to respect
num_retriesandretry_strategyparameters.Problem:
dspy.streamify()uses_get_stream_completion_fn()which callslitellm.acompletion(stream=True)withoutnum_retriesorretry_strategy. Rate limit errors (429) crash immediately instead of retrying with exponential backoff.Fix:
num_retriesparameter to_get_stream_completion_fn()num_retriesandretry_strategy="exponential_backoff_retry"tolitellm.acompletion(stream=True)litellm_completion()andalitellm_completion()to passnum_retriesalitellm_completion()was also missingheaders— now addedChanges
dspy/clients/lm.py:_get_stream_completion_fn: addednum_retries=0parameterstream_completion()closure: passnum_retriesandretry_strategytolitellm.acompletion(stream=True)litellm_completion: passnum_retriesto_get_stream_completion_fnalitellm_completion: passnum_retriesandheadersto_get_stream_completion_fnReproduction (from issue)
Security/Reliability
retry_strategy=Nonewhennum_retries=0preserves existing behaviorContribution by abdelhadisalmaoui0909@outlook.fr