Skip to content

Commit

Permalink
fix for in response getting ']' brackets, it's inconsistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavan-Microsoft committed Jan 3, 2025
1 parent 983b1f7 commit 220cfce
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 220cfce

Please sign in to comment.