Replicate
本页介绍如何在 LangChain 中在 Replicate 上运行模型。
安装和设置
- 创建一个 Replicate 帐户。获取您的 API 密钥并将其设置为环境变量 (
REPLICATE_API_TOKEN
) - 使用
pip install replicate
安装 Replicate python 客户端
调用模型
在 Replicate 探索页面 上查找模型,然后粘贴此格式的模型名称和版本:owner-name/model-name:version
例如,对于此 dolly 模型,单击 API 选项卡。模型名称/版本为:"replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5"
只需要 model
参数,但任何其他模型参数也可以使用 input={model_param: value, ...}
格式传入
例如,如果我们运行 stable diffusion 并想要更改图像尺寸
Replicate(model="stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf", input={'image_dimensions': '512x512'})
请注意,仅返回模型的第一个输出。 从这里,我们可以初始化我们的模型
llm = Replicate(model="replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5")
并运行它
prompt = """
Answer the following yes/no question by reasoning step by step.
Can a dog drive a car?
"""
llm(prompt)
我们可以使用此语法调用任何 Replicate 模型(不只是 LLM)。例如,我们可以调用 Stable Diffusion
text2image = Replicate(model="stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf", input={'image_dimensions':'512x512'})
image_output = text2image("A cat riding a motorcycle by Picasso")