/openweb-ui-anthropic-async

An async version of Open WebUI's Anthropic Manifold function

Primary LanguagePython

OpenWebUI Anthropic Async Pipe

An async implementation of the Anthropic Claude integration for OpenWebUI, converted from the synchronous version to use aiohttp for better performance and scalability.

Features

  • Async/Await Support - Full async implementation using aiohttp
  • Streaming Responses - Real-time text generation with async generators
  • Image Processing - Support for both base64 and URL images with size validation
  • Multiple Models - Support for Claude Sonnet 4 and Opus 4
  • Error Handling - Comprehensive error handling and validation
  • OpenWebUI Compatible - Drop-in replacement for the sync version

Installation

  1. Install dependencies:

    uv sync
  2. Set your Anthropic API key:

    export ANTHROPIC_API_KEY=your_api_key_here

Usage

The async pipe can be used as a drop-in replacement for the synchronous version in OpenWebUI. The pipe function signature is compatible with OpenWebUI's async function calling pattern.

from anthropic_async import Pipe

# Initialize the pipe
pipe = Pipe()

# Use in async context
async def example():
    body = {
        "model": "anthropic.claude-sonnet-4-20250514",
        "messages": [{"role": "user", "content": "Hello!"}],
        "stream": False
    }
    
    response = await pipe.pipe(body)
    print(response)

Testing

Comprehensive integration tests using pytest test all functionality against the real Anthropic API.

Setup

# Install dependencies including test dependencies
uv sync

# Set API key
export ANTHROPIC_API_KEY=your_api_key_here

Run Tests

# Run all tests
just test

# Run specific test categories
just test-streaming    # Only streaming tests
just test-images       # Only image tests
just test-errors       # Only error handling tests
just test-slow         # Only slow tests

# Run tests by name pattern
just test-name "image_url"

# Or use pytest directly
uv run pytest tests/ -v

Test Coverage

  • ✅ Non-streaming and streaming responses
  • ✅ Image processing (base64 and URLs)
  • ✅ System message handling
  • ✅ Multiple Claude models
  • ✅ Error handling and validation
  • ✅ Concurrent request handling
  • ✅ Parametrized test cases

Key Differences from Sync Version

  1. Async Methods: All HTTP operations use aiohttp instead of requests
  2. Image Processing: URL image validation is now async
  3. Streaming: Uses async generators for streaming responses
  4. Error Handling: Updated for aiohttp.ClientError exceptions
  5. Performance: Better handling of concurrent requests

Development

Available Commands

This project uses just for task automation:

# Show all available commands
just

# Run tests
just test
just test-streaming
just test-images

# Code quality
just format        # Format with black
just lint-ruff     # Lint with ruff
just lint-fix      # Lint and auto-fix

# Development
just run           # Run the main module
just install       # Install dependencies
just update        # Update dependencies

This project uses opencode as a copilot for development assistance.