跳到主要内容

GigaChat

此笔记本展示了如何将 LangChain 与 GigaChat 一起使用。要使用,您需要安装 gigachat python 包。

%pip install --upgrade --quiet  gigachat

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

示例

import os
from getpass import getpass

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

llm = GigaChat(verify_ssl_certs=False, scope="GIGACHAT_API_PERS")
API 参考:GigaChat
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"])
API 参考:LLMChain | PromptTemplate
The capital of Russia is Moscow.

此页面是否对您有帮助? (Was this page helpful?)