跳到主要內容

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.

此頁面是否對您有幫助?