Documentation Index
Fetch the complete documentation index at: https://langchain.idochub.dev/llms.txt
Use this file to discover all available pages before exploring further.
This example goes over how to use LangChain to interact with Anthropic models.
Installation
%pip install -qU langchain-anthropic
Environment Setup
We’ll need to get an Anthropic API key and set the ANTHROPIC_API_KEY environment variable:
import os
from getpass import getpass
if "ANTHROPIC_API_KEY" not in os.environ:
os.environ["ANTHROPIC_API_KEY"] = getpass()
Usage
from langchain_anthropic import AnthropicLLM
from langchain_core.prompts import PromptTemplate
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate.from_template(template)
model = AnthropicLLM(model="claude-2.1")
chain = prompt | model
chain.invoke({"question": "What is LangChain?"})
'\nLangChain is a decentralized blockchain network that leverages AI and machine learning to provide language translation services.'