> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Replicate 集成

> 使用 LangChain Python 与 Replicate 集成。

本页面介绍了如何在 LangChain 中在 Replicate 上运行模型。

## 安装和设置

* 创建一个 [Replicate](https://replicate.com) 账户。获取您的 API 密钥并将其设置为环境变量（`REPLICATE_API_TOKEN`）
* 使用 `pip install replicate` 安装 [Replicate python 客户端](https://github.com/replicate/replicate-python)

## 调用模型

在 [Replicate 探索页面](https://replicate.com/explore) 上找到模型，然后将模型名称和版本以这种格式粘贴进来：`owner-name/model-name:version`

例如，对于这个 [dolly 模型](https://replicate.com/replicate/dolly-v2-12b)，点击 API 标签。模型名称/版本将是：`"replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5"`

只需要 `model` 参数是必需的，但也可以使用格式 `input={model_param: value, ...}` 传递任何其他模型参数

例如，如果我们正在运行 stable diffusion 并想更改图像尺寸：

```
Replicate(model="stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf", input={'image_dimensions': '512x512'})
```

*注意，模型只会返回第一个输出。*
从这里，我们可以初始化我们的模型：

```python theme={null}
llm = Replicate(model="replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5")
```

然后运行它：

```python theme={null}
prompt = """
Answer the following yes/no question by reasoning step by step.
Can a dog drive a car?
"""
llm(prompt)
```

我们可以使用这种语法调用任何 Replicate 模型（不仅限于 LLM）。例如，我们可以调用 [Stable Diffusion](https://replicate.com/stability-ai/stable-diffusion)：

```python theme={null}
text2image = Replicate(model="stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf", input={'image_dimensions':'512x512'})

image_output = text2image("A cat riding a motorcycle by Picasso")
```

***

> 官方原文：[src/oss/python/integrations/providers/replicate.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/providers/replicate.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.