Skip to main content

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 instructions
  • 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)

Configuration

  • ai.set_api_key(provider, key) - Set API key for a provider
  • ai.use(provider) - Switch to a different provider
    • ai.use('mock') - Use the mock provider for testing
  • 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

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 response
  • raw_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


Download files

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

Source Distribution

miniai-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

miniai-0.1.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

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

Hashes for miniai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 96c2a417a02a99c0264792ed6dbbc6bcdce75f71d32c094546533fc031be0758
MD5 1d5f702f0902e055ae50f12cad719ad6
BLAKE2b-256 6d5034ea015c18b0180bbbdc035ed5038e3ffac16538c9a6c5785f3799e29f62

See more details on using hashes here.

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

Hashes for miniai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f79aa9375a5c8be91f7b190a75500eb8590af8052566f3745f29b1bc43d49c87
MD5 9a57963320db4b2cda9a433484806281
BLAKE2b-256 86b6356db18858cd4d5e4fe8e926cff4376e359992494249109bbae05a2bd4b4

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