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:
huang-jl 2024-06-18 16:01:53 +08:00
parent 38cea1daf2
commit dcea8b71c8

View file

@ -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)