Skip to main content

A lightweight AI engineering framework for building natural language interfaces that are reliable, scalable, and easy to trust.

Project description

Marvin

The AI engineering framework

Marvin is a lightweight AI engineering framework for building natural language interfaces that are reliable, scalable, and easy to trust.

Sometimes the most challenging part of working with generative AI is remembering that it's not magic; it's software. It's new, it's nondeterministic, and it's incredibly powerful - but still software.

Marvin's goal is to bring the best practices for building dependable, observable software to generative AI. As the team behind Prefect, which does something very similar for data engineers, we've poured years of open-source developer tool experience and lessons into Marvin's design.

Documentation

Marvin's docs are available at askmarvin.ai, including concepts, tutorials, and an API reference.

pip install marvin

Getting started? Head over to our setup guide.

Community

To ask questions, share ideas, or just chat with like-minded developers, join us on Discord or Twitter!

Core AI Components

Marvin's high-level abstractions are familiar Python interfaces that make it easy to leverage AI in your application. These interfaces aim to be simple and self-documenting, adding a touch of AI magic to everyday objects.

🧩 AI Models for structuring text into type-safe schemas

🏷️ AI Classifiers for bulletproof classification and routing

🪄 AI Functions for complex business logic and transformations

🤝 AI Applications for interactive use and persistent state


🧩 AI Models

Marvin's most basic component is the AI Model, a drop-in replacement for Pydantic's BaseModel. AI Models can be instantiated from any string, making them ideal for structuring data, entity extraction, and synthetic data generation.

You can learn more about AI models here.

from marvin import ai_model
from pydantic import BaseModel, Field


@ai_model
class Location(BaseModel):
    city: str
    state: str = Field(..., description="The two-letter state abbreviation")


Location("The Big Apple")
# Location(city='New York', state='NY')

🏷️ AI Classifiers

AI Classifiers let you build multi-label classifiers with no code and no training data. Given user input, each classifier uses a clever logit bias trick to force an LLM to deductively choose the best option. It's bulletproof, cost-effective, and lets you build classifiers as quickly as you can write your classes.

You can learn more about AI Classifiers here.

from marvin import ai_classifier
from enum import Enum


@ai_classifier
class AppRoute(Enum):
    """Represents distinct routes command bar for a different application"""

    USER_PROFILE = "/user-profile"
    SEARCH = "/search"
    NOTIFICATIONS = "/notifications"
    SETTINGS = "/settings"
    HELP = "/help"
    CHAT = "/chat"
    DOCS = "/docs"
    PROJECTS = "/projects"
    WORKSPACES = "/workspaces"


AppRoute("update my name")
# AppRoute.USER_PROFILE

🪄 AI Functions

AI Functions look like regular functions, but have no source code. Instead, an AI uses their description and inputs to generate their outputs, making them ideal for NLP applications like sentiment analysis.

You can learn more about AI Functions here.

from marvin import ai_fn


@ai_fn
def sentiment(text: str) -> float:
    """
    Given `text`, returns a number between 1 (positive) and -1 (negative)
    indicating its sentiment score.
    """


sentiment("I love working with Marvin!") # 0.8
sentiment("These examples could use some work...") # -0.2

🤝 AI Applications

AI Applications permit interactive use cases and are designed to be invoked multiple times. They maintain three forms of state: the application's own state, the AI's plan, and a history of interactions. AI Applications can be used to implement many "classic" LLM use cases, such as chatbots, tool-using agents, developer assistants, and more. In addition, thanks to their persistent state and planning, they can implement applications that don't have a traditional chat UX, such as a ToDo app. Here's an example:

from datetime import datetime
from pydantic import BaseModel, Field
from marvin import AIApplication


# create models to represent the state of our ToDo app
class ToDo(BaseModel):
    title: str
    description: str = None
    due_date: datetime = None
    done: bool = False


class ToDoState(BaseModel):
    todos: list[ToDo] = []


# create the app with an initial state and description
todo_app = AIApplication(
    state=ToDoState(),
    description=(
        "A simple todo app. Users will provide instructions for creating and updating"
        " their todo lists."
    ),
)

# invoke the application by adding a todo
response = todo_app("I need to go to the store tomorrow at 5pm")


print(f"Response: {response.content}\n")
# Response: Got it! I've added a new task to your to-do list. You need to go to the store tomorrow at 5pm.


print(f"App state: {todo_app.state.json(indent=2)}")
# App state: {
#   "todos": [
#     {
#       "title": "Go to the store",
#       "description": "Buy groceries",
#       "due_date": "2023-07-12T17:00:00+00:00",
#       "done": false
#     }
#   ]
# }

Marvin is great for...

Scalable APIs, data pipelines, and agents:

🏷️ Build bulletproof and lightning-fast classifiers

🧩 Extract structured & type-safe data from unstructured text

🧪 Generate synthetic data for your applications

🫡 Solve complex deductive and inferential tasks at scale

🔎 Scrape web data without custom scrapers

AI powered apps with access to tools, data, and the web:

😍 Customize ChatGPT with system prompts and tools

🎓 Extract relevant insights from your data

🧑‍💻 Add a junior developer to your team

🗣️ Quickly add NLP to your app

Advanced applications:

📱 AI applications with persistent state

🕵️ Autonomous agents with high-level planning

💬 Text-to-application: generate stateful applications by describing them

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

marvin-1.5.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

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

marvin-1.5.0-py3-none-any.whl (97.3 kB view details)

Uploaded Python 3

File details

Details for the file marvin-1.5.0.tar.gz.

File metadata

  • Download URL: marvin-1.5.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for marvin-1.5.0.tar.gz
Algorithm Hash digest
SHA256 4fd266406727ec8d6cb0516cd5df40941e12a640d100664293c8c8a1776bc73c
MD5 ec6e6fcf77858916b3ade1fdd5b59abc
BLAKE2b-256 55c11f6e6e4619a52a6aed920d7c90a5f0d5096c742ec1859c081d29c7b33065

See more details on using hashes here.

File details

Details for the file marvin-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: marvin-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 97.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for marvin-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff5cf0e2bec44e0065ff5501b1671ca0d1eafb9534361ef2108d7d1c1ebe4b13
MD5 92f0316a102358cb8afb24f8bae0a412
BLAKE2b-256 7ba5e669a838eb799c7ab2c6fc7284b3a01929b3ebc13816f1f421d81103d4e4

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