Basic Extraction API¶
With Marvin, you can easily build a production-grade application or data pipeline to extract structured data from unstructured text. In this example, we'll show how to
- Write an AI-powered Function.
- Build a production-ready API.
Writing an AI-powered Function.¶
Marvin translates your Python code into English, passes that to an Large Language Model, and parses its response. It uses AI to evaluate your function, no code required.
Let's build a function that extracts a person's first_name, last_name, and age from a paragraph of text. This is typically a pretty daunting task for a machine learning savant, much less your average engineer. Marvin lets you accomplish this by write code the way you normally would, no PhD required.
We'll simply write a Python function, tell it that we expect a
text input and that it'll
dict, or dictionary. With Marvin, we'll use
ai_fn and decorate his function.
When we do, this function will use AI to get its answer.
Build a production-ready API.¶
In the following example, we will demonstrate how to deploy the AI function we just created as an API using FastAPI. FastAPI is a powerful tool that allows us to easily turn our AI function into a fully-fledged API. This API can then be used by anyone to send a POST request to our
/extract_person/ endpoint and get the structured data they need. Let's see how this can be done.
Now that we have our AI function, let's deploy it as an API using FastAPI. FastAPI is a modern, fast (high-performance), web framework for building APIs.
With just a few lines of code, we've turned our AI function into a fully-fledged API. Now, anyone can send a POST request to our
/extract_person/ endpoint and get the structured data they need.
/extract_person/endpoint with the provided text and print the response.