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
Release history Release notifications | RSS feed
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.2.0.tar.gz
(46.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
maniac-0.2.0-py3-none-any.whl
(35.1 kB
view details)
File details
Details for the file maniac-0.2.0.tar.gz.
File metadata
- Download URL: maniac-0.2.0.tar.gz
- Upload date:
- Size: 46.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
130c73491ad6193cd0953c1fc179a1a5bcfb13f08a13eb7207873d31abb03b91
|
|
| MD5 |
ce7329346e0074d59967bc0a9a5bb82f
|
|
| BLAKE2b-256 |
2b9e9b3245afe064c279bb544f3b7378ee4c24e359fe9f120734d4f4db8eb8d7
|
File details
Details for the file maniac-0.2.0-py3-none-any.whl.
File metadata
- Download URL: maniac-0.2.0-py3-none-any.whl
- Upload date:
- Size: 35.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7272e3149036b2b1180bb86d059b05e44adc74abd0e76ee90c8dbf4fcb659ff7
|
|
| MD5 |
812ffb7c295c8b39a46050269e6cdfa1
|
|
| BLAKE2b-256 |
8242945f0149e1ef9fd3b77795de167faa6fbcbf2dd9bb1956f3f13c2ceae084
|