聊天YandexGPT
本笔记本介绍了如何将 Langchain 与 YandexGPT 聊天模型结合使用。
要使用yandexcloudpython 软件包。
%pip install --upgrade --quiet yandexcloud
首先,您应该使用ai.languageModels.user角色。
接下来,您有两个身份验证选项:
-
IAM 令牌。 您可以在 constructor 参数中指定令牌
iam_token或在环境变量YC_IAM_TOKEN. -
API 密钥您可以在 constructor 参数中指定 key
api_key或在环境变量YC_API_KEY.
指定可以使用model_uri参数,请参阅文档了解更多详细信息。
默认情况下,最新版本的yandexgpt-lite从参数中指定的文件夹中使用folder_id或YC_FOLDER_ID环境变量。
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.')