安装
安装langchain-upstage 包。
环境配置
请确保设置以下环境变量:UPSTAGE_API_KEY: 从 Upstage 控制台 获取您的 Upstage API 密钥。
使用方法
链式调用
官方原文:src/oss/python/integrations/chat/upstage.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
与ChatUpstage对话模型通过LangChain Python集成
langchain-upstage 包。
pip install -U langchain-upstage
UPSTAGE_API_KEY: 从 Upstage 控制台 获取您的 Upstage API 密钥。import os
os.environ["UPSTAGE_API_KEY"] = "YOUR_API_KEY"
from langchain_core.prompts import ChatPromptTemplate
from langchain_upstage import ChatUpstage
chat = ChatUpstage()
# using chat invoke
chat.invoke("Hello, how are you?")
# using chat stream
stream = chat.stream_events("Hello, how are you?", version="v3")
for token in stream.text:
print(token, end="", flush=True)
# 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?"})
官方原文:src/oss/python/integrations/chat/upstage.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。