From dcea8b71c8c6e360c0dec1fc5761df944971b4f2 Mon Sep 17 00:00:00 2001 From: huang-jl <1046678590@qq.com> Date: Tue, 18 Jun 2024 16:01:53 +0800 Subject: [PATCH] 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. --- metagpt/roles/invoice_ocr_assistant.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/metagpt/roles/invoice_ocr_assistant.py b/metagpt/roles/invoice_ocr_assistant.py index a39a48b97..afcc527a3 100644 --- a/metagpt/roles/invoice_ocr_assistant.py +++ b/metagpt/roles/invoice_ocr_assistant.py @@ -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)