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

GigaChat 公司

此笔记本介绍如何将 LangChain 与 GigaChat 结合使用。 要使用,您需要安装langchain_gigachatpython 软件包。

%pip install --upgrade --quiet  langchain-gigachat

要获取 GigaChat 凭据,您需要创建帐户访问 API

import os
from getpass import getpass

if "GIGACHAT_CREDENTIALS" not in os.environ:
os.environ["GIGACHAT_CREDENTIALS"] = getpass()
from langchain_gigachat import GigaChat

chat = GigaChat(verify_ssl_certs=False, scope="GIGACHAT_API_PERS")
from langchain_core.messages import HumanMessage, SystemMessage

messages = [
SystemMessage(
content="You are a helpful AI that shares everything you know. Talk in English."
),
HumanMessage(content="What is capital of Russia?"),
]

print(chat.invoke(messages).content)
API 参考:HumanMessage | SystemMessage 系统
The capital of Russia is Moscow.