mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-08 11:58:34 +02:00
minor touchups
This commit is contained in:
parent
6f50f6710a
commit
9738e5e628
@ -110,13 +110,13 @@ class SingleMessageQAHandler(QAHandler):
|
||||
content="You are a question answering system that is constantly learning and improving. "
|
||||
"You can process and comprehend vast amounts of text and utilize this knowledge "
|
||||
"to provide accurate and detailed answers to diverse queries.\n"
|
||||
"You ALWAYS responds in a json containing an answer and quotes that support the answer.\n"
|
||||
"You ALWAYS responds with only a json containing an answer and quotes that support the answer.\n"
|
||||
"Your responses are as INFORMATIVE and DETAILED as possible.\n"
|
||||
f"{GENERAL_SEP_PAT}CONTEXT:\n\n{context_docs_str}"
|
||||
f"{GENERAL_SEP_PAT}Sample response:"
|
||||
f"{CODE_BLOCK_PAT.format(json.dumps(EMPTY_SAMPLE_JSON))}\n"
|
||||
f"{QUESTION_PAT} {query}\n"
|
||||
"Hint: Make the answer as detailed as possible and use a JSON! "
|
||||
"Hint: Make the answer as DETAILED as possible and respond in JSON format!\n"
|
||||
"Quotes MUST be EXACT substrings from provided documents!"
|
||||
)
|
||||
]
|
||||
|
@ -25,6 +25,7 @@ from danswer.dynamic_configs import get_dynamic_config_store
|
||||
from danswer.llm.utils import check_number_of_tokens
|
||||
from danswer.utils.logger import setup_logger
|
||||
from danswer.utils.text_processing import clean_model_quote
|
||||
from danswer.utils.text_processing import clean_up_code_blocks
|
||||
from danswer.utils.text_processing import shared_precompare_cleanup
|
||||
|
||||
logger = setup_logger()
|
||||
@ -158,7 +159,9 @@ def process_answer(
|
||||
chunks: list[InferenceChunk],
|
||||
is_json_prompt: bool = True,
|
||||
) -> tuple[DanswerAnswer, DanswerQuotes]:
|
||||
answer, quote_strings = separate_answer_quotes(answer_raw, is_json_prompt)
|
||||
answer_clean = clean_up_code_blocks(answer_raw)
|
||||
|
||||
answer, quote_strings = separate_answer_quotes(answer_clean, is_json_prompt)
|
||||
if answer == UNCERTAINTY_PAT or not answer:
|
||||
if answer == UNCERTAINTY_PAT:
|
||||
logger.debug("Answer matched UNCERTAINTY_PAT")
|
||||
@ -226,6 +229,12 @@ def process_model_tokens(
|
||||
# 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
|
||||
found_answer_start = True
|
||||
|
||||
# Prevent heavy cases of hallucinations where model is not even providing a json until later
|
||||
if is_json_prompt and len(model_output) > 20:
|
||||
logger.warning("LLM did not produce json as prompted")
|
||||
found_answer_end = True
|
||||
|
||||
continue
|
||||
|
||||
if found_answer_start and not found_answer_end:
|
||||
|
@ -51,6 +51,8 @@ def get_query_validation_messages(user_query: str) -> list[dict[str, str]]:
|
||||
f"relevant and consistent knowledge about the entity.\n"
|
||||
f"The system is not tuned for writing code.\n"
|
||||
f"The system is not tuned for interfacing with structured data via query languages like SQL.\n"
|
||||
f"If the question might not require code or query language, "
|
||||
f"then assume it can be answered without code or query language.\n"
|
||||
f"Determine if that system should attempt to answer.\n"
|
||||
f'"{ANSWERABLE_PAT}" must be exactly "True" or "False"\n{GENERAL_SEP_PAT}\n'
|
||||
f"{ambiguous_example_question}{CODE_BLOCK_PAT.format(ambiguous_example_answer)}\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user