Skip to main content

A unified handler for LLM API calls across OpenAI, Anthropic, and Google

Project description

LLM Handler

A unified Python package for handling LLM API calls across multiple providers (OpenAI, Anthropic, and Google).

Features

  • Unified interface for multiple LLM providers
  • Async and sync support
  • Token limit validation
  • Consistent token counting across providers
  • Built-in error handling
  • Environment variable configuration

Installation

pip install llm-handler

Usage

Async Usage

import asyncio
from llm_handler import LLMHandler

async def main():
    handler = LLMHandler()
    
    response = await handler.get_completion(
        prompt="Tell me a joke",
        model="gpt-4o",
        temperature=0.7,
        max_tokens=100
    )
    
    print(f"Response: {response.text}")
    print(f"Prompt tokens: {response.prompt_tokens}")
    print(f"Completion tokens: {response.completion_tokens}")

asyncio.run(main())

Synchronous Usage

from llm_handler import LLMHandler

handler = LLMHandler()
response = handler.get_completion_sync(
    prompt="Tell me a joke",
    model="gpt-4o",
    temperature=0.7,
)
print(response.text)

Supported Models

OpenAI

  • gpt-4o
  • gpt-4o-mini
  • o1-preview
  • o1-mini

Anthropic

  • claude-3-opus-latest
  • claude-3-sonnet-latest

Google

  • gemini-1.5-pro

Configuration

Create a .env file in your project root:

OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
GOOGLE_API_KEY=your_google_key

License

MIT License - see LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_handler-0.1.4.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

llm_handler-0.1.4-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_handler-0.1.4.tar.gz.

File metadata

  • Download URL: llm_handler-0.1.4.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for llm_handler-0.1.4.tar.gz
Algorithm Hash digest
SHA256 46854b62e8d233a0ea103d4c39fc50a44b3f4076f9d3d57f8fcf8f690b18a8aa
MD5 f62bac399472c6e090627b08693347c2
BLAKE2b-256 d05ef820a31e0dfd0573dab21574c2d7df4428982cd98e26d8002cb5527fd2fa

See more details on using hashes here.

File details

Details for the file llm_handler-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: llm_handler-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for llm_handler-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 43c910ed133f633161e75d5550378772fd0c0fff203fb3e5e0d27043e24fa2a3
MD5 dfc64f308743f2247bbc9ca30dfa212e
BLAKE2b-256 168ac61f5d4fd8c80f67c9a3b365af5de54c8afbb6839d13fd4acde2b6cb31c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page