From b6ba989f2fe06b02077adcd9194595cc3d12246c Mon Sep 17 00:00:00 2001 From: Daniel Chalef <131175+danielchalef@users.noreply.github.com> Date: Sun, 19 Mar 2023 21:19:42 -0600 Subject: [PATCH] Add request timeout to ChatOpenAI (#1798) Add request_timeout field to ChatOpenAI. Defaults to 60s. --------- Co-authored-by: Daniel Chalef --- langchain/chat_models/openai.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/langchain/chat_models/openai.py b/langchain/chat_models/openai.py index 62736b53..bea56fbf 100644 --- a/langchain/chat_models/openai.py +++ b/langchain/chat_models/openai.py @@ -123,6 +123,8 @@ class ChatOpenAI(BaseChatModel, BaseModel): model_kwargs: Dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `create` call not explicitly specified.""" openai_api_key: Optional[str] = None + request_timeout: int = 60 + """Timeout in seconds for the OpenAPI request.""" max_retries: int = 6 """Maximum number of retries to make when generating.""" streaming: bool = False @@ -185,6 +187,7 @@ class ChatOpenAI(BaseChatModel, BaseModel): """Get the default parameters for calling OpenAI API.""" return { "model": self.model_name, + "request_timeout": self.request_timeout, "max_tokens": self.max_tokens, "stream": self.streaming, "n": self.n,