6大核心模块(Modules)
LLMS
Ai21

LangChain

AI21#

AI21 Studio (opens in a new tab) 提供 API 访问 Jurassic-2 大型语言模型。

本示例介绍如何使用 LangChain 与 AI21 模型 (opens in a new tab) 进行交互。

# install the package:
!pip install ai21
 
# get AI21_API_KEY. Use https://studio.ai21.com/account/account
 
from getpass import getpass
AI21_API_KEY  = getpass()
 
from langchain.llms import AI21
from langchain import PromptTemplate, LLMChain
 
template = """Question: {question}
 
Answer: Let's think step by step."""
 
prompt = PromptTemplate(template=template, input_variables=["question"])
 
llm = AI21(ai21_api_key=AI21_API_KEY)
 
llm_chain = LLMChain(prompt=prompt, llm=llm)
 
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
 
llm_chain.run(question)
 
'\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.'