Skip to main content
Open In Colab在 GitHub 上打开

YandexGPT

本笔记本介绍了如何将 Langchain 与 YandexGPT 一起使用。

要使用yandexcloudpython 软件包。

%pip install --upgrade --quiet  yandexcloud

首先,您应该使用ai.languageModels.user角色。

接下来,您有两个身份验证选项:

  • IAM 令牌。 您可以在 constructor 参数中指定令牌iam_token或在环境变量YC_IAM_TOKEN.

  • API 密钥您可以在 constructor 参数中指定 keyapi_key或在环境变量YC_API_KEY.

指定可以使用model_uri参数,请参阅文档了解更多详细信息。

默认情况下,最新版本的yandexgpt-lite从参数中指定的文件夹中使用folder_idYC_FOLDER_ID环境变量。

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.'