YandexGPT
本 Notebook 将介绍如何将 Langchain 与 YandexGPT 结合使用。
要使用,您应该已安装 yandexcloud python 包。
%pip install --upgrade --quiet yandexcloud
首先,您需要创建一个具有 ai.languageModels.user 角色的服务账号。
接下来,您有两种身份验证选项:
-
IAM token。 您可以在构造函数参数
iam_token或环境变量YC_IAM_TOKEN中指定令牌。 -
API key 您可以在构造函数参数
api_key或环境变量YC_API_KEY中指定密钥。
要指定模型,您可以使用 model_uri 参数,有关更多详细信息,请参阅文档。
默认情况下,将使用 folder_id 参数或 YC_FOLDER_ID 环境变量中指定的文件夹内的最新版本的 yandexgpt-lite。
from langchain.chains import LLMChain
from langchain_community.llms import YandexGPT
from langchain_core.prompts import PromptTemplate
template = "What is the capital of {country}?"
prompt = PromptTemplate.from_template(template)
llm = YandexGPT()
llm_chain = LLMChain(prompt=prompt, llm=llm)
country = "Russia"
llm_chain.invoke(country)
'The capital of Russia is Moscow.'
Related
- LLM conceptual guide
- LLM how-to guides