Skip to content

Commit

Permalink
Import replicate package inside constructor.
Browse files Browse the repository at this point in the history
Signed-off-by: Fayvor Love <[email protected]>
  • Loading branch information
fayvor committed Nov 2, 2024
1 parent b581070 commit 28169fe
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions libs/community/langchain_community/llms/replicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@

if TYPE_CHECKING:
from replicate.prediction import Prediction

try:
from replicate.client import Client
except ImportError:
raise ImportError(
"Could not import replicate python package. "
"Please install it with `pip install replicate`."
)

Check failure on line 17 in libs/community/langchain_community/llms/replicate.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.13

Ruff (I001)

langchain_community/llms/replicate.py:15:1: I001 Import block is un-sorted or un-formatted

Check failure on line 17 in libs/community/langchain_community/llms/replicate.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.9

Ruff (I001)

langchain_community/llms/replicate.py:15:1: I001 Import block is un-sorted or un-formatted
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -65,7 +58,7 @@ class Replicate(LLM):
stop: List[str] = Field(default_factory=list)
"""Stop sequences to early-terminate generation."""

_client: Client = Client()
_client: Client = None

model_config = ConfigDict(
populate_by_name=True,
Expand Down Expand Up @@ -112,6 +105,13 @@ def build_extra(cls, values: Dict[str, Any]) -> Any:
@model_validator(mode="after")
def set_client(self) -> Self:
"""Add a client to the values."""
try:
from replicate.client import Client
except ImportError:
raise ImportError(
"Could not import replicate python package. "
"Please install it with `pip install replicate`."
)
self._client = Client(api_token=self.replicate_api_token)
return self

Expand Down

0 comments on commit 28169fe

Please sign in to comment.