跳到主要内容
本笔记本介绍了如何开始使用 Upstage 聊天模型。

安装

安装 langchain-upstage 包。
pip install -U langchain-upstage

环境设置

请确保设置以下环境变量

用法

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
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?"})

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.