Replicate models. To use, you should have the ``replicate`` python package installed, and the environment variable ``REPLICATE_API_TOKEN`` set with your API token. You can find your token here: https://replicate.com/account The model param is required, but any other model parameter
| 16 | |
| 17 | |
| 18 | class Replicate(LLM): |
| 19 | """Replicate models. |
| 20 | |
| 21 | To use, you should have the ``replicate`` python package installed, |
| 22 | and the environment variable ``REPLICATE_API_TOKEN`` set with your API token. |
| 23 | You can find your token here: https://replicate.com/account |
| 24 | |
| 25 | The model param is required, but any other model parameters can also |
| 26 | be passed in with the format model_kwargs={model_param: value, ...} |
| 27 | |
| 28 | Example: |
| 29 | .. code-block:: python |
| 30 | |
| 31 | from langchain_community.llms import Replicate |
| 32 | |
| 33 | replicate = Replicate( |
| 34 | model=( |
| 35 | "stability-ai/stable-diffusion: " |
| 36 | "27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478", |
| 37 | ), |
| 38 | model_kwargs={"image_dimensions": "512x512"} |
| 39 | ) |
| 40 | """ |
| 41 | |
| 42 | model: str |
| 43 | model_kwargs: Dict[str, Any] = Field(default_factory=dict, alias="input") |
| 44 | replicate_api_token: Optional[str] = None |
| 45 | prompt_key: Optional[str] = None |
| 46 | version_obj: Any = Field(default=None, exclude=True) |
| 47 | """Optionally pass in the model version object during initialization to avoid |
| 48 | having to make an extra API call to retrieve it during streaming. NOTE: not |
| 49 | serializable, is excluded from serialization. |
| 50 | """ |
| 51 | |
| 52 | streaming: bool = False |
| 53 | """Whether to stream the results.""" |
| 54 | |
| 55 | stop: List[str] = Field(default_factory=list) |
| 56 | """Stop sequences to early-terminate generation.""" |
| 57 | |
| 58 | class Config: |
| 59 | """Configuration for this pydantic config.""" |
| 60 | |
| 61 | allow_population_by_field_name = True |
| 62 | extra = Extra.forbid |
| 63 | |
| 64 | @property |
| 65 | def lc_secrets(self) -> Dict[str, str]: |
| 66 | return {"replicate_api_token": "REPLICATE_API_TOKEN"} |
| 67 | |
| 68 | @classmethod |
| 69 | def is_lc_serializable(cls) -> bool: |
| 70 | return True |
| 71 | |
| 72 | @classmethod |
| 73 | def get_lc_namespace(cls) -> List[str]: |
| 74 | """Get the namespace of the langchain object.""" |
| 75 | return ["langchain", "llms", "replicate"] |
no outgoing calls