Skip to content

Commit

Permalink
Fix non-json model output processing (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhongsun96 authored Aug 25, 2023
1 parent 6897416 commit cb13f5b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions backend/danswer/direct_qa/qa_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ def process_model_tokens(
model_previous = model_output
model_output += token

trimmed_combine = model_output.replace(" ", "").replace("\n", "")
if not found_answer_start and '{"answer":"' in trimmed_combine:
if not found_answer_start and '{"answer":"' in re.sub(r"\s", "", model_output):
# Note, if the token that completes the pattern has additional text, for example if the token is "?
# Then the chars after " will not be streamed, but this is ok as it prevents streaming the ? in the
# event that the model outputs the UNCERTAINTY_PAT
Expand All @@ -232,7 +231,7 @@ def process_model_tokens(
if hold_quote + token in quote_pat_full:
hold_quote += token
continue
yield DanswerAnswerPiece(answer_piece=token)
yield DanswerAnswerPiece(answer_piece=hold_quote + token)
hold_quote = ""

logger.debug(f"Raw model output: {model_output}")
Expand Down

1 comment on commit cb13f5b

@vercel
Copy link

@vercel vercel bot commented on cb13f5b Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.