ChatUpstage
本筆記本涵蓋如何開始使用 Upstage 聊天模型。
安裝
安裝 langchain-upstage
套件。
pip install -U langchain-upstage
環境設定
請務必設定以下環境變數
UPSTAGE_API_KEY
:您的 Upstage API 金鑰,來自 Upstage 控制台。
使用方式
import os
os.environ["UPSTAGE_API_KEY"] = "YOUR_API_KEY"
from langchain_core.prompts import ChatPromptTemplate
from langchain_upstage import ChatUpstage
chat = ChatUpstage()
API 參考文檔:ChatPromptTemplate | ChatUpstage
# using chat invoke
chat.invoke("Hello, how are you?")
# using chat stream
for m in chat.stream("Hello, how are you?"):
print(m)
鏈接
# using chain
prompt = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful assistant that translates English to French."),
("human", "Translate this sentence from English to French. {english_text}."),
]
)
chain = prompt | chat
chain.invoke({"english_text": "Hello, how are you?"})