GigaChat
本筆記本展示如何將 LangChain 與 GigaChat 搭配使用。若要使用,您需要安裝 langchain_gigachat
python 套件。
%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.