Skip to main content

YandexGPT

本文介绍如何在YandexGPT中使用Langchain。

要使用,您应该已安装yandexcloud Python包。

%pip install --upgrade --quiet  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.'

Was this page helpful?


You can leave detailed feedback on GitHub.