Skip to content

Commit

Permalink
fix: Response getting ']' brackets, it's inconsistent (#1611)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavan-Microsoft <v-kupavan@microsoft.com>
  • Loading branch information
AjitPadhi-Microsoft and Pavan-Microsoft authored Jan 6, 2025
1 parent 5994f99 commit dc7b87c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions code/backend/batch/utilities/parser/output_parser_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dc7b87c

Please sign in to comment.