A minimalist Python library for byte-sized AI tasks
Project description
MiniAI
A minimalist Python library for byte-sized AI tasks. No complex chains, no confusing abstractions, just AI that works.
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 difficult 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
# Simple tasks with just one line
text = ai.ask("Write a haiku about Python")
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 goes here...")
translated = ai.translate("Hello world", to="spanish")
answer = ai.ask("Who was Ada Lovelace?")
image_analysis = ai.ask("What's in this image?", images=["Logo.png"])
image_url_analysis = ai.ask("What's in this image?", images=["https://example.com/image.jpg"])
# Configure once, use anywhere
ai.set_api_key("openai", "your-api-key-here") # Or use environment variables
ai.use("anthropic") # Switch providers dynamically
ai.set_model("gpt-4-turbo") # Set model for current provider
# Mock mode for testing without API keys
ai.config.mock(True)
result = ai.ask("This will return a mock response") # No API key needed
Turn Any Function into an AI Function
The most powerful feature is the function decorator:
@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
@ai.function(system_prompt="You are a professional software engineer.")
def write_code(task, language):
"""Write {language} code to {task}. Include comments."""
code = write_code("sort a list", "python")
Installation
pip install miniai
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
- 📦 Lightweight: No heavy dependencies
- 🧩 Extensible: Easy to add new providers and tasks
- 🧪 Test-friendly: Mock mode for development without API keys
API Reference
Core Functions
ai.ask(question, format_instructions=None, images=None, raw_response=False, **kwargs)- Answer a question, optionally with images and format instructionsai.classify(text, categories, raw_response=False, **kwargs)- Classify text into categoriesai.extract(text, entities, raw_response=False, **kwargs)- Extract entities from textai.summarize(text, raw_response=False, **kwargs)- Summarize textai.translate(text, to, raw_response=False, **kwargs)- Translate text to another languageai.embedding(text, raw_response=False, **kwargs)- Get embedding vector for textai.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)
Configuration
ai.set_api_key(provider, key)- Set API key for a providerai.use(provider)- Switch to a different providerai.use('mock')- Use the mock provider for testing
ai.set_model(model, provider=None)- Set model for current or specified providerai.get_active_provider()- Get current providerai.get_available_providers()- List all available providers
Response Format
By default, all functions return the processed response that makes sense for the task (e.g. a string for text generation, a list of entities for entity extraction, etc.).
All functions also support a raw_response parameter that returns a Response object with:
content: The processed responseraw_response: The complete response from the provider
Example:
response = ai.ask("What is the capital of France?", raw_response=True)
print(response.content) # The text answer
print(response.raw_response) # Full provider response
More examples in the examples directory.
Decorator
@ai.function(system_prompt=None)- Turn any function into an AI function
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file miniai-0.1.0.tar.gz.
File metadata
- Download URL: miniai-0.1.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96c2a417a02a99c0264792ed6dbbc6bcdce75f71d32c094546533fc031be0758
|
|
| MD5 |
1d5f702f0902e055ae50f12cad719ad6
|
|
| BLAKE2b-256 |
6d5034ea015c18b0180bbbdc035ed5038e3ffac16538c9a6c5785f3799e29f62
|
File details
Details for the file miniai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: miniai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f79aa9375a5c8be91f7b190a75500eb8590af8052566f3745f29b1bc43d49c87
|
|
| MD5 |
9a57963320db4b2cda9a433484806281
|
|
| BLAKE2b-256 |
86b6356db18858cd4d5e4fe8e926cff4376e359992494249109bbae05a2bd4b4
|