diff --git a/code/backend/batch/utilities/parser/output_parser_tool.py b/code/backend/batch/utilities/parser/output_parser_tool.py index ace176a83..481903586 100644 --- a/code/backend/batch/utilities/parser/output_parser_tool.py +++ b/code/backend/batch/utilities/parser/output_parser_tool.py @@ -22,10 +22,13 @@ def _get_source_docs_from_answer(self, answer): def _make_doc_references_sequential(self, answer): doc_matches = list(re.finditer(r"\[doc\d+\]", answer)) + updated_answer = answer + offset = 0 for i, match in enumerate(doc_matches): - start, end = match.span() - answer = answer[:start] + f"[doc{i + 1}]" + answer[end:] - return answer + start, end = match.start() + offset, match.end() + offset + updated_answer = updated_answer[:start] + f"[doc{i + 1}]" + updated_answer[end:] + offset += len(f"[doc{i + 1}]") - (end - start) + return updated_answer def parse( self,