Skip to main content

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

Project description

PyPI version Docs Twitter Follow

Marvin

The AI engineering toolkit

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

Each of Marvin's tools is simple and self-documenting, using AI to solve common but complex challenges like entity extraction, classification, and generating synthetic data. Each tool is independent and incrementally adoptable, so you can use them on their own or in combination with any other library. Marvin is also multi-modal, supporting both image and audio generation as well using images as inputs for extraction and classification.

Marvin is for developers who care more about using AI than building AI, and we are focused on creating an exceptional developer experience. Marvin users should feel empowered to bring tightly-scoped "AI magic" into any traditional software project with just a few extra lines of code.

Marvin aims to merge the best practices for building dependable, observable software with the best practices for building with generative AI into a single, easy-to-use library. It's a serious tool, but we hope you have fun with it.

Marvin is open-source, free to use, and made with 💙 by the team at Prefect.

Installation

Install the latest version with pip:

pip install marvin -U

To verify your installation, run marvin version in your terminal.

Tools

Marvin consists of a variety of useful tools, all designed to be used independently. Each one represents a common LLM use case, and is designed to package that power into a simple, self-documenting interface.

General

🦾 Write custom AI-powered functions without source code

Text

🏷️ Classify text into categories

🔍 Extract structured entities from text

🪄 Transform text into structured data

Generate synthetic data from a schema

Images

🖼️ Create images from text or functions

📝 Describe images with natural language

🏷️ Classify images into categories

🔍 Extract structured entities from images

🪄 Transform images into structured data

Audio

🎙️ Generate speech from text or functions

Interaction

🤖 Chat with assistants and use custom tools

🧭 Build applications that manage persistent state

Quickstart

Here's a whirlwind tour of a few of Marvin's main features. For more information, check the docs!

🏷️ Classify text

Marvin can classify text using a set of labels:

import marvin

marvin.classify(
    "Marvin is so easy to use!",
    labels=["positive", "negative"],
)

#  "positive"

Learn more about classification here.

🔍 Extract structured entities

Marvin can extract structured entities from text:

from pydantic import BaseModel

class Location(BaseModel):
    city: str
    state: str

marvin.extract("I moved from NY to CHI", target=Location)

# [
#     Location(city="New York", state="New York"),
#     Location(city="Chcago", state="Illinois")
# ]

Almost all Marvin functions can be given instructions for more control. Here we extract only monetary values:

marvin.extract(
    "I paid $10 for 3 tacos and got a dollar and 25 cents back.",
    target=float,
    instructions="Only extract money"
)

#  [10.0, 1.25]

Learn more about entity extraction here.

✨ Generate data

Marvin can generate synthetic data for you, following instructions and an optional schema:

from pydantic import BaseModel

class Location(BaseModel):
    city: str
    state: str

marvin.generate(
    n=4,
    target=Location,
    instructions="cities in the United States named after presidents"
)

# [
#     Location(city='Washington', state='District of Columbia'),
#     Location(city='Jackson', state='Mississippi'),
#     Location(city='Cleveland', state='Ohio'),
#     Location(city='Lincoln', state='Nebraska'),
# ]

Learn more about data generation here.

🪄 Standardize text by casting to types

Marvin can cast arbitrary text to any Python type:

marvin.cast("one two three", list[int])

#  [1, 2, 3]

This is useful for standardizing text inputs or matching natural language to a schema:

from pydantic import BaseModel

class Location(BaseModel):
    city: str
    state: str

marvin.cast("The Big Apple", Location)

# Location(city="New York", state="New York")

For a class-based approach, Marvin's @model decorator can be applied to any Pydantic model to let it be instantiated from text:

@marvin.model
class Location(BaseModel):
    city: str
    state: str

Location("The Big Apple")

# Location(city="New York", state="New York")

Learn more about casting to types here.

🦾 Build AI-powered functions

Marvin functions let you combine any inputs, instructions, and output types to create custom AI-powered behaviors... without source code. These functions can can go well beyond the capabilities of extract or classify, and are ideal for complex natural language processing or mapping combinations of inputs to outputs.

@marvin.fn
def sentiment(text: str) -> float:
    """
    Returns a sentiment score for `text`
    between -1 (negative) and 1 (positive).
    """

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

Marvin functions look exactly like regular Python functions, except that you don't have to write any source code. When these functions are called, an AI interprets their description and inputs and generates the output.

Note that Marvin does NOT work by generating or executing source code, which would be unsafe for most use cases. Instead, it uses the LLM itself as a "runtime" to predict function outputs. That's actually the source of its power: Marvin functions can handle complex use cases that would be difficult or impossible to express as code.

You can learn more about functions here.

🖼️ Generate images from text

Marvin can paint images from text:

marvin.paint("a simple cup of coffee, still warm")

Learn more about image generation here.

🔍 Classify images (beta)

In addition to text, Marvin has beta support for captioning, classifying, transforming, and extracting entities from images using the GPT-4 vision model:

marvin.beta.classify(
    marvin.Image("docs/images/coffee.png"),
    labels=["drink", "food"],
)

# "drink"

Get in touch!

💡 Feature idea? share it in the #development channel in our Discord.

🐛 Found a bug? feel free to open an issue.

👷 Feedback? Marvin is under active development, and we'd love to hear it.

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-2.1b1.tar.gz (22.6 MB view details)

Uploaded Source

Built Distribution

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

marvin-2.1b1-py3-none-any.whl (88.4 kB view details)

Uploaded Python 3

File details

Details for the file marvin-2.1b1.tar.gz.

File metadata

  • Download URL: marvin-2.1b1.tar.gz
  • Upload date:
  • Size: 22.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for marvin-2.1b1.tar.gz
Algorithm Hash digest
SHA256 879c47bed27e5d5dfc3239e41e6de7ed87b69b090d580e383cd0a6cae6153f24
MD5 6bae858320aaa57a5912c381f95e6066
BLAKE2b-256 59964d9ab199b366df3a35288dee58e1f5e8dcd29c3da8884bd5191cc73c6901

See more details on using hashes here.

File details

Details for the file marvin-2.1b1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for marvin-2.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 3996a5f12242dbd8ca4f1efb0a21d8676e0a55c14901b937a979db82fb012b78
MD5 ac16b1a4237dad8c21f255b9463ece4f
BLAKE2b-256 28db74d7cce3587d5be0024321fd0c5748f638fe17468085aa00ee20f4f19eb0

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