prompt improvements for wekaer models

This commit is contained in:
Evan Lohn 2025-02-03 10:30:51 -08:00
parent 024207e2d9
commit 3f6de7968a
2 changed files with 11 additions and 3 deletions

View File

@ -1,4 +1,3 @@
import re
from datetime import datetime
from typing import cast
@ -80,7 +79,12 @@ def extract_entities_terms(
prompt=msg,
)
cleaned_response = re.sub(r"```json\n|\n```", "", str(llm_response.content))
cleaned_response = (
str(llm_response.content).replace("```json\n", "").replace("\n```", "")
)
first_bracket = cleaned_response.find("{")
last_bracket = cleaned_response.rfind("}")
cleaned_response = cleaned_response[first_bracket : last_bracket + 1]
try:
entity_extraction_result = EntityExtractionResult.model_validate_json(

View File

@ -139,6 +139,7 @@ INITIAL_QUESTION_DECOMPOSITION_PROMPT = (
"{question}\n"
f"{SEPARATOR_LINE}\n\n"
"{history}\n\n"
"Do NOT include any text in your answer outside of the list of sub-questions!"
"Please formulate your answer as a newline-separated list of questions like so:\n"
" <sub-question>\n"
" <sub-question>\n"
@ -148,6 +149,7 @@ INITIAL_QUESTION_DECOMPOSITION_PROMPT = (
).strip()
# TODO: combine shared pieces with INITIAL_QUESTION_DECOMPOSITION_PROMPT
INITIAL_DECOMPOSITION_PROMPT_QUESTIONS_AFTER_SEARCH = (
"Decompose the initial user question into no more than 3 appropriate sub-questions that help to answer the"
" original question. The purpose for this decomposition may be to:\n"
@ -175,6 +177,7 @@ INITIAL_DECOMPOSITION_PROMPT_QUESTIONS_AFTER_SEARCH = (
"{question}\n"
f"{SEPARATOR_LINE}\n\n"
"{history}\n\n"
"Do NOT include any text in your answer outside of the list of sub-questions!"
"Please formulate your answer as a newline-separated list of questions like so:\n"
" <sub-question>\n"
" <sub-question>\n"
@ -194,6 +197,7 @@ QUERY_REWRITING_PROMPT = (
f"{SEPARATOR_LINE}\n"
"{question}\n"
f"{SEPARATOR_LINE}\n\n"
"Do NOT include any text in your answer outside of the list of queries!"
"Formulate the queries separated by newlines (Do not say 'Query 1: ...', just write the querytext) as follows:\n"
"<query 1>\n"
"<query 2>\n"
@ -221,7 +225,7 @@ DOCUMENT_VERIFICATION_PROMPT = (
f"{SEPARATOR_LINE}\n"
"{question}\n"
f"{SEPARATOR_LINE}\n\n"
"Please answer with exactly and only a 'yes' or 'no':\n\n"
"Please answer with exactly and only a 'yes' or 'no'. Do NOT include any other text in your response:\n\n"
"Answer:"
).strip()