From 655ded986e0fd6f198e1cdfb7dd164952ab29b9b Mon Sep 17 00:00:00 2001 From: Farouk Adeleke Date: Sat, 25 Oct 2025 03:28:44 -0400 Subject: [PATCH] (no commit message) --- README.md | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 18 ++------- 2 files changed, 116 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e69de29..79cd4f6 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,112 @@ +# 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 + +1. **Install dependencies:** + ```bash + uv add modaic + # or with pip: + pip install modaic + ``` + +2. **Set up environment variables:** + Create a `.env` file 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 + +```python +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 + +1. **Loads a precompiled agent** - The `farouk1/receipt-classifier` agent is downloaded from the Modaic Hub +2. **Configures the agent** - Sets max_tokens to 500 for response length control +3. **Processes an image** - Analyzes the receipt image from the provided URL +4. **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 +1. Sign up at [Modaic](https://modaic.dev) +2. Navigate to your account settings +3. Generate an API token + +### OpenAI API Key +1. Sign up at [OpenAI](https://platform.openai.com) +2. Go to API keys section +3. 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 + +```bash +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](https://hub.modaic.dev) +- Learn about creating your own agents with the Modaic SDK +- Check out the [Modaic documentation](https://docs.modaic.dev) for advanced features + +## Support + +For questions or issues: +- Visit the [Modaic documentation](https://docs.modaic.dev) +- Check the [GitHub repository](https://github.com/modaic/modaic) +- Join the community discussions \ No newline at end of file diff --git a/main.py b/main.py index 0476d45..20e5caa 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,13 @@ from modaic import PrecompiledAgent, PrecompiledConfig import dspy - class ReceiptClassifierConfig( PrecompiledConfig -): # configurable for each agent instance - lm: str = "openai/gpt-4o-mini" # set OPENAI_API_KEY +): # Configurable for each agent instance + lm: str = "openai/gpt-4o-mini" # Set OPENAI_API_KEY max_tokens: int = 500 - -class ReceiptClassifier(PrecompiledAgent): # extends dspy.module() +class ReceiptClassifier(PrecompiledAgent): # Extends dspy.module() config: ReceiptClassifierConfig def __init__(self, config: ReceiptClassifierConfig, **kwargs): @@ -23,13 +21,5 @@ class ReceiptClassifier(PrecompiledAgent): # extends dspy.module() receipt_image = dspy.Image(url=image_url) return self.extract(image=receipt_image) - agent = ReceiptClassifier(ReceiptClassifierConfig()) - - -def main(): - agent.push_to_hub("farouk1/receipt-classifier", with_code=True) - - -if __name__ == "__main__": - main() +agent.push_to_hub("farouk1/receipt-classifier", with_code=True) # Set MODAIC_TOKEN