Anthropic LLM Integration for LlamaIndex

0.11.2 · active · verified Wed Apr 15

The `llama-index-llms-anthropic` package provides an integration for using Anthropic's Claude models within the LlamaIndex framework. Anthropic is an AI research company focused on developing advanced language models, notably the Claude series, prioritizing safety and alignment. This integration allows LlamaIndex applications to leverage Anthropic's models for various LLM operations. The current version is `0.11.2`, and it follows LlamaIndex's rapid release cadence with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Anthropic LLM, set the Anthropic API key from an environment variable, configure the LlamaIndex global tokenizer for accurate token counting, and make a basic text completion call using a Claude 3 Opus model.

import os
from llama_index.llms.anthropic import Anthropic
from llama_index.core import Settings

os.environ["ANTHROPIC_API_KEY"] = os.environ.get("ANTHROPIC_API_KEY", "YOUR_ANTHROPIC_API_KEY")

# Initialize the Anthropic LLM
llm = Anthropic(model="claude-3-opus-20240229")

# Set the tokenizer for accurate token counting (important for Anthropic models)
Settings.tokenizer = llm.tokenizer

# Make a completion call
resp = llm.complete("What is the capital of France?")
print(resp)

view raw JSON →