Skip to main content

[!IMPORTANT] Work in progress - internal code refactor.

Delusion

✨ The missing conveniences in generative models ✨

📦 Description

A small toolkit for generative models, with practical conveniences built in: such as caching, fast imports, syntactic sugars, opinionated architecture, curated providers, and more.

  • Message classes with type-safe structured output generics, auto validation (chat)
  • Modular: Easily write your implementations or modify existing ones.
  • Minimal: Avoids the complexity and commitment of a full framework.

📦 Usage

Simply add the delusion PyPI package to your project and use it:

[project]
dependencies = ["delusion"]

Chat

from delusion.chat.router.ollamax import Ollama
from pydantic import BaseModel, Field

class Country(BaseModel):
    name: str
    capital: str
    languages: set[str] = Field(
        description="Officially recognized languages"
    )

chat = Ollama().serve()
chat.gemma4("e2b").pull()
chat.send("Tell me about Canada, its capital and spoken languages.")

# Your linter should properly point to the class
canada = chat.generate(schema=Country)
print(canada.model)

assert (canada.model.name == "Canada")
assert (canada.model.capital == "Ottawa")
assert (canada.model.languages == {"English", "French"})

📦 Standards

In an effort to minimize xkcd 927, Delusion only introduces abstractions that provide clear value or represent shared semantics across providers, using provider-native packages whenever available.

For example, the Options class for ollama models shall only apply to itself:

import ollama

local = Ollama(model="gemma4:e2b")
cloud = OpenAI(model="gpt-whatever")

isinstance(local.options, ollama.Options) # True
isinstance(cloud.options, ollama.Options) # False

Although both support .temperature = 0.0, the intended use is:

# Individual settings
if os.getenv("PRODUCTION", None):
    chat = OpenAI(model=...)
    chat.options.temperature = 0.0
else:
    chat = Ollama(model=...)
    chat.options.temperature = 0.0

# Shared interface
chat.send(...)
chat.generate(schema=...)

Same for models: rather than over-abstracting capabilities, quantization, names, variants, and other provider-specific details, some code duplication is natural to keep it minimal and decoupled.

Conversely, Message[T] is abstracted because it represents a common semantic across providers.

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

delusion-0.3.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file delusion-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: delusion-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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 delusion-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bcfe8af76971d2f8f0446801d43aecf068319dc0f9cda8f3841f72766869c6f7
MD5 28917ca6b1b4484bea03a30be3c840c4
BLAKE2b-256 b9c7250df0d7eb4e57e84c013133405f69c01bf46e30dab836c75e0378d5c12e

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 Sentry Error logging StatusPage Status page