🚰 Pipe Function: Create Custom "Agents/Models"
Welcome to this guide on creating Pipes in MANTA! Think of Pipes as a way to adding a new model to MANTA. In this document, we'll break down what a Pipe is, how it works, and how you can create your own to add custom logic and processing to your MANTA models. We'll use clear metaphors and go through every detail to ensure you have a comprehensive understanding.
Introduction to Pipes
Imagine MANTA as a plumbing system where data flows through pipes and valves. In this analogy:
- Pipes are like plugins that let you introduce new pathways for data to flow, allowing you to inject custom logic and processing.
- Valves are the configurable parts of your pipe that control how data flows through it.
By creating a Pipe, you're essentially crafting a custom model with the specific behavior you want, all within the MANTA framework.
Understanding the Pipe Structure
Let's start with a basic, barebones version of a Pipe to understand its structure:
from pydantic import BaseModel, Field
class Pipe:
class Valves(BaseModel):
MODEL_ID: str = Field(default="")
def __init__(self):
self.valves = self.Valves()
def pipe(self, body: dict):
# Logic goes here
print(self.valves, body) # This will print the configuration options and the input body
return "Hello, World!"
The Pipe Class
- Definition: The
Pipeclass is where you define your custom logic. - Purpose: Acts as the blueprint for your plugin, determining how it behaves within MANTA.
Valves: Configuring Your Pipe
- Definition:
Valvesis a nested class withinPipe, inheriting fromBaseModel. - Purpose: It contains the configuration options (parameters) that persist across the use of your Pipe.
- Example: In the above code,
MODEL_IDis a configuration option with a default empty string.
Metaphor: Think of Valves as the knobs on a real-world pipe system that control the flow of water. In your Pipe, Valves allow users to adjust settings that influence how the data flows and is processed.