Skip to content

Commit

Permalink
Mrbean/support timeout (#398)
Browse files Browse the repository at this point in the history
Add support for passing in a request timeout to the API
  • Loading branch information
sam-h-bean authored Dec 22, 2022
1 parent 6b60c50 commit 136f759
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion langchain/llms/huggingface_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HuggingFacePipeline(LLM, BaseModel):
pipe = pipeline(
"text-generation", model=model, tokenizer=tokenizer, max_new_tokens=10
)
hf = HuggingFacePipeline(pipeline=pipe
hf = HuggingFacePipeline(pipeline=pipe)
"""

pipeline: Any #: :meta private:
Expand Down
5 changes: 4 additions & 1 deletion langchain/llms/openai.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Wrapper around OpenAI APIs."""
import sys
from typing import Any, Dict, Generator, List, Mapping, Optional
from typing import Any, Dict, Generator, List, Mapping, Optional, Tuple, Union

from pydantic import BaseModel, Extra, Field, root_validator

Expand Down Expand Up @@ -49,6 +49,8 @@ class BaseOpenAI(BaseLLM, BaseModel):
openai_api_key: Optional[str] = None
batch_size: int = 20
"""Batch size to use when passing multiple documents to generate."""
request_timeout: Optional[Union[float, Tuple[float, float]]] = None
"""Timeout for requests to OpenAI completion API. Default is 600 seconds."""

class Config:
"""Configuration for this pydantic object."""
Expand Down Expand Up @@ -98,6 +100,7 @@ def _default_params(self) -> Dict[str, Any]:
"presence_penalty": self.presence_penalty,
"n": self.n,
"best_of": self.best_of,
"request_timeout": self.request_timeout,
}
return {**normal_params, **self.model_kwargs}

Expand Down

0 comments on commit 136f759

Please sign in to comment.