Skip to main content

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

Metadata

Release files for llm-handler 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-handler 0.1.4
File Size Uploaded
llm_handler-0.1.4.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-handler 0.1.4
File Interpreter ABI Platform
llm_handler-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / llm_handler-0.1.4.tar.gz

Download URL llm_handler-0.1.4.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
46854b62e8d233a0ea103d4c39fc50a44b3f4076f9d3d57f8fcf8f690b18a8aa
BLAKE2b-256 checksum
How to use checksums
d05ef820a31e0dfd0573dab21574c2d7df4428982cd98e26d8002cb5527fd2fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.6

Release files / llm_handler-0.1.4-py3-none-any.whl

Download URL llm_handler-0.1.4-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43c910ed133f633161e75d5550378772fd0c0fff203fb3e5e0d27043e24fa2a3
BLAKE2b-256 checksum
How to use checksums
168ac61f5d4fd8c80f67c9a3b365af5de54c8afbb6839d13fd4acde2b6cb31c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page