Skip to main content

Minimal, reusable AI service handlers for Gemini and other LLMs

Project description

AI Proxy Core

A minimal Python package providing reusable AI service handlers for Gemini and other LLMs. No web framework dependencies - just the core logic.

Installation

pip install ai-proxy-core

Or install from source:

git clone https://github.com/ebowwa/ai-proxy-core.git
cd ai-proxy-core
pip install -e .

Usage

Completions Handler

from ai_proxy_core import CompletionsHandler

# Initialize handler
handler = CompletionsHandler(api_key="your-gemini-api-key")

# Create completion
response = await handler.create_completion(
    messages=[
        {"role": "user", "content": "Hello, how are you?"}
    ],
    model="gemini-1.5-flash",
    temperature=0.7
)

print(response["choices"][0]["message"]["content"])

Gemini Live Session

from ai_proxy_core import GeminiLiveSession

# Create session
session = GeminiLiveSession(api_key="your-gemini-api-key")

# Set up callbacks
session.on_audio = lambda data: print(f"Received audio: {len(data)} bytes")
session.on_text = lambda text: print(f"Received text: {text}")

# Start session
await session.start()

# Send audio/text
await session.send_audio(audio_data)
await session.send_text("Hello!")

# Stop when done
await session.stop()

Integration with FastAPI

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from ai_proxy_core import CompletionsHandler

app = FastAPI()
handler = CompletionsHandler()

class CompletionRequest(BaseModel):
    messages: list
    model: str = "gemini-1.5-flash"
    temperature: float = 0.7

@app.post("/api/chat/completions")
async def create_completion(request: CompletionRequest):
    try:
        response = await handler.create_completion(
            messages=request.messages,
            model=request.model,
            temperature=request.temperature
        )
        return response
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

Features

  • No framework dependencies - Use with FastAPI, Flask, or any Python app
  • Async/await support - Modern async Python
  • Type hints - Full type annotations
  • Minimal surface area - Just the core logic you need
  • Easy testing - Mock the handlers in your tests

Development

Building the Package

When building the package for distribution, use setup.py directly instead of python -m build to avoid pip isolation issues:

python setup.py sdist bdist_wheel

This will create both source distribution and wheel files in the dist/ directory.

Publishing to PyPI

twine upload dist/*

License

MIT

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

ai_proxy_core-0.1.3.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_proxy_core-0.1.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file ai_proxy_core-0.1.3.tar.gz.

File metadata

  • Download URL: ai_proxy_core-0.1.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for ai_proxy_core-0.1.3.tar.gz
Algorithm Hash digest
SHA256 48e19314abf401799d61f853acd29bdb1f9c4e977f31d7748fc76974938e9e9d
MD5 619198e2641e93d2c63af485be637943
BLAKE2b-256 16ad3a93cb37163def8f07e99bffcfd129ff70391ca2cda5ce5bdfccb5658051

See more details on using hashes here.

File details

Details for the file ai_proxy_core-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ai_proxy_core-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for ai_proxy_core-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4086e32b033b9f49212d8c326f37c8b15071fd85749263a593645565d41f3601
MD5 3abecca3dd12acc5551f84b33a37632b
BLAKE2b-256 3b303030ffddd9cd372e97daeb405b89b463df077f1282d9d6abfdde7daef51e

See more details on using hashes here.

Supported by

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