Skip to main content

MiniAI

A minimalist Python library for byte-sized AI tasks. No complex chains, no confusing abstractions, just AI that works.

pip install miniai

The Problem

Using AI models for simple tasks comes with too much overhead: Writing boilerplate API calls, managing prompts and message lists, configuring providers and models, learning complex frameworks like LangChain.

These barriers make it annoying to quickly prototype and integrate AI capabilities into your workflow.

The Solution

MiniAI provides a dead-simple interface for common AI tasks.

from miniai import ai

text = ai.ask("Write a haiku about Python")

ai.ask() is a powerful function that can do anything. But here are some helper functions for common tasks:

image_analysis = ai.ask("What's in this image?", images=["image.png", "https://example.com/image.png"])

category = ai.classify("I love this product!", ["positive", "negative", "neutral"])

entities = ai.extract("Apple was founded by Steve Jobs in 1976", ["people", "organizations", "dates"])

summary = ai.summarize("Very long text")

translated = ai.translate("Hello world", to="spanish")

audio = ai.text_to_speech("Hello world")

text = ai.speech_to_text(audio) # Transcription

See more examples in the examples directory.

Intuitive and Flexible

The only terminology you need to know is "provider" and "model". A provider is an AI service/company like OpenAI or Anthropic. A model is a specific AI model like GPT-4o or Claude 3.5.

The defaults will usually get your work done, but if you need more control, it's super intuitive. Need a different provider? A different model? A system prompt? Additional settings? just pass a parameter to ai.ask().

text = ai.ask("Write a haiku about Python", system_prompt="Respond in Spanish") # uses gpt-4o from openai by default

text = ai.ask("Write a haiku about Python", provider="anthropic")

text = ai.ask("Write a haiku about Python", provider="openai", model="gpt-3.5-turbo", temperature=0.5, max_tokens=100)

If you need the raw response from the provider, just pass raw_response=True.

response = ai.ask("Write a haiku about Python", raw_response=True)
print(response.content) # The text answer
print(response.raw_response) # Full provider response

Turn Any Function into an AI Function

The function decorator is a powerful way to turn any function into an AI function.

@ai.function
def generate_poem(topic, style):
    """Generate a poem about {topic} in the style of {style}."""

poem = generate_poem("autumn leaves", "haiku")
print(poem)

# With system prompt and model
@ai.function(system_prompt="You are a professional software engineer.", model="gpt-4o-mini")
def write_code(task, language):
    """Write {language} code to {task}. Include comments."""

code = write_code("sort a list", "python")

Why Choose MiniAI?

  • 🚀 Simple API: Just one import, intuitive methods
  • 🔧 Zero configuration: Works out of the box (with environment variables)
  • 🧠 Smart defaults: Uses appropriate models for each task
  • 🔄 Model agnostic: Works with OpenAI, Anthropic, and more coming soon
  • 📦 Lightweight: No heavy dependencies
  • 🧩 Extensible: Easy to add new providers and tasks
  • 🛠️ Error handling: Clear and helpful error messages

API Reference

API Keys: MiniAI requires API keys for the desired providers. You can set these using environment variables (e.g., OPENAI_API_KEY, ANTHROPIC_API_KEY) or programmatically using ai.set_api_key(provider, key).

Core Function

Function Description
ai.ask(question, system_prompt=None, messages=None, format_instructions=None, images=None, raw_response=False, **kwargs) General-purpose AI request supporting text, images, format instructions, system prompts, and conversation history (messages). Uses default provider/model (OpenAI GPT-4o initially), override via arguments (provider=, model=, **kwargs).

Helper Functions

Function Description
ai.classify(text, categories, raw_response=False, **kwargs) Classify text into categories
ai.extract(text, entities, raw_response=False, **kwargs) Extract entities from text
ai.summarize(text, raw_response=False, **kwargs) Summarize text
ai.translate(text, to, raw_response=False, **kwargs) Translate text to another language
ai.embedding(text, raw_response=False, **kwargs) Get embedding vector for text
ai.text_to_speech(text, raw_response=False, **kwargs) Convert text to speech (OpenAI only)
ai.speech_to_text(audio_data, raw_response=False, **kwargs) Convert speech to text (OpenAI only)

Accessing Raw Provider Output: By default, MiniAI functions return a directly usable result (e.g., a string for ai.ask, a list for ai.extract). To get the complete, unmodified response from the underlying AI provider's API, pass raw_response=True. This returns a Response object containing:

  • content: The processed output (same as when raw_response=False).
  • raw_response: The full, untouched response object from the provider.

Configuration

Function Description
ai.set_api_key(provider, key) Set API key for a provider
ai.use(provider) Switch to a different provider
ai.set_model(model, provider=None) Set model for current or specified provider
ai.get_active_provider() Get current provider
ai.get_available_providers() List all available providers

Note: Use ai.use('mock') to enable the mock provider for testing without API keys.

Decorator

Decorator Description
@ai.function(system_prompt=None, messages=None, format_instructions=None, images=None, raw_response=False, **kwargs) Turn any function into an AI function. The function's docstring is used as the prompt. See examples.

License

MIT

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for step-by-step guidelines.

Release files for miniai 0.1.1

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

Source distribution (sdist)

Source distribution for miniai 0.1.1
File Size Uploaded
miniai-0.1.1.tar.gz 16.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for miniai 0.1.1
File Interpreter ABI Platform
miniai-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size:34.0 kB

Release files / miniai-0.1.1.tar.gz

Download URL miniai-0.1.1.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dae13bd96befce64f6db50900dddb9785e7cf9ad27250366af8d14e024577bf0
BLAKE2b-256 checksum
How to use checksums
8e364413a9ec649a0c58acbb722a93fa73d71f3de2e45913a00f4443c0616925
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Release files / miniai-0.1.1-py3-none-any.whl

Download URL miniai-0.1.1-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44a434bee3cc4869ab34b45f5d5377eb3f6727238664528e31384e66d3edc520
BLAKE2b-256 checksum
How to use checksums
7471869f88f9a2ae7bde314a3cf82067e2e99920b30992f8592824ec540d6af5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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