f69def1fef16e5f2dba4cc71b61aabd2d5f95341
Modaic AutoAgent Quickstart
A simple quickstart project demonstrating how to use Modaic's AutoAgent for receipt classification and cost extraction from images.
Overview
This project shows how to:
- Use a precompiled agent from the Modaic Hub
- Extract cost information from receipt images
- Configure agent parameters like max tokens
Prerequisites
- Python 3.11 or higher
- Modaic account and API token
- OpenAI API key
Installation
-
Install dependencies:
uv add modaic # or with pip: pip install modaic -
Set up environment variables: Create a
.envfile in the project root with your API keys:MODAIC_TOKEN=your_modaic_token_here OPENAI_API_KEY=your_openai_api_key_here
Usage
Basic Example
from modaic import AutoAgent
# Load a precompiled receipt classifier from the Modaic Hub
receipt_classifier = AutoAgent.from_precompiled(
"farouk1/receipt-classifier",
config_options={"max_tokens": 500}
)
# Analyze a receipt image and extract the total cost
results = receipt_classifier(
"https://ocr.space/Content/Images/receipt-ocr-original.webp"
)
print(results.total_cost) # Output: 98.21
What This Does
- Loads a precompiled agent - The
farouk1/receipt-classifieragent is downloaded from the Modaic Hub - Configures the agent - Sets max_tokens to 500 for response length control
- Processes an image - Analyzes the receipt image from the provided URL
- Extracts cost data - Returns the total cost found on the receipt
Key Features
- Precompiled Agents: Use ready-made agents from the Modaic Hub
- Image Processing: Direct support for image URLs and analysis
- Configurable Parameters: Customize agent behavior with config options
- Simple API: Just a few lines of code to get started
Getting API Keys
Modaic Token
- Sign up at Modaic
- Navigate to your account settings
- Generate an API token
OpenAI API Key
- Sign up at OpenAI
- Go to API keys section
- Create a new API key
Project Structure
quickstart/
.env # API keys (not committed to git)
.gitignore # Git ignore patterns
main.py # Agent implementation and hub upload
pyproject.toml # Project dependencies and metadata
README.md # This file
uv.lock # Dependency lock file
Running the Example
python main.py
This will run the quickstart example and display the extracted total cost from the receipt image.
Next Steps
- Explore more precompiled agents on the Modaic Hub
- Learn about creating your own agents with the Modaic SDK
- Check out the Modaic documentation for advanced features
Support
For questions or issues:
- Visit the Modaic documentation
- Check the GitHub repository
- Join the community discussions
Languages
Python
100%