ChatYandexGPT
这个笔记本介绍了如何使用LangChain与YandexGPT聊天模型。
要使用,请确保已经安装了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_community.chat_models import ChatYandexGPT
from langchain_core.messages import HumanMessage, SystemMessage
chat_model = ChatYandexGPT()
answer = chat_model.invoke(
[
SystemMessage(
content="You are a helpful assistant that translates English to French."
),
HumanMessage(content="I love programming."),
]
)
answer
AIMessage(content='Je adore le programmement.')