Skip to main content

mittal-ai

Mittal Analytics' reusable AI harness. Install it as mittal-ai and import it as mittal_ai. It provides:

  • streaming, non-streaming and structured LLM responses;
  • tool-call handling, reusable tool helpers and message-history repair;
  • token-cost calculation;
  • OpenRouter routing and provider preferences;
  • compatibility fixes for Chinese models; and
  • dj-evals events for model requests and tool calls.

The application keeps its API keys. The model declares which provider and base URL the harness should use:

from mittal_ai import AIModel, get_client, get_structured_response
from pydantic import BaseModel


class Summary(BaseModel):
    text: str


model = AIModel(
    name="openai/gpt-5.4",
    api_key="...",
    provider="openrouter",
    base_url="https://openrouter.ai/api/v1",
    input_tokens_cost_usd=2.5,
    input_tokens_cached_cost_usd=0.25,
    output_tokens_cost_usd=15,
    output_tokens_reasoning_cost_usd=15,
)

async with get_client(model) as client:
    async for event in get_structured_response(
        client=client,
        ai_model=model,
        input=[{"role": "user", "content": "Summarise this."}],
        tools=[],
        text_format=Summary,
        reasoning_effort="low",
    ):
        print(event)

The main public entry points are get_response, get_streaming_response and get_structured_response.

Tool helpers

Use format_docstring to customize a reusable tool description and partial_with_doc to bind arguments that should not be exposed to the model:

from mittal_ai import format_docstring, get_streaming_response, partial_with_doc


@format_docstring(entity="company")
def answer_question(_company_id: int, question: str) -> str:
    """Answer a question about a {entity}.

    Args:
        - question: Question asked by the user.
    """
    return f"{_company_id}: {question}"


company_tool = partial_with_doc(answer_question, _company_id=123)

async for event in get_streaming_response(
    user="user-123",
    ai_model=model,
    messages=[{"role": "user", "content": "What changed?"}],
    tools=[company_tool],
    reasoning_effort="low",
):
    print(event)

company_tool preserves the tool metadata while exposing only question; the bound company ID remains private.

Publishing a new version

The release workflow publishes version tags to PyPI using trusted publishing. From a clean working tree, publish the next patch release with:

uv version --bump patch
version=$(uv version --short)

uv run pytest
uv run pre-commit run --all-files

git add pyproject.toml uv.lock
git commit -m "Release version $version"
git tag -a "v$version" -m "v$version"
git push origin main "v$version"

The tag must match the version in pyproject.toml, with a v prefix. Use --bump minor or --bump major when appropriate. PyPI versions are immutable, so every release needs a new version.

Download files

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

Source Distribution

mittal_ai-0.1.3.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

mittal_ai-0.1.3-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mittal_ai-0.1.3.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mittal_ai-0.1.3.tar.gz
Algorithm Hash digest
SHA256 31ce515b8909ab87cd7c21f28c7c5d72954099791055aaea1c8d460b3990b5d7
MD5 8e3b3b2ec2593530c82d6f51875e99ca
BLAKE2b-256 c07380866655660472413af3cb69c5bb25dc89d6317904a6fbcc7ef77b514ec1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mittal_ai-0.1.3.tar.gz:

Publisher: release.yml on Mittal-Analytics/mittal-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: mittal_ai-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mittal_ai-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d9b795ef3001021788d65be17003e6cd205b634397301c501f6b0ee917ce9d4b
MD5 610b0f4e1c28690581cab11baa5ab122
BLAKE2b-256 c1ccb97edc671b72f3449781e020534000a1fbed660d85969c94e8a6fc8094b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mittal_ai-0.1.3-py3-none-any.whl:

Publisher: release.yml on Mittal-Analytics/mittal-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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