Skip to main content

Centralized AI clients (LLM, embeddings, STT, TTS, RAG) for self-hosted OpenAI-compatible GPU services.

Project description

aitoolkit

Centralized AI clients — LLM, Embeddings, Speech-to-Text, Text-to-Speech, and RAG — targeting self-hosted, OpenAI-compatible services. Reusable across projects via a single git install.

Why

Replaces scattered, provider-specific AI code (cloud-LLM wrappers, local Whisper, ad-hoc LangChain) with one thin, stable, dependency-light package. The core is 100% LangChain-free; LangChain is an opt-in extra used only where LangGraph orchestration needs it.

Design principles

  1. Depend on stable interfaces, hide volatile implementations. The public API is a small set of clients + plain types; provider SDKs stay internal.
  2. Core is dependency-light and LangChain-free. Heavy/optional things (qdrant, redis, langchain) live behind extras and import lazily.
  3. No project specifics in the package. Hosts, model ids, voices, collection names, and keywords are parameters/config — never hardcoded.
  4. OpenAI-compatible first. LLM, embeddings and STT use the openai SDK; only TTS is a small custom httpx client.
  5. Async-first, with sync convenience wrappers where ergonomics demand it.

Install

# core only (LLM, embeddings, STT, TTS)
pip install "aitoolkit @ git+https://github.com/CNIT-Organization/aitoolkit.git@v0.2.0"

# with RAG (Qdrant) + caching + LangChain bridge
pip install "aitoolkit[all] @ git+https://github.com/CNIT-Organization/aitoolkit.git@v0.2.0"

# pick exactly what a service needs
pip install "aitoolkit[rag,cache] @ git+...@v0.2.0"
pip install "aitoolkit[rag,langchain] @ git+...@v0.2.0"

Extras: rag (qdrant-client) · cache (redis) · langchain (langchain-core + langchain-openai) · all.

Configuration

All config is environment-driven (AITOOLKIT_*, see .env.example), but every client also accepts explicit overrides, so no env is strictly required.

Quick start

import asyncio
from aitoolkit import get_llm_client, get_embeddings_client, get_stt_client, get_tts_client

async def main():
    llm = get_llm_client()
    print(await llm.chat("Say hello in one short sentence."))

    async for tok in llm.stream("Count to five."):
        print(tok, end="", flush=True)

    emb = get_embeddings_client()
    vecs = await emb.aembed_documents(["first document", "second document"])
    print("dim:", emb.dimension)

    stt = get_stt_client()
    result = await stt.transcribe("audio.wav", language="en")
    print(result.text)

    tts = get_tts_client()
    audio = await tts.synthesize("Hello world", voice="your-voice-id")
    open("out.wav", "wb").write(audio)

    # multi-speaker: synthesize each turn with its own voice and stitch to one WAV
    dialogue = await tts.synthesize_dialogue([
        {"voice_id": "voice-a", "text": "Welcome to the overview."},
        {"voice_id": "voice-b", "text": "Let's dive in."},
    ])
    open("dialogue.wav", "wb").write(dialogue)

asyncio.run(main())

Structured output

from pydantic import BaseModel
class Flashcard(BaseModel):
    question: str
    answer: str

card = await get_llm_client().chat_structured(Flashcard, "Make a flashcard about the water cycle.")

RAG (aitoolkit[rag])

from aitoolkit.rag import get_rag_agent
agent = get_rag_agent(collection_name="documents")
await agent.add_documents(["chunk 1", "chunk 2"], file_id="doc-42")
answer = await agent.answer_question("What does the document say about safety?")

LangChain bridge (aitoolkit[langchain])

from aitoolkit.integrations.langchain import to_chat_model, LangChainEmbeddings
chat_model = to_chat_model(temperature=0.3)   # a LangChain BaseChatModel for LangGraph
embeddings = LangChainEmbeddings()            # a LangChain Embeddings

Testing

pip install -e ".[all]" --group dev
pytest                       # unit tests (mocked)
AITOOLKIT_RUN_LIVE=1 pytest  # also run live smoke tests against your endpoints

Live tests auto-skip when the configured endpoints are unreachable.

Project details


Download files

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

Source Distribution

ff_aitoolkit-0.2.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

ff_aitoolkit-0.2.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file ff_aitoolkit-0.2.0.tar.gz.

File metadata

  • Download URL: ff_aitoolkit-0.2.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","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 ff_aitoolkit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1f40cd19164b9b914c8e0eb304d7bcc09297ce0198a3a474b6fdfe99b6745dfb
MD5 d5b85762d48ec6bdd4c755fe9ada5702
BLAKE2b-256 32b1122c48296e01d9d35b2dc6abac0b01a2f01f6f8b01d35dbf018eaa2be380

See more details on using hashes here.

File details

Details for the file ff_aitoolkit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ff_aitoolkit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","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 ff_aitoolkit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e0d903105dc43d06ea1ffbb03942795ae2491859cf41043812aff4d820c7557
MD5 31b7bf89af0e661a2c61741fb9fcb819
BLAKE2b-256 8a44fd58c937931b3682618fb1313228cd82deeb4f640568ec4645a407d526a3

See more details on using hashes here.

Supported by

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