File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed
llm/answering/stream_processing
tests/unit/danswer/llm/answering/stream_processing Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -231,16 +231,16 @@ def process_token(
231
231
232
232
model_previous = self .model_output
233
233
self .model_output += token
234
-
235
234
if not self .found_answer_start :
236
235
m = answer_pattern .search (self .model_output )
237
236
if m :
238
237
self .found_answer_start = True
239
238
240
239
# Prevent heavy cases of hallucinations
241
- if self .is_json_prompt and len (self .model_output ) > 70 :
242
- logger .warning ("LLM did not produce json as prompted" )
240
+ if self .is_json_prompt and len (self .model_output ) > 400 :
243
241
self .found_answer_end = True
242
+ logger .warning ("LLM did not produce json as prompted" )
243
+ logger .debug ("Model output thus far:" , self .model_output )
244
244
return
245
245
246
246
remaining = self .model_output [m .end () :]
Original file line number Diff line number Diff line change 4
4
import string
5
5
from urllib .parse import quote
6
6
7
+ from danswer .utils .logger import setup_logger
8
+
9
+
10
+ logger = setup_logger (__name__ )
7
11
8
12
ESCAPE_SEQUENCE_RE = re .compile (
9
13
r"""
@@ -77,7 +81,8 @@ def extract_embedded_json(s: str) -> dict:
77
81
last_brace_index = s .rfind ("}" )
78
82
79
83
if first_brace_index == - 1 or last_brace_index == - 1 :
80
- raise ValueError ("No valid json found" )
84
+ logger .warning ("No valid json found, assuming answer is entire string" )
85
+ return {"answer" : s , "quotes" : []}
81
86
82
87
json_str = s [first_brace_index : last_brace_index + 1 ]
83
88
try :
Original file line number Diff line number Diff line change @@ -324,8 +324,13 @@ def test_lengthy_prefixed_json_with_quotes() -> None:
324
324
assert quotes [0 ] == "Document"
325
325
326
326
327
- def test_prefixed_json_with_quotes () -> None :
327
+ def test_json_with_lengthy_prefix_and_quotes () -> None :
328
328
tokens = [
329
+ "*** Based on the provided documents, there does not appear to be any information " ,
330
+ "directly relevant to answering which documents are my favorite. " ,
331
+ "The documents seem to be focused on describing the Danswer product " ,
332
+ "and its features/use cases. Since I do not have personal preferences " ,
333
+ "for documents, I will provide a general response:\n \n " ,
329
334
"```" ,
330
335
"json" ,
331
336
"\n " ,
You can’t perform that action at this time.
0 commit comments