mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-09 03:15:19 +03:00
3.2 KiB
3.2 KiB
In [ ]:
# Install the package
!pip install anthropicIn [ ]:
# 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, LLMChainIn [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 [ ]: