Package: marvin
MarvinThe AI engineering toolkitMarvin 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 aboutusingAI thanbuildingAI, 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 atPrefect.InstallationInstall the latest version withpip:pipinstallmarvin-UTo verify your installation, runmarvin versionin your terminal.ToolsMarvin consists of a variety of useful tools, all designed to be used independently. Each one represents a common LLM use case, and packages that power into a simple, self-documenting interface.General🦾Write custom AI-powered functionswithout source codeText🏷️Classify textinto categories🔍Extract structured entitiesfrom text🪄Transform textinto structured data✨Generate synthetic datafrom a schemaImages🖼️Create imagesfrom text or functions📝Describe imageswith natural language🏷️Classify imagesinto categories🔍Extract structured entitiesfrom images🪄Transform imagesinto structured dataAudio🎙️Generate speechfrom text or functionsInteraction🤖Chat with assistantsand use custom tools🧭Build applicationsthat manage persistent stateQuickstartHere's a whirlwind tour of a few of Marvin's main features. For more information,check the docs!🏷️ Classify textMarvin canclassifytext using a set of labels:importmarvinmarvin.classify("Marvin is so easy to use!",labels=["positive","negative"],)#  "positive"Learn more about classificationhere.🔍 Extract structured entitiesMarvin canextractstructured entities from text:importpydanticclassLocation(pydantic.BaseModel):city:strstate:strmarvin.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 giveninstructionsfor 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 extractionhere.✨ Generate dataMarvin cangeneratesynthetic data for you, following instructions and an optional schema:classLocation(pydantic.BaseModel):city:strstate:strmarvin.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 generationhere.🪄 Standardize text by casting to typesMarvin cancastarbitrary 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:classLocation(pydantic.BaseModel):city:strstate:strmarvin.cast("The Big Apple",Location)# Location(city="New York", state="New York")For a class-based approach, Marvin's@modeldecorator can be applied to any Pydantic model to let it be instantiated from text:@marvin.modelclassLocation(pydantic.BaseModel):city:strstate:strLocation("The Big Apple")# Location(city="New York", state="New York")Learn more about casting to typeshere.🦾 Build AI-powered functionsMarvin 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 ofextractorclassify, and are ideal for complex natural language processing or mapping combinations of inputs to outputs.@marvin.fndefsentiment(text:str)->float:"""Returns a sentiment score for `text`between -1 (negative) and 1 (positive)."""sentiment("I love working with Marvin!")# 0.8sentiment("These examples could use some work...")# -0.2Marvin 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 functionshere.🖼️ Generate images from textMarvin canpaintimages from text:marvin.paint("a simple cup of coffee, still warm")Learn more about image generationhere.🔍 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#developmentchannel inour Discord.🐛Found a bug?feel free toopen an issue.👷Feedback?Marvin is under active development, and we'd love tohear it.