From 4f901a2bbe0657731fb3a5182e4efa91530b6969 Mon Sep 17 00:00:00 2001 From: Farouk Adeleke Date: Sat, 25 Oct 2025 02:36:59 -0400 Subject: [PATCH] (no commit message) --- agent.json | 6 +++--- auto_classes.json | 4 ++-- main.py | 31 +++++++++++++++++++++++++++++++ setup.py | 23 ----------------------- 4 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 main.py delete mode 100644 setup.py diff --git a/agent.json b/agent.json index 28abe86..f452049 100644 --- a/agent.json +++ b/agent.json @@ -4,11 +4,11 @@ "train": [], "demos": [], "signature": { - "instructions": "Given the fields `image`, produce the fields `total_cost`.", + "instructions": "Given the fields `image_url`, produce the fields `total_cost`.", "fields": [ { - "prefix": "Image:", - "description": "${image}" + "prefix": "Image Url:", + "description": "${image_url}" }, { "prefix": "Total Cost:", diff --git a/auto_classes.json b/auto_classes.json index 8e16488..7c1e517 100644 --- a/auto_classes.json +++ b/auto_classes.json @@ -1,4 +1,4 @@ { - "AutoConfig": "setup.ReceiptClassifierConfig", - "AutoAgent": "setup.ReceiptClassifier" + "AutoConfig": "main.ReceiptClassifierConfig", + "AutoAgent": "main.ReceiptClassifier" } \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..277d317 --- /dev/null +++ b/main.py @@ -0,0 +1,31 @@ +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 + max_tokens: int = 500 + +class ReceiptClassifier(PrecompiledAgent): # Extends dspy.module() + config: ReceiptClassifierConfig + + def __init__(self, config: ReceiptClassifierConfig, **kwargs): + super().__init__(config, **kwargs) + + self.extract = dspy.Predict("image_url -> total_cost") + lm = dspy.LM(config.lm, max_tokens=config.max_tokens) + self.extract.set_lm(lm) + + def forward(self, image_url: str) -> str: + receipt_image = dspy.Image.from_url(image_url) + return self.extract(receipt_image) + +agent = ReceiptClassifier(ReceiptClassifierConfig()) + +def main(): + agent.push_to_hub("farouk1/receipt-classifier", with_code=True) + +if __name__ == "__main__": + main() + diff --git a/setup.py b/setup.py deleted file mode 100644 index 4d17d67..0000000 --- a/setup.py +++ /dev/null @@ -1,23 +0,0 @@ -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 - max_tokens: int = 500 - -class ReceiptClassifier(PrecompiledAgent): # Extends dspy.module() - config: ReceiptClassifierConfig - - def __init__(self, config: ReceiptClassifierConfig, **kwargs): - super().__init__(config, **kwargs) - - self.extract = dspy.Predict("image -> total_cost") - lm = dspy.LM(config.lm, max_tokens=config.max_tokens) - self.extract.set_lm(lm) - - def forward(self, image_path: str) -> str: - receipt_image = dspy.Image.from_file(image_path) - return self.extract(receipt_image) - -agent = ReceiptClassifier(ReceiptClassifierConfig()) -agent.push_to_hub("farouk1/receipt-classifier", with_code=True)