Skip to main content

ChatUpstage

This notebook covers how to get started with Upstage chat models.

Installationโ€‹

Install langchain-upstage package.

pip install -U langchain-upstage

Environment Setupโ€‹

Make sure to set the following environment variables:

Usageโ€‹

import os

os.environ["UPSTAGE_API_KEY"] = "YOUR_API_KEY"
from langchain_core.prompts import ChatPromptTemplate
from langchain_upstage import ChatUpstage

chat = ChatUpstage()
API Reference:ChatPromptTemplate
# using chat invoke
chat.invoke("Hello, how are you?")
# using chat stream
for m in chat.stream("Hello, how are you?"):
print(m)

Chainingโ€‹

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

Was this page helpful?


You can also leave detailed feedback on GitHub.