Files
langchain/docs/modules/models/llms/integrations/anthropic_example.ipynb
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

Anthropic

Anthropic is creator of the Claude LLM.

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

In [ ]:
# Install the package
!pip install anthropic
In [ ]:
# get a new token: https://www.anthropic.com/earlyaccess

from getpass import getpass

ANTHROPIC_API_KEY = getpass()
In [1]:
from langchain.llms import Anthropic
from langchain import PromptTemplate, LLMChain
In [2]:
template = """Question: {question}

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

prompt = PromptTemplate(template=template, input_variables=["question"])
In [ ]:
llm = Anthropic(, anthropic_api_key=ANTHROPIC_API_KEY)
In [4]:
llm_chain = LLMChain(prompt=prompt, llm=llm)
In [5]:
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.run(question)
Out [5]:
" Step 1: Justin Beiber was born on March 1, 1994\nStep 2: The NFL season ends with the Super Bowl in January/February\nStep 3: Therefore, the Super Bowl that occurred closest to Justin Beiber's birth would be Super Bowl XXIX in 1995\nStep 4: The San Francisco 49ers won Super Bowl XXIX in 1995\n\nTherefore, the answer is the San Francisco 49ers won the Super Bowl in the year Justin Beiber was born."
In [ ]: