Skip to main content

simple_module_ai

AI base module for SimpleModule apps: one provider-configurable service layer (chat + embeddings) that every other module shares, with DB-backed settings, encrypted keys and an admin page.

The module owns connection configuration — provider, endpoint, key, model name. Consuming modules own behaviour — agents, prompts, temperature, retries, streaming.

Full documentation lives in docs/: user guide (the AI settings page), API reference (the sm_ai.contracts API and the HTTP routes), operations (install, settings and SM_AI_* env fallback, key rotation, troubleshooting) and architecture.

Install

pip install simple_module_ai

Add simple_module_ai to your host's dependencies; it is discovered at boot via the simple_module entry point. There are no tables and no migrations.

Usage (consuming from another module)

Declare the dependency in your module's ModuleMeta:

meta = ModuleMeta(name="MyModule", depends_on=["Ai"], ...)

Then resolve connections wherever you need them:

from pydantic_ai import Agent
from sm_ai.contracts import AiNotConfiguredError, resolve_model, resolve_embedder

agent = Agent(instructions="...", output_type=MySchema)
result = await agent.run(text, model=resolve_model())

embedder = resolve_embedder()          # raises AiNotConfiguredError until the
result = await embedder.embed_documents(chunks)  # embedding slot is set up

resolve_model(model_name=...) overrides the configured model name for same-endpoint multi-model setups. embedding_dim() returns the configured vector width. All errors subclass AiError.

The import package is sm_ai, not ai — the bare name belongs to another PyPI project and would collide in hosts that install it.

Settings

Two slots — chat and embeddings — each with provider (anthropic, openai, google, openai_compatible), model, base URL and API key. The openai_compatible provider covers vLLM, Ollama and LM Studio (base URL required; a blank key is replaced by a protocol-satisfying placeholder).

Configure at /ai/ (permission ai.manage) or seed via SM_AI_* env vars (e.g. SM_AI_CHAT_MODEL); DB values win over env. API keys are encrypted at rest with a key derived from SM_SECRET_KEY — rotating that secret means re-entering provider keys (the old ciphertexts surface as unreadable). A settings save hot-reloads the worker that handled it; other workers pick the change up on restart.

Routes

Route Purpose
GET /ai/ admin settings page
GET/PUT /api/ai/settings read (secrets masked) / update
POST /api/ai/test probe the chat or embedding slot
POST /api/ai/models list the model ids the slot's saved endpoint serves (first 500, sorted)

Writes require an X-CSRF-Token header bound to the session (the admin page sends it automatically; the token is mirrored to the sm_ai_csrf cookie).

Metadata

Release files for simple-module-ai 0.0.11

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

Source distribution (sdist)

Source distribution for simple-module-ai 0.0.11
File Size Uploaded
simple_module_ai-0.0.11.tar.gz 48.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-module-ai 0.0.11
File Interpreter ABI Platform
simple_module_ai-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 82.9 kB

Release files / simple_module_ai-0.0.11.tar.gz

Download URL simple_module_ai-0.0.11.tar.gz
Size 48.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d51d37c1508d87a7033723d44ecdd0af8ede1b5a9eb3bc74176dbdb2be07e963
BLAKE2b-256 checksum
How to use checksums
3cff58162acb61a0aa61c7c05b19be0badc76480b7726d7ba734cef8f7a48505
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release files / simple_module_ai-0.0.11-py3-none-any.whl

Download URL simple_module_ai-0.0.11-py3-none-any.whl
Size 34.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43bbd6b88142fd345f8cec1d74caa09adbfa84ebffbd5d695a0e7ecaf31e067b
BLAKE2b-256 checksum
How to use checksums
8e56614537cff36dbe5aa3644e9c9dc665679f21d1ccb0c07580fd6064ed1258
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

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