Git Product home page Git Product logo

marvin's Introduction

Marvin

PyPI version Twitter Follow Docs

An AI engineering framework

... made with 💙 by the team at Prefect.

pip install marvin

Getting started? Head over to our setup guide.


⚠️ Marvin is a work in progress, and we'd love your feedback! ⚠️

Looking for info on Marvin 1.x?


Offerings

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 Functions for complex business logic and transformations

🧩 AI Models for structuring text into type-safe schemas

🤖 (beta) Assistants for building stateful natural language interfaces


🪄 AI Functions

AI Functions look like regular functions, but have no source code. Instead, an AI interprets their description and inputs to generate their outputs, making them ideal for general 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

🎬 You can define your own types for AI Functions to return, using things like:

from typing_extensions import TypedDict

class DetailedSentiment(TypedDict):
    """A detailed sentiment analysis result.

    - `sentiment_score` is a number between 1 (positive) and -1 (negative)
    - `summary_in_a_word` is a one-word summary of the general sentiment, 
        use any apt word that captures the nuance of the sentiment
    """
    sentiment_score: float
    summary_in_a_word: str

@ai_fn
def detailed_sentiment(text: str) -> DetailedSentiment:
    """What do you think the sentiment of `text` is?
    
    Use your theory of mind to put yourself in the shoes of its author.
    """

detailed_sentiment("I'ma Mario, and I'ma gonna wiiiiin!")
# {'sentiment_score': 0.8, 'summary_in_a_word': 'energetic'}

🧩 AI Models

AI models are based on Pydantic's BaseModel, but with a twist: they are instantiated with plain text, and will use an LLM to infer their values.

You can learn more about AI models here.

from marvin import ai_model
from pydantic import BaseModel, Field


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


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

Assistants (Beta)

Based on OpenAI's Assistant API, Marvin's Assistants are the easiest way to build a stateful natural language interface equipped with familiar tools (i.e. python functions).

from marvin.beta.assistants import Assistant, Thread

def multiply(x: float, y: float) -> float:
    return x * y

def divide(x: float, y: float) -> float:
    return x / y


with Assistant(tools=[multiply, divide]) as assistant:
    thread = Thread()
    while True:
        message = input("You: ")
        if message.lower() in ["exit", ":q", "bye"]:
            break
        thread.add(message)
        thread.run(assistant)
        print("\n\n".join(m.content[0].text.value for m in thread.get_messages()))
        # what is the speed of light (m/s) times the number of days in a year?

        # what is that number divided by 42?

Read more about our SDK and/or the OpenAI docs.

Reach out!

💡 Have an idea for a feature? toss it in #development in our Discord

🐛 found a bug? feel free to open an issue

marvin's People

Contributors

jlowin avatar zzstoatzz avatar aaazzam avatar jamiezieziula avatar discdiver avatar ksallee avatar dependabot[bot] avatar wybryan avatar roboojack avatar thanseefpp avatar abrookins avatar geminixiang avatar cicdw avatar lucemia avatar yasyf avatar phodaie avatar chrisguidry avatar anna-geller avatar brianjking avatar csreuter avatar donavan avatar eltociear avatar lmmx avatar oaustegard avatar richardscottoz avatar maisim avatar vickyliin avatar polacekpavel avatar sarahmk125 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.