Skip to main content

GigaChat

这篇笔记展示了如何在 GigaChat 中使用 LangChain。要使用它,你需要安装 gigachat Python 包。

%pip install --upgrade --quiet  gigachat

要获取 GigaChat 凭据,你需要创建账户获取 API 访问权限

示例

import os
from getpass import getpass
os.environ["GIGACHAT_CREDENTIALS"] = getpass()
from langchain_community.llms import GigaChat
llm = GigaChat(verify_ssl_certs=False, scope="GIGACHAT_API_PERS")
from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
template = "What is capital of {country}?"
prompt = PromptTemplate.from_template(template)
llm_chain = LLMChain(prompt=prompt, llm=llm)
generated = llm_chain.invoke(input={"country": "Russia"})
print(generated["text"])
俄罗斯的首都是莫斯科。

Was this page helpful?


You can leave detailed feedback on GitHub.