Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Anthropic Conversation (Standalone)

A standalone implementation of an Anthropic conversation integration for Home Assistant that doesn't depend on the Home Assistant core package. This allows you to use Anthropic's Claude AI models in your own applications or integrate them into custom Home Assistant setups.

Features

  • Full conversation handling with Claude AI models
  • Configuration flow support (UI-based setup)
  • Conversation history management
  • Support for all Claude models (3.5 Sonnet, 3.5 Haiku, etc.)
  • Configurable parameters (temperature, max tokens, thinking budget)
  • Standalone operation without Home Assistant core dependencies

Installation

  1. Install the required dependencies:
pip install -r requirements.txt
  1. Set up your Anthropic API key:
export ANTHROPIC_API_KEY="your-api-key-here"

Usage

Standalone Usage

import asyncio
from anthropic_standalone import StandaloneAnthropicIntegration

async def main():
    # Initialize the integration
    integration = StandaloneAnthropicIntegration(
        api_key="your-api-key",
        model="claude-3-5-sonnet-20241022",
        max_tokens=1024,
        temperature=0.7,
        thinking_budget=20000
    )
    
    # Set up the integration
    await integration.async_setup()
    
    # Process messages
    response = await integration.async_process_message(
        "Hello! How can you help me today?",
        conversation_id="my_conversation"
    )
    print(response)
    
    # Clean up
    await integration.async_close()

asyncio.run(main())

Running the Example

python -m anthropic_standalone.example

Configuration Options

  • api_key: Your Anthropic API key (required)
  • model: Claude model to use (default: "claude-3-5-sonnet-20241022")
  • max_tokens: Maximum tokens in response (default: 1024)
  • temperature: Response creativity (0.0-1.0, default: 0.7)
  • thinking_budget: Tokens for extended reasoning (default: 20000)

Available Claude Models

  • claude-3-5-sonnet-20241022 (recommended)
  • claude-3-5-haiku-20241022
  • claude-3-opus-20240229
  • claude-3-sonnet-20240229
  • claude-3-haiku-20240307

File Structure

anthropic_standalone/
├── __init__.py              # Main integration setup and standalone runner
├── api_client.py            # Anthropic API client wrapper
├── config_flow.py           # Configuration flow for UI setup
├── conversation.py          # Conversation entity handler
├── const.py                 # Constants and configuration keys
├── manifest.json            # Integration metadata
├── strings.json             # UI strings and translations
├── requirements.txt         # Python dependencies
├── example.py               # Usage example
└── README.md               # This file

API Methods

StandaloneAnthropicIntegration

  • async_setup(): Initialize the integration
  • async_process_message(message, conversation_id=None): Process a message and get response
  • clear_conversation(conversation_id=None): Clear conversation history
  • async_close(): Clean up resources

Integration with Home Assistant

Method 1: HACS Installation (Recommended)

  1. Add to HACS Custom Repositories:

    • Go to HACS → Integrations → ⋮ → Custom repositories
    • URL: https://github.com/ketan0/ha-anthropic-standalone
    • Category: Integration
  2. Install & Configure:

    • Search for "Anthropic Conversation (Standalone)" in HACS
    • Download and restart Home Assistant

Method 2: Manual Installation

  1. Copy the anthropic_standalone directory to your custom_components folder
  2. Restart Home Assistant

Configuration Options

Option A: YAML Configuration

Add to your configuration.yaml:

# Basic configuration
anthropic_standalone:
  api_key: "your-anthropic-api-key-here"

# Advanced configuration with all options
anthropic_standalone:
  api_key: "your-anthropic-api-key-here"
  model: "claude-3-5-sonnet-20241022"
  max_tokens: 1024
  temperature: 0.7
  thinking_budget: 20000

Configuration Parameters:

  • api_key (required): Your Anthropic API key
  • model (optional): Claude model to use (default: claude-3-5-sonnet-20241022)
  • max_tokens (optional): Maximum response tokens 1-8192 (default: 1024)
  • temperature (optional): Response creativity 0.0-1.0 (default: 0.7)
  • thinking_budget (optional): Extended reasoning tokens 1000-100000 (default: 20000)

Option B: UI Configuration

  1. Go to Settings → Devices & Services → Add Integration
  2. Search for "Anthropic Conversation (Standalone)"
  3. Enter your configuration details in the UI form

Error Handling

The integration includes comprehensive error handling for:

  • Invalid API keys
  • Rate limiting
  • Connection issues
  • API errors
  • Malformed responses

License

This implementation is designed to be compatible with Home Assistant's integration patterns while remaining standalone. It follows the same architectural principles as the official Home Assistant Anthropic integration.

Requirements

  • Python 3.11+
  • anthropic library
  • voluptuous for configuration validation
  • Valid Anthropic API key with billing enabled

Notes

  • Conversation history is maintained per conversation ID
  • History is automatically trimmed to the last 20 messages to manage memory
  • The system message sets up Claude as a helpful assistant in a Home Assistant context
  • All API interactions are asynchronous for better performance

About

Home Assistant Anthropic Conversation integration that works standalone without core dependencies

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages