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.1
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.1.tar.gz | 18.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| patera_aiinterface-0.11.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.8 kB
Release files / patera_aiinterface-0.11.1.tar.gz
| Download URL | patera_aiinterface-0.11.1.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61e6fe653c17e73287137e732582fb87de520eb4f8401ca93227ee69d2b2f12b
|
|
BLAKE2b-256 checksum How to use checksums |
14f4eda755bee2f8d2912ade63f16298cecb8bc79284c8cd45ca7e649c581de5
|
| 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.1-py3-none-any.whl
| Download URL | patera_aiinterface-0.11.1-py3-none-any.whl |
|---|---|
| Size | 26.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7519fa9d7f4b8ae73d7d9dc61be99c8313860d7751f2f19a7a813a4cfe9e381
|
|
BLAKE2b-256 checksum How to use checksums |
c76745ac9df021fcd5fbc2a56811d13d2d4a9a85a54e91bec6d25a9dcd3726a1
|
| 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}
|