Skip to main content

Anthropic Anthropic

The AnthropicLLMService provides conversational reasoning using Anthropic's Claude models. It supports Claude 3.5 Sonnet, Claude 3 Opus, and Claude 3 Haiku, featuring advanced steerability and long context windows.

Installation

To use Anthropic, install the required dependencies:

pip install "piopiy-ai[anthropic]"

Prerequisites

  • An Anthropic account and API key (Get yours here).
  • Set your API key in your environment:
    export ANTHROPIC_API_KEY="your_api_key_here"

Configuration

AnthropicLLMService Parameters

ParameterTypeDefaultDescription
api_keystrNoneAnthropic API key (defaults to env var).
modelstr"claude-3-5-sonnet-latest"Claude model identifier.
max_tokensint4096Maximum tokens for the response.
temperaturefloatNoneSampling temperature (0.0 to 1.0).

Usage

Basic Setup

import os
from piopiy.services.anthropic.llm import AnthropicLLMService

llm = AnthropicLLMService(
api_key=os.getenv("ANTHROPIC_API_KEY"),
model="claude-3-5-sonnet-latest",
temperature=0.7
)

Notes

  • Model Choices: Claude 3.5 Sonnet offers the best balance of speed and intelligence for real-time voice agents.
  • Context Handling: The service automatically manages conversational context and history for use with the LLMContextAggregator.