From 3788041115f7a50ec3fbc02eb221033446613a43 Mon Sep 17 00:00:00 2001 From: Weves Date: Mon, 3 Jun 2024 16:31:11 -0700 Subject: [PATCH] Fix missing end of answer for quotes processor --- .../answering/stream_processing/quotes_processing.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/danswer/llm/answering/stream_processing/quotes_processing.py b/backend/danswer/llm/answering/stream_processing/quotes_processing.py index 61d379a53..10d15b719 100644 --- a/backend/danswer/llm/answering/stream_processing/quotes_processing.py +++ b/backend/danswer/llm/answering/stream_processing/quotes_processing.py @@ -247,6 +247,17 @@ def process_model_tokens( if found_answer_start and not found_answer_end: if is_json_prompt and _stream_json_answer_end(model_previous, token): found_answer_end = True + + # return the remaining part of the answer e.g. token might be 'd.", ' and we should yield 'd.' + if token: + try: + answer_token_section = token.index('"') + yield DanswerAnswerPiece( + answer_piece=hold_quote + token[:answer_token_section] + ) + except ValueError: + logger.error("Quotation mark not found in token") + yield DanswerAnswerPiece(answer_piece=hold_quote + token) yield DanswerAnswerPiece(answer_piece=None) continue elif not is_json_prompt: