Closed lukasugar closed 2 months ago
To address the issue with the maxRetries
parameter not being properly passed to ChatOpenAI
, it's important to note that the parameter needs to be dynamically included in the client configuration. The current setup might have maxRetries
hardcoded to 0
in the client configuration, which would prevent any retry attempts from being made.
To ensure maxRetries
is utilized as intended, you should:
maxRetries
is part of the ChatOpenAI
configuration passed to the OpenAI client. If it's not, you'll need to add it.maxRetries
value from the ChatOpenAI
configuration instead of a hardcoded value.This approach will enable the retry mechanism to function according to the specified maxRetries
value. The default behavior without specifying maxRetries
does not include a retry mechanism, contrary to a 6-time retry with exponential backoff.
Implementing or adjusting the retry logic to respect the maxRetries
parameter will ensure that your requests to OpenAI have the desired level of resilience against failures.
I'm passing maxRetries
exactly as in the docs: https://js.langchain.com/docs/modules/model_io/chat/dealing_with_api_errors
Should this line be changed from 0 to 6 to match the documentation: https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-openai/src/chat_models.ts#L916
const endpoint = getEndpoint(openAIEndpointConfig);
const params = {
...this.clientConfig,
baseURL: endpoint,
timeout: this.timeout,
maxRetries: 0, // change to 6
};
@lukasugar Thanks for reporting this.
@jacoblee93 can you help me with the review?
@rahilvora thanks you for picking it up. I hope this fix gets shipped soon :) I hope @jacoblee93 will have time to review the PR soon, in the meantime I added a small comment there :)
Hey @lukasugar! We only retry certain types of errors - things like 400s will not be retried (it wouldn't make sense to retry something like You requested a model that is not compatible with this engine. Please contact us through our help center at help.openai.com for further questions.
because it would never succeed).
We could look into adding maxRetries
to the traced invocationParams
in LangSmith though.
Checked other resources
Example Code
I have this code for creating a chain with ChatOpenAI client:
I invoke the chain like this:
Error Message and Stack Trace (if applicable)
No response
Description
The openai call returned an error but no retries were made. OpenAI error:
The langsmith logs show that retries parameter is present in the metadata passed
But when looking at invocation metadata in LangSmith, the retry parameter isn't present:
How to properly pass
maxRetries
parameter to ChatOpenAI? I want to specify a specific number, but does not specifying it at all really default to a 6 time retry with exponential backoff?System Info
Running on an ec2 instance with linux
Langchain versions: