跳到主要内容
本笔记本介绍了如何将 LangChain 与 YandexGPT 结合使用。 要使用它,您应该安装 yandexcloud python 包。
pip install -qU  yandexcloud
首先,您应该 创建一个具有 ai.languageModels.user 角色 的服务账户。 接下来,您有两种身份验证选项:
  • IAM 令牌。您可以在构造函数参数 iam_token 或环境变量 YC_IAM_TOKEN 中指定令牌。
  • API 密钥。您可以在构造函数参数 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.'

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.