Files
langchain/docs/modules/models/llms/integrations/ai21.ipynb
T
leo-gan 5420a0e404 updated langchain/docs/modules/models/llms/integrations/ notebooks (#3041)
- Updated `langchain/docs/modules/models/llms/integrations/` notebooks:
added links to the original sites, the install information, etc.
- Added the `nlpcloud` notebook.
- Removed "Example" from Titles of some notebooks, so all notebook
titles are consistent.
2023-04-17 20:25:32 -07:00

3.2 KiB

AI21

AI21 Studio provides API access to Jurassic-2 large language models.

This example goes over how to use LangChain to interact with AI21 models.

In [ ]:
# install the package:
!pip install ai21
In [7]:
# get AI21_API_KEY. Use https://studio.ai21.com/account/account

from getpass import getpass
AI21_API_KEY  = getpass()
 ········
In [8]:
from langchain.llms import AI21
from langchain import PromptTemplate, LLMChain
In [9]:
template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])
In [10]:
llm = AI21(ai21_api_key=AI21_API_KEY)
In [11]:
llm_chain = LLMChain(prompt=prompt, llm=llm)
In [12]:
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.run(question)
Out [12]:
'\n1. What year was Justin Bieber born?\nJustin Bieber was born in 1994.\n2. What team won the Super Bowl in 1994?\nThe Dallas Cowboys won the Super Bowl in 1994.'
In [ ]: