(no commit message)
This commit is contained in:
12
main.py
12
main.py
@@ -4,24 +4,24 @@ 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):
|
||||
super().__init__(config, **kwargs)
|
||||
|
||||
self.extract = dspy.Predict("image_url -> total_cost")
|
||||
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_url: str) -> str:
|
||||
receipt_image = dspy.Image.from_url(url=image_url)
|
||||
return self.extract(receipt_image)
|
||||
receipt_image = dspy.Image(url=image_url)
|
||||
return self.extract(image=receipt_image)
|
||||
|
||||
|
||||
agent = ReceiptClassifier(ReceiptClassifierConfig())
|
||||
|
||||
Reference in New Issue
Block a user