Skip to main content

ChatAI21

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

Installation

!pip install -qU langchain-ai21

Environment Setup

We'll need to get a AI21 API key and set the AI21_API_KEY environment variable:

import os
from getpass import getpass

os.environ["AI21_API_KEY"] = getpass()

Usage

from langchain_ai21 import ChatAI21
from langchain_core.prompts import ChatPromptTemplate

chat = ChatAI21(model="jamba-instruct")

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?"})
AIMessage(content='Bonjour, comment vas-tu?')

Was this page helpful?


You can also leave detailed feedback on GitHub.