MistralAIEmbeddings retry decorator catches wrong exception type for rate limiting #29125
Open
5 tasks done
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
Checked other resources
Example Code
Making multiple requests in quick succession triggers rate limits
Error Message and Stack Trace (if applicable)
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 286, in invoke
self.generate_prompt(
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 786, in generate_prompt
return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 643, in generate
raise e
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 633, in generate
self._generate_with_cache(
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 851, in _generate_with_cache
result = self._generate(
File "/usr/local/lib/python3.10/site-packages/langchain_mistralai/chat_models.py", line 545, in _generate
response = self.completion_with_retry(
File "/usr/local/lib/python3.10/site-packages/langchain_mistralai/chat_models.py", line 464, in completion_with_retry
rtn = _completion_with_retry(**kwargs)
File "/usr/local/lib/python3.10/site-packages/langchain_mistralai/chat_models.py", line 461, in _completion_with_retry
_raise_on_error(response)
File "/usr/local/lib/python3.10/site-packages/langchain_mistralai/chat_models.py", line 170, in _raise_on_error
raise httpx.HTTPStatusError(
httpx.HTTPStatusError: Error response 429 while fetching https://api.mistral.ai/v1/chat/completions: {"message":"Requests rate limit exceeded"}
Description
The
MistralAIEmbeddings
class currently uses a retry decorator that only catcheshttpx.TimeoutException
, but according to the documentation, it should be handling rate limit (429) errors using thewait_time
parameter.Current Behavior
httpx.TimeoutException
httpx.HTTPStatusError
without retryingwait_time
parameter is documented as "The number of seconds to wait before retrying a request in case of 429 error" but isn't actually used for this purposeExpected Behavior
httpx.HTTPStatusError
to handle 429 rate limit responseswait_time
seconds before retryingwait_time
parameterSystem Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: