mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-15 11:02:36 +02:00
fix: invoice ocr assistant
Currently, the invoice_ocr_assistant example cannot run, it will complain about the index out of range exceptions. The problem comes from adding actions in _act() but do not update the state and max_react_loop. The solution is copied from tutorial_assistants.py.
This commit is contained in:
parent
38cea1daf2
commit
dcea8b71c8
1 changed files with 5 additions and 7 deletions
|
|
@ -80,19 +80,17 @@ class InvoiceOCRAssistant(Role):
|
|||
raise Exception("Invoice file not uploaded")
|
||||
|
||||
resp = await todo.run(file_path)
|
||||
actions = list(self.actions)
|
||||
if len(resp) == 1:
|
||||
# Single file support for questioning based on OCR recognition results
|
||||
self.set_actions([GenerateTable, ReplyQuestion])
|
||||
actions.extend([GenerateTable, ReplyQuestion])
|
||||
self.orc_data = resp[0]
|
||||
else:
|
||||
self.set_actions([GenerateTable])
|
||||
|
||||
self.set_todo(None)
|
||||
actions.append(GenerateTable)
|
||||
self.set_actions(actions)
|
||||
self.rc.max_react_loop = len(self.actions)
|
||||
content = INVOICE_OCR_SUCCESS
|
||||
resp = OCRResults(ocr_result=json.dumps(resp))
|
||||
msg = Message(content=content, instruct_content=resp)
|
||||
self.rc.memory.add(msg)
|
||||
return await super().react()
|
||||
elif isinstance(todo, GenerateTable):
|
||||
ocr_results: OCRResults = msg.instruct_content
|
||||
resp = await todo.run(json.loads(ocr_results.ocr_result), self.filename)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue