Skip to content

Commit

Permalink
cohere[patch]: support request timeout in BaseCohere (langchain-ai#19641
Browse files Browse the repository at this point in the history
)

As in langchain-ai#19346, this PR exposes `request_timeout` in `BaseCohere`, while
`max_retires` is no longer a parameter of the beneath client
(`cohere.Client`) and it is already configured in
`langchain_cohere.llms.Cohere`.

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
  • Loading branch information
2 people authored and marlenezw committed Apr 2, 2024
1 parent 54f4299 commit 78d2e24
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/partners/cohere/langchain_cohere/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class BaseCohere(Serializable):
streaming: bool = Field(default=False)
"""Whether to stream the results."""

timeout: Optional[float] = 60
"""Timeout in seconds for the Cohere API request."""

user_agent: str = "langchain"
"""Identifier for the application making the request."""

Expand All @@ -82,11 +85,13 @@ def validate_environment(cls, values: Dict) -> Dict:
values["client"] = cohere.Client(
api_key=values["cohere_api_key"].get_secret_value(),
client_name=client_name,
timeout=values["timeout"],
base_url=values["base_url"],
)
values["async_client"] = cohere.AsyncClient(
api_key=values["cohere_api_key"].get_secret_value(),
client_name=client_name,
timeout=values["timeout"],
base_url=values["base_url"],
)
return values
Expand Down

0 comments on commit 78d2e24

Please sign in to comment.