A package to make working with AI simple.
Project description
MAIAI (Multi-Agentic Instructor AI)
This package provides tools to make building workflows with GPT models simple and efficient.
Installation
You can install this package using pip:
pip install MAIAI
Components
This package contains two main components: Agent, Task.
Agent
The Agent class is defined in the MAIAI module. An Agent represents an AI model that can perform tasks. It has the following attributes:
model: The name of the AI model.temperature: The temperature parameter for the AI model, which controls the randomness of the model's output.role: The role or purpose of the AI agent, which can guide its responses.
Task
The Task class represents a task that an Agent can perform. It has the following attributes:
agent: TheAgentthat will perform the task.goal: The goal or prompt for the task.expected_output: The expected format or type of output (optional).retries: The number of attempts to complete the task in case of failure (default is 3).validate: A validation function to check the output's correctness (optional).
Task Methods
-
execute:- Executes the main message of the task, optionally formatting the response as JSON.
- Returns the output of the task execution, in JSON format if
response_typeis "json", else as text. - Includes retries and enhanced response handling.
-
chat:- Processes a chat session by formatting the chat history, appending system and user messages, and sending it to an API for a response.
- Supports retries and handles errors.
-
retry:- Allows for automatic retries when performing a task if an error occurs.
- Attempts the specified number of retries before returning a failure message.
-
read_image:- Processes an image by encoding it to base64 and sends it to the API for processing.
- Can return the extracted content as text or JSON, depending on the
jsonargument.
Moderation Check
The moderation_check function is a standalone function that checks the content of the goal for compliance using the OpenAI Moderation API. If the content is flagged, an exception is raised, preventing the task from executing.
Usage
Here's a basic example of how to use these classes:
from MAIAI import Agent, Task
# Create an agent
agent = Agent(model="gpt-4o-mini", temperature=0.5, role="Translate text from English to French.")
# Create a task with a goal
task = Task(agent=agent, goal="Hello world!", expected_output="French Sentence")
# Execute the task
output = task.execute()
print("Output:", output)
Using Additional Features
-
Chat Functionality:
- Example to utilize the
chatmethod with a session history:
chat_history = [("Hello", "Hi, how can I help you?"), ("What's your name?", "I am MAIAI.")] task = Task(agent=agent, goal="What's the weather today?") output = task.chat(chat_history) print("Chat Output:", output)
- Example to utilize the
-
Retry Mechanism:
- Example to test the retry functionality with a function that may fail:
# Initialize an agent agent = Agent(model="gpt-4o-mini", temperature=0.5, role="Retry Test Agent") # Define a goal for the task goal = "Give me your favorite line." # Create a validation function that checks if "MAIAI" is in the output def contains_maiai(output): return "MAIAI" in output # Create a Task instance with the validation function task = Task(agent=agent, goal=goal, retries=3, validate=contains_maiai) # Execute the task with retry if "MAIAI" is not in the response output = task.execute() print("Retry Test Output:", output)
-
Reading Images:
- Use the
read_imagemethod to process an image file:
image_path = "path/to/image.png" image_task = Task(agent=agent, goal="Extract text from this image.") # Get the response as text or JSON output = image_task.read_image(image_path, json=False) print("Image Output:", output)
- Use the
Summary
With MAIAI, you have a flexible and reliable way to interact with GPT models, providing tools for moderation, retries, and even image processing. The Task and Agent classes allow building robust Multi-Model Agentic Architectures with simple setups, enhancing productivity in AI-driven workflows.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file maiai-3.0.1.tar.gz.
File metadata
- Download URL: maiai-3.0.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84b50e8381fa46e5ffba623fa528fe6b8431279fd5269ae17d704eb7245eb859
|
|
| MD5 |
80b9747cae8b6d5909f4401e58d58a09
|
|
| BLAKE2b-256 |
0bfe74596da813a0b56746578380016e6248559c275277a7e167f88626e1fce7
|
File details
Details for the file MAIAI-3.0.1-py3-none-any.whl.
File metadata
- Download URL: MAIAI-3.0.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f557e6c7b41a9653119464a26f2b793650ea99fa016ed659939959ee0a4cda7d
|
|
| MD5 |
2d40737ee336ee1773e4c93bd761cbdc
|
|
| BLAKE2b-256 |
32f18860c71e15c08b2b359f9c43481d73f4eaff3a2ada211184bbf2f4ec55d8
|