|
|
|
|
|
|
|
|
END_SEARCH_RESULT = "<|end_search_result|>" |
|
|
END_SEARCH_RESULT = "<|end_search_result|>" |
|
|
MAX_SEARCH_LIMIT = 6 |
|
|
MAX_SEARCH_LIMIT = 6 |
|
|
|
|
|
|
|
|
REASON_PROMPT = ( |
|
|
|
|
|
"You are a reasoning assistant with the ability to perform dataset searches to help " |
|
|
|
|
|
"you answer the user's question accurately. You have special tools:\n\n" |
|
|
|
|
|
f"- To perform a search: write {BEGIN_SEARCH_QUERY} your query here {END_SEARCH_QUERY}.\n" |
|
|
|
|
|
f"Then, the system will search and analyze relevant content, then provide you with helpful information in the format {BEGIN_SEARCH_RESULT} ...search results... {END_SEARCH_RESULT}.\n\n" |
|
|
|
|
|
f"You can repeat the search process multiple times if necessary. The maximum number of search attempts is limited to {MAX_SEARCH_LIMIT}.\n\n" |
|
|
|
|
|
"Once you have all the information you need, continue your reasoning.\n\n" |
|
|
|
|
|
"-- Example 1 --\n" ######################################## |
|
|
|
|
|
"Question: \"Are both the directors of Jaws and Casino Royale from the same country?\"\n" |
|
|
|
|
|
"Assistant:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_QUERY}Who is the director of Jaws?{END_SEARCH_QUERY}\n\n" |
|
|
|
|
|
"User:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_RESULT}\nThe director of Jaws is Steven Spielberg...\n{END_SEARCH_RESULT}\n\n" |
|
|
|
|
|
"Continues reasoning with the new information.\n" |
|
|
|
|
|
"Assistant:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_QUERY}Where is Steven Spielberg from?{END_SEARCH_QUERY}\n\n" |
|
|
|
|
|
"User:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_RESULT}\nSteven Allan Spielberg is an American filmmaker...\n{END_SEARCH_RESULT}\n\n" |
|
|
|
|
|
"Continues reasoning with the new information...\n\n" |
|
|
|
|
|
"Assistant:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_QUERY}Who is the director of Casino Royale?{END_SEARCH_QUERY}\n\n" |
|
|
|
|
|
"User:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_RESULT}\nCasino Royale is a 2006 spy film directed by Martin Campbell...\n{END_SEARCH_RESULT}\n\n" |
|
|
|
|
|
"Continues reasoning with the new information...\n\n" |
|
|
|
|
|
"Assistant:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_QUERY}Where is Martin Campbell from?{END_SEARCH_QUERY}\n\n" |
|
|
|
|
|
"User:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_RESULT}\nMartin Campbell (born 24 October 1943) is a New Zealand film and television director...\n{END_SEARCH_RESULT}\n\n" |
|
|
|
|
|
"Continues reasoning with the new information...\n\n" |
|
|
|
|
|
"Assistant:\nIt's enough to answer the question\n" |
|
|
|
|
|
|
|
|
|
|
|
"-- Example 2 --\n" ######################################### |
|
|
|
|
|
"Question: \"When was the founder of craigslist born?\"\n" |
|
|
|
|
|
"Assistant:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_QUERY}Who was the founder of craigslist?{END_SEARCH_QUERY}\n\n" |
|
|
|
|
|
"User:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_RESULT}\nCraigslist was founded by Craig Newmark...\n{END_SEARCH_RESULT}\n\n" |
|
|
|
|
|
"Continues reasoning with the new information.\n" |
|
|
|
|
|
"Assistant:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_QUERY} When was Craig Newmark born?{END_SEARCH_QUERY}\n\n" |
|
|
|
|
|
"User:\n" |
|
|
|
|
|
f" {BEGIN_SEARCH_RESULT}\nCraig Newmark was born on December 6, 1952...\n{END_SEARCH_RESULT}\n\n" |
|
|
|
|
|
"Continues reasoning with the new information...\n\n" |
|
|
|
|
|
"Assistant:\nIt's enough to answer the question\n" |
|
|
|
|
|
"**Remember**:\n" |
|
|
|
|
|
f"- You have a dataset to search, so you just provide a proper search query.\n" |
|
|
|
|
|
f"- Use {BEGIN_SEARCH_QUERY} to request a dataset search and end with {END_SEARCH_QUERY}.\n" |
|
|
|
|
|
"- The language of query MUST be as the same as 'Question' or 'search result'.\n" |
|
|
|
|
|
"- If no helpful information can be found, rewrite the search query to be less and precise keywords.\n" |
|
|
|
|
|
"- When done searching, continue your reasoning.\n\n" |
|
|
|
|
|
'Please answer the following question. You should think step by step to solve it.\n\n' |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
RELEVANT_EXTRACTION_PROMPT = """**Task Instruction:** |
|
|
|
|
|
|
|
|
|
|
|
You are tasked with reading and analyzing web pages based on the following inputs: **Previous Reasoning Steps**, **Current Search Query**, and **Searched Web Pages**. Your objective is to extract relevant and helpful information for **Current Search Query** from the **Searched Web Pages** and seamlessly integrate this information into the **Previous Reasoning Steps** to continue reasoning for the original question. |
|
|
|
|
|
|
|
|
|
|
|
**Guidelines:** |
|
|
|
|
|
|
|
|
|
|
|
1. **Analyze the Searched Web Pages:** |
|
|
|
|
|
- Carefully review the content of each searched web page. |
|
|
|
|
|
- Identify factual information that is relevant to the **Current Search Query** and can aid in the reasoning process for the original question. |
|
|
|
|
|
|
|
|
|
|
|
2. **Extract Relevant Information:** |
|
|
|
|
|
- Select the information from the Searched Web Pages that directly contributes to advancing the **Previous Reasoning Steps**. |
|
|
|
|
|
- Ensure that the extracted information is accurate and relevant. |
|
|
|
|
|
|
|
|
|
|
|
3. **Output Format:** |
|
|
|
|
|
- **If the web pages provide helpful information for current search query:** Present the information beginning with `**Final Information**` as shown below. |
|
|
|
|
|
- The language of query **MUST BE** as the same as 'Search Query' or 'Web Pages'.\n" |
|
|
|
|
|
**Final Information** |
|
|
|
|
|
|
|
|
|
|
|
[Helpful information] |
|
|
|
|
|
|
|
|
|
|
|
- **If the web pages do not provide any helpful information for current search query:** Output the following text. |
|
|
|
|
|
|
|
|
|
|
|
**Final Information** |
|
|
|
|
|
|
|
|
|
|
|
No helpful information found. |
|
|
|
|
|
|
|
|
|
|
|
**Inputs:** |
|
|
|
|
|
- **Previous Reasoning Steps:** |
|
|
|
|
|
{prev_reasoning} |
|
|
|
|
|
|
|
|
|
|
|
- **Current Search Query:** |
|
|
|
|
|
{search_query} |
|
|
|
|
|
|
|
|
|
|
|
- **Searched Web Pages:** |
|
|
|
|
|
{document} |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
REASON_PROMPT = f"""You are an advanced reasoning agent. Your goal is to answer the user's question by breaking it down into a series of verifiable steps. |
|
|
|
|
|
|
|
|
|
|
|
You have access to a powerful search tool to find information. |
|
|
|
|
|
|
|
|
|
|
|
**Your Task:** |
|
|
|
|
|
1. Analyze the user's question. |
|
|
|
|
|
2. If you need information, issue a search query to find a specific fact. |
|
|
|
|
|
3. Review the search results. |
|
|
|
|
|
4. Repeat the search process until you have all the facts needed to answer the question. |
|
|
|
|
|
5. Once you have gathered sufficient information, synthesize the facts and provide the final answer directly. |
|
|
|
|
|
|
|
|
|
|
|
**Tool Usage:** |
|
|
|
|
|
- To search, you MUST write your query between the special tokens: {BEGIN_SEARCH_QUERY}your query{END_SEARCH_QUERY}. |
|
|
|
|
|
- The system will provide results between {BEGIN_SEARCH_RESULT}search results{END_SEARCH_RESULT}. |
|
|
|
|
|
- You have a maximum of {MAX_SEARCH_LIMIT} search attempts. |
|
|
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
**Example 1: Multi-hop Question** |
|
|
|
|
|
|
|
|
|
|
|
**Question:** "Are both the directors of Jaws and Casino Royale from the same country?" |
|
|
|
|
|
|
|
|
|
|
|
**Your Thought Process & Actions:** |
|
|
|
|
|
First, I need to identify the director of Jaws. |
|
|
|
|
|
{BEGIN_SEARCH_QUERY}who is the director of Jaws?{END_SEARCH_QUERY} |
|
|
|
|
|
[System returns search results] |
|
|
|
|
|
{BEGIN_SEARCH_RESULT} |
|
|
|
|
|
Jaws is a 1975 American thriller film directed by Steven Spielberg. |
|
|
|
|
|
{END_SEARCH_RESULT} |
|
|
|
|
|
Okay, the director of Jaws is Steven Spielberg. Now I need to find out his nationality. |
|
|
|
|
|
{BEGIN_SEARCH_QUERY}where is Steven Spielberg from?{END_SEARCH_QUERY} |
|
|
|
|
|
[System returns search results] |
|
|
|
|
|
{BEGIN_SEARCH_RESULT} |
|
|
|
|
|
Steven Allan Spielberg is an American filmmaker. Born in Cincinnati, Ohio... |
|
|
|
|
|
{END_SEARCH_RESULT} |
|
|
|
|
|
So, Steven Spielberg is from the USA. Next, I need to find the director of Casino Royale. |
|
|
|
|
|
{BEGIN_SEARCH_QUERY}who is the director of Casino Royale 2006?{END_SEARCH_QUERY} |
|
|
|
|
|
[System returns search results] |
|
|
|
|
|
{BEGIN_SEARCH_RESULT} |
|
|
|
|
|
Casino Royale is a 2006 spy film directed by Martin Campbell. |
|
|
|
|
|
{END_SEARCH_RESULT} |
|
|
|
|
|
The director of Casino Royale is Martin Campbell. Now I need his nationality. |
|
|
|
|
|
{BEGIN_SEARCH_QUERY}where is Martin Campbell from?{END_SEARCH_QUERY} |
|
|
|
|
|
[System returns search results] |
|
|
|
|
|
{BEGIN_SEARCH_RESULT} |
|
|
|
|
|
Martin Campbell (born 24 October 1943) is a New Zealand film and television director. |
|
|
|
|
|
{END_SEARCH_RESULT} |
|
|
|
|
|
I have all the information. Steven Spielberg is from the USA, and Martin Campbell is from New Zealand. They are not from the same country. |
|
|
|
|
|
|
|
|
|
|
|
Final Answer: No, the directors of Jaws and Casino Royale are not from the same country. Steven Spielberg is from the USA, and Martin Campbell is from New Zealand. |
|
|
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
**Example 2: Simple Fact Retrieval** |
|
|
|
|
|
|
|
|
|
|
|
**Question:** "When was the founder of craigslist born?" |
|
|
|
|
|
|
|
|
|
|
|
**Your Thought Process & Actions:** |
|
|
|
|
|
First, I need to know who founded craigslist. |
|
|
|
|
|
{BEGIN_SEARCH_QUERY}who founded craigslist?{END_SEARCH_QUERY} |
|
|
|
|
|
[System returns search results] |
|
|
|
|
|
{BEGIN_SEARCH_RESULT} |
|
|
|
|
|
Craigslist was founded in 1995 by Craig Newmark. |
|
|
|
|
|
{END_SEARCH_RESULT} |
|
|
|
|
|
The founder is Craig Newmark. Now I need his birth date. |
|
|
|
|
|
{BEGIN_SEARCH_QUERY}when was Craig Newmark born?{END_SEARCH_QUERY} |
|
|
|
|
|
[System returns search results] |
|
|
|
|
|
{BEGIN_SEARCH_RESULT} |
|
|
|
|
|
Craig Newmark was born on December 6, 1952. |
|
|
|
|
|
{END_SEARCH_RESULT} |
|
|
|
|
|
I have found the answer. |
|
|
|
|
|
|
|
|
|
|
|
Final Answer: The founder of craigslist, Craig Newmark, was born on December 6, 1952. |
|
|
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
**Important Rules:** |
|
|
|
|
|
- **One Fact at a Time:** Decompose the problem and issue one search query at a time to find a single, specific piece of information. |
|
|
|
|
|
- **Be Precise:** Formulate clear and precise search queries. If a search fails, rephrase it. |
|
|
|
|
|
- **Synthesize at the End:** Do not provide the final answer until you have completed all necessary searches. |
|
|
|
|
|
- **Language Consistency:** Your search queries should be in the same language as the user's question. |
|
|
|
|
|
|
|
|
|
|
|
Now, begin your work. Please answer the following question by thinking step-by-step. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
RELEVANT_EXTRACTION_PROMPT = """You are a highly efficient information extraction module. Your sole purpose is to extract the single most relevant piece of information from the provided `Searched Web Pages` that directly answers the `Current Search Query`. |
|
|
|
|
|
|
|
|
|
|
|
**Your Task:** |
|
|
|
|
|
1. Read the `Current Search Query` to understand what specific information is needed. |
|
|
|
|
|
2. Scan the `Searched Web Pages` to find the answer to that query. |
|
|
|
|
|
3. Extract only the essential, factual information that answers the query. Be concise. |
|
|
|
|
|
|
|
|
|
|
|
**Context (For Your Information Only):** |
|
|
|
|
|
The `Previous Reasoning Steps` are provided to give you context on the overall goal, but your primary focus MUST be on answering the `Current Search Query`. Do not use information from the previous steps in your output. |
|
|
|
|
|
|
|
|
|
|
|
**Output Format:** |
|
|
|
|
|
Your response must follow one of two formats precisely. |
|
|
|
|
|
|
|
|
|
|
|
1. **If a direct and relevant answer is found:** |
|
|
|
|
|
- Start your response immediately with `Final Information`. |
|
|
|
|
|
- Provide only the extracted fact(s). Do not add any extra conversational text. |
|
|
|
|
|
|
|
|
|
|
|
*Example:* |
|
|
|
|
|
`Current Search Query`: Where is Martin Campbell from? |
|
|
|
|
|
`Searched Web Pages`: [Long article snippet about Martin Campbell's career, which includes the sentence "Martin Campbell (born 24 October 1943) is a New Zealand film and television director..."] |
|
|
|
|
|
|
|
|
|
|
|
*Your Output:* |
|
|
|
|
|
Final Information |
|
|
|
|
|
Martin Campbell is a New Zealand film and television director. |
|
|
|
|
|
|
|
|
|
|
|
2. **If no relevant answer that directly addresses the query is found in the web pages:** |
|
|
|
|
|
- Start your response immediately with `Final Information`. |
|
|
|
|
|
- Write the exact phrase: `No helpful information found.` |
|
|
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
**BEGIN TASK** |
|
|
|
|
|
|
|
|
|
|
|
**Inputs:** |
|
|
|
|
|
|
|
|
|
|
|
- **Previous Reasoning Steps:** |
|
|
|
|
|
{prev_reasoning} |
|
|
|
|
|
|
|
|
|
|
|
- **Current Search Query:** |
|
|
|
|
|
{search_query} |
|
|
|
|
|
|
|
|
|
|
|
- **Searched Web Pages:** |
|
|
|
|
|
{document} |
|
|
|
|
|
""" |