patera-aiinterface
Experimental LLM interface for Patera: prompts, chat history and retrieval augmentation. Part of Patera, a modular async-first Python web framework.
Experimental. This package is not yet ready for production use; its API may change in any release.
Installation
pip install patera-aiinterface
# with retrieval augmentation (sentence-transformers, PyTorch, pgvector)
pip install "patera-aiinterface[augmentation]"
Requires Python 3.13 or newer and patera>=0.121.
Usage
patera-aiinterface connects to chat completion APIs (OpenAI-compatible and Ollama). Retrieval
augmentation needs the augmentation extra; everything else works without it.
from typing import AsyncIterator, Optional
from patera.aiinterface import (
AiService, AiServiceConfig, ChatResponse, SqlHistoryProvider, history, system_prompt, user_prompt,
)
from patera.aiinterface.service_provider.openai import OpenAIServiceProvider
class ChatHistory(SqlHistoryProvider[ChatMessageRow]): # a model with session_id, role,
model = ChatMessageRow # content and order_number columns
class Assistant(AiService):
service_provider = OpenAIServiceProvider() # or OllamaServiceProvider()
history_provider = ChatHistory()
@system_prompt("You are a helpful translator.")
@user_prompt("Translate '<:text>' to <:language>.")
async def translate(self, text: str, language: str = "German") -> ChatResponse: ...
@history
@system_prompt("You are a friendly assistant.")
@user_prompt("<:message>")
async def chat(self, session_id: Optional[str], message: str) -> AsyncIterator[ChatResponse]: ...
class Config(BaseConfig):
...
ASSISTANT: AiServiceConfig = AiServiceConfig(
BASE_URL="https://api.openai.com/v1", API_KEY="...", MODEL="gpt-4o-mini", HISTORY_LIMIT=10,
)
See the AI interface (experimental) section of the Patera documentation for the full guide.
License
MIT. See LICENSE.
Metadata
Release files for patera-aiinterface 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| patera_aiinterface-0.11.0.tar.gz | 18.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| patera_aiinterface-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.6 kB
Release files / patera_aiinterface-0.11.0.tar.gz
| Download URL | patera_aiinterface-0.11.0.tar.gz |
|---|---|
| Size | 18.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a493460d1171cb47abec59c0bb1985db2701bda129f6025cf2f6bca69c981f0f
|
|
BLAKE2b-256 checksum How to use checksums |
5c440865d13094cd4adc1b464cd505bc3a4dc2469c0559cc7460a0e026d61912
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / patera_aiinterface-0.11.0-py3-none-any.whl
| Download URL | patera_aiinterface-0.11.0-py3-none-any.whl |
|---|---|
| Size | 26.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2942d8f9872a68e0b52aeebc8f4a01c656a43f9b7125d133a2fcfb9f3a6b0281
|
|
BLAKE2b-256 checksum How to use checksums |
eb32fb7b15e54b597f651874182328571d963b0e3d203c360ee6969feca58fe0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|