(no commit message)
This commit is contained in:
@@ -4,11 +4,11 @@
|
|||||||
"train": [],
|
"train": [],
|
||||||
"demos": [],
|
"demos": [],
|
||||||
"signature": {
|
"signature": {
|
||||||
"instructions": "Given the fields `image`, produce the fields `total_cost`.",
|
"instructions": "Given the fields `image_url`, produce the fields `total_cost`.",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"prefix": "Image:",
|
"prefix": "Image Url:",
|
||||||
"description": "${image}"
|
"description": "${image_url}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"prefix": "Total Cost:",
|
"prefix": "Total Cost:",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"AutoConfig": "setup.ReceiptClassifierConfig",
|
"AutoConfig": "main.ReceiptClassifierConfig",
|
||||||
"AutoAgent": "setup.ReceiptClassifier"
|
"AutoAgent": "main.ReceiptClassifier"
|
||||||
}
|
}
|
||||||
31
main.py
Normal file
31
main.py
Normal file
@@ -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()
|
||||||
|
|
||||||
23
setup.py
23
setup.py
@@ -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)
|
|
||||||
Reference in New Issue
Block a user