From 220cfce476d92b416309c33ee8af36fa619a1112 Mon Sep 17 00:00:00 2001 From: Pavan-Microsoft Date: Fri, 3 Jan 2025 17:20:06 +0530 Subject: [PATCH] fix for in response getting ']' brackets, it's inconsistent --- .../backend/batch/utilities/parser/output_parser_tool.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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,