mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-07-12 22:23:01 +02:00
added context type for when internet search tool is used (#3930)
This commit is contained in:
@ -140,6 +140,7 @@ def build_citations_user_message(
|
|||||||
context_docs: list[LlmDoc] | list[InferenceChunk],
|
context_docs: list[LlmDoc] | list[InferenceChunk],
|
||||||
all_doc_useful: bool,
|
all_doc_useful: bool,
|
||||||
history_message: str = "",
|
history_message: str = "",
|
||||||
|
context_type: str = "context documents",
|
||||||
) -> HumanMessage:
|
) -> HumanMessage:
|
||||||
multilingual_expansion = get_multilingual_expansion()
|
multilingual_expansion = get_multilingual_expansion()
|
||||||
task_prompt_with_reminder = build_task_prompt_reminders(
|
task_prompt_with_reminder = build_task_prompt_reminders(
|
||||||
@ -156,6 +157,7 @@ def build_citations_user_message(
|
|||||||
optional_ignore = "" if all_doc_useful else DEFAULT_IGNORE_STATEMENT
|
optional_ignore = "" if all_doc_useful else DEFAULT_IGNORE_STATEMENT
|
||||||
|
|
||||||
user_prompt = CITATIONS_PROMPT.format(
|
user_prompt = CITATIONS_PROMPT.format(
|
||||||
|
context_type=context_type,
|
||||||
optional_ignore_statement=optional_ignore,
|
optional_ignore_statement=optional_ignore,
|
||||||
context_docs_str=context_docs_str,
|
context_docs_str=context_docs_str,
|
||||||
task_prompt=task_prompt_with_reminder,
|
task_prompt=task_prompt_with_reminder,
|
||||||
@ -165,6 +167,7 @@ def build_citations_user_message(
|
|||||||
else:
|
else:
|
||||||
# if no context docs provided, assume we're in the tool calling flow
|
# if no context docs provided, assume we're in the tool calling flow
|
||||||
user_prompt = CITATIONS_PROMPT_FOR_TOOL_CALLING.format(
|
user_prompt = CITATIONS_PROMPT_FOR_TOOL_CALLING.format(
|
||||||
|
context_type=context_type,
|
||||||
task_prompt=task_prompt_with_reminder,
|
task_prompt=task_prompt_with_reminder,
|
||||||
user_query=query,
|
user_query=query,
|
||||||
history_block=history_block,
|
history_block=history_block,
|
||||||
|
@ -91,7 +91,7 @@ SAMPLE RESPONSE:
|
|||||||
# similar to the chat flow, but with the option of including a
|
# similar to the chat flow, but with the option of including a
|
||||||
# "conversation history" block
|
# "conversation history" block
|
||||||
CITATIONS_PROMPT = f"""
|
CITATIONS_PROMPT = f"""
|
||||||
Refer to the following context documents when responding to me.{DEFAULT_IGNORE_STATEMENT}
|
Refer to the following {{context_type}} when responding to me.{DEFAULT_IGNORE_STATEMENT}
|
||||||
|
|
||||||
CONTEXT:
|
CONTEXT:
|
||||||
{GENERAL_SEP_PAT}
|
{GENERAL_SEP_PAT}
|
||||||
@ -108,7 +108,7 @@ CONTEXT:
|
|||||||
# NOTE: need to add the extra line about "getting right to the point" since the
|
# NOTE: need to add the extra line about "getting right to the point" since the
|
||||||
# tool calling models from OpenAI tend to be more verbose
|
# tool calling models from OpenAI tend to be more verbose
|
||||||
CITATIONS_PROMPT_FOR_TOOL_CALLING = f"""
|
CITATIONS_PROMPT_FOR_TOOL_CALLING = f"""
|
||||||
Refer to the provided context documents when responding to me.{DEFAULT_IGNORE_STATEMENT} \
|
Refer to the provided {{context_type}} when responding to me.{DEFAULT_IGNORE_STATEMENT} \
|
||||||
You should always get right to the point, and never use extraneous language.
|
You should always get right to the point, and never use extraneous language.
|
||||||
|
|
||||||
{{history_block}}{{task_prompt}}
|
{{history_block}}{{task_prompt}}
|
||||||
|
@ -279,4 +279,5 @@ class InternetSearchTool(Tool):
|
|||||||
using_tool_calling_llm=using_tool_calling_llm,
|
using_tool_calling_llm=using_tool_calling_llm,
|
||||||
answer_style_config=self.answer_style_config,
|
answer_style_config=self.answer_style_config,
|
||||||
prompt_config=self.prompt_config,
|
prompt_config=self.prompt_config,
|
||||||
|
context_type="internet search results",
|
||||||
)
|
)
|
||||||
|
@ -25,6 +25,7 @@ def build_next_prompt_for_search_like_tool(
|
|||||||
using_tool_calling_llm: bool,
|
using_tool_calling_llm: bool,
|
||||||
answer_style_config: AnswerStyleConfig,
|
answer_style_config: AnswerStyleConfig,
|
||||||
prompt_config: PromptConfig,
|
prompt_config: PromptConfig,
|
||||||
|
context_type: str = "context documents",
|
||||||
) -> AnswerPromptBuilder:
|
) -> AnswerPromptBuilder:
|
||||||
if not using_tool_calling_llm:
|
if not using_tool_calling_llm:
|
||||||
final_context_docs_response = next(
|
final_context_docs_response = next(
|
||||||
@ -58,6 +59,7 @@ def build_next_prompt_for_search_like_tool(
|
|||||||
else False
|
else False
|
||||||
),
|
),
|
||||||
history_message=prompt_builder.single_message_history or "",
|
history_message=prompt_builder.single_message_history or "",
|
||||||
|
context_type=context_type,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user