Skip to main content

LLM inference SDK, for telemetry and internal model routing

Project description

Maniac Python Client

A minimal python client for Maniac's API. Supports chat completions and dataset uploads.

Installation

pip install maniac

Example Usage

from __future__ import annotations

import asyncio

from maniac import Maniac


async def main() -> None:
    client = Maniac()  # or Maniac({"apiKey": os.environ["MANIAC_API_KEY"]})
    try:
        # Run inference without a container
        # Using kwargs
        standard_response = await client.chat.completions.create(
            model="openai/gpt-4o-mini",
            messages=[{"role": "user", "content": "Tell me a story about france"}],
        )
        print(standard_response["choices"][0]["message"]["content"])  # type: ignore[index]

        # Create a container to collect telemetry
        container = await client.containers.create(
            label="local-test",
            initial_model="openai/gpt-4o-mini",
            initial_system_prompt="You are a helpful assistant that answers questions and discusses travel topics.",
        )

        container_response = await client.chat.completions.create(
            container=container,
            messages=[{"role": "user", "content": "Tell me a story about france"}],
        )
        print(container_response["choices"][0]["message"]["content"])  # type: ignore[index]

        # Stream responses as async iterable
        gen = await client.chat.completions.stream(
            container=container,
            messages=[{"role": "user", "content": "Tell me a story about france"}],
        )
        async for chunk in gen:  # type: ignore[union-attr]
            piece = (
                (chunk.get("choices") or [{}])[0].get("delta", {}).get("content", "")
            )
            if piece:
                print(piece, end="", flush=True)
        print()

        # Stream responses with callback
        async def on_chunk(chunk) -> None:
            piece = (
                (chunk.get("choices") or [{}])[0].get("delta", {}).get("content", "")
            )
            if piece:
                print(piece, end="", flush=True)

        await client.chat.completions.stream(
            {"container": container, "messages": [{"role": "user", "content": "Tell me a story about france"}]},
            on_chunk,
        )

        # Get a container by label and run a completion
        travel_agent = await client.containers.get("local-test")
        email_resp = await client.chat.completions.create(
            container=travel_agent,
            messages=[{"role": "user", "content": "Tell me a story about france"}],
        )
        print(email_resp["choices"][0]["message"]["content"])  # type: ignore[index]

        # Models list / retrieve
        models = await client.models.list()
        print([m["id"] for m in models.get("data", [])])
        model = await client.models.retrieve("openai/gpt-4o-mini")
        print(model)
    finally:
        await client.aclose()


if __name__ == "__main__":
    asyncio.run(main())

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

maniac-0.3.0.tar.gz (47.8 kB view details)

Uploaded Source

Built Distribution

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

maniac-0.3.0-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file maniac-0.3.0.tar.gz.

File metadata

  • Download URL: maniac-0.3.0.tar.gz
  • Upload date:
  • Size: 47.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for maniac-0.3.0.tar.gz
Algorithm Hash digest
SHA256 70781f3d7713351ea1f9ebdbe757bc0946ee1a5b78a9aa490fca6143aa58a680
MD5 839fe11aa3898d852f0a91c4a5004426
BLAKE2b-256 67848b6be0d9d4ed3e3ab91631de62f05eb4e53a72eb680a4dd6a88d53a5bbab

See more details on using hashes here.

File details

Details for the file maniac-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: maniac-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for maniac-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6306433e554d9db4085cb58a22a3d38cc4efb339141de93cc036559a5903ec80
MD5 1a11226b0944fd2350f9f2a809b50d70
BLAKE2b-256 8364016f25f54026a15d3c6a31f962c0bc466ec28f9d9ca77d2159fc5f3a51cd

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