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

Help us out by providing feedback on this documentation page: