You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

prompts.py 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. BEGIN_SEARCH_QUERY = "<|begin_search_query|>"
  17. END_SEARCH_QUERY = "<|end_search_query|>"
  18. BEGIN_SEARCH_RESULT = "<|begin_search_result|>"
  19. END_SEARCH_RESULT = "<|end_search_result|>"
  20. MAX_SEARCH_LIMIT = 6
  21. REASON_PROMPT = (
  22. "You are a reasoning assistant with the ability to perform dataset searches to help "
  23. "you answer the user's question accurately. You have special tools:\n\n"
  24. f"- To perform a search: write {BEGIN_SEARCH_QUERY} your query here {END_SEARCH_QUERY}.\n"
  25. 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"
  26. 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"
  27. "Once you have all the information you need, continue your reasoning.\n\n"
  28. "-- Example 1 --\n" ########################################
  29. "Question: \"Are both the directors of Jaws and Casino Royale from the same country?\"\n"
  30. "Assistant:\n"
  31. f" {BEGIN_SEARCH_QUERY}Who is the director of Jaws?{END_SEARCH_QUERY}\n\n"
  32. "User:\n"
  33. f" {BEGIN_SEARCH_RESULT}\nThe director of Jaws is Steven Spielberg...\n{END_SEARCH_RESULT}\n\n"
  34. "Continues reasoning with the new information.\n"
  35. "Assistant:\n"
  36. f" {BEGIN_SEARCH_QUERY}Where is Steven Spielberg from?{END_SEARCH_QUERY}\n\n"
  37. "User:\n"
  38. f" {BEGIN_SEARCH_RESULT}\nSteven Allan Spielberg is an American filmmaker...\n{END_SEARCH_RESULT}\n\n"
  39. "Continues reasoning with the new information...\n\n"
  40. "Assistant:\n"
  41. f" {BEGIN_SEARCH_QUERY}Who is the director of Casino Royale?{END_SEARCH_QUERY}\n\n"
  42. "User:\n"
  43. f" {BEGIN_SEARCH_RESULT}\nCasino Royale is a 2006 spy film directed by Martin Campbell...\n{END_SEARCH_RESULT}\n\n"
  44. "Continues reasoning with the new information...\n\n"
  45. "Assistant:\n"
  46. f" {BEGIN_SEARCH_QUERY}Where is Martin Campbell from?{END_SEARCH_QUERY}\n\n"
  47. "User:\n"
  48. f" {BEGIN_SEARCH_RESULT}\nMartin Campbell (born 24 October 1943) is a New Zealand film and television director...\n{END_SEARCH_RESULT}\n\n"
  49. "Continues reasoning with the new information...\n\n"
  50. "Assistant:\nIt's enough to answer the question\n"
  51. "-- Example 2 --\n" #########################################
  52. "Question: \"When was the founder of craigslist born?\"\n"
  53. "Assistant:\n"
  54. f" {BEGIN_SEARCH_QUERY}Who was the founder of craigslist?{END_SEARCH_QUERY}\n\n"
  55. "User:\n"
  56. f" {BEGIN_SEARCH_RESULT}\nCraigslist was founded by Craig Newmark...\n{END_SEARCH_RESULT}\n\n"
  57. "Continues reasoning with the new information.\n"
  58. "Assistant:\n"
  59. f" {BEGIN_SEARCH_QUERY} When was Craig Newmark born?{END_SEARCH_QUERY}\n\n"
  60. "User:\n"
  61. f" {BEGIN_SEARCH_RESULT}\nCraig Newmark was born on December 6, 1952...\n{END_SEARCH_RESULT}\n\n"
  62. "Continues reasoning with the new information...\n\n"
  63. "Assistant:\nIt's enough to answer the question\n"
  64. "**Remember**:\n"
  65. f"- You have a dataset to search, so you just provide a proper search query.\n"
  66. f"- Use {BEGIN_SEARCH_QUERY} to request a dataset search and end with {END_SEARCH_QUERY}.\n"
  67. "- The language of query MUST be as the same as 'Question' or 'search result'.\n"
  68. "- If no helpful information can be found, rewrite the search query to be less and precise keywords.\n"
  69. "- When done searching, continue your reasoning.\n\n"
  70. 'Please answer the following question. You should think step by step to solve it.\n\n'
  71. )
  72. RELEVANT_EXTRACTION_PROMPT = """**Task Instruction:**
  73. 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.
  74. **Guidelines:**
  75. 1. **Analyze the Searched Web Pages:**
  76. - Carefully review the content of each searched web page.
  77. - Identify factual information that is relevant to the **Current Search Query** and can aid in the reasoning process for the original question.
  78. 2. **Extract Relevant Information:**
  79. - Select the information from the Searched Web Pages that directly contributes to advancing the **Previous Reasoning Steps**.
  80. - Ensure that the extracted information is accurate and relevant.
  81. 3. **Output Format:**
  82. - **If the web pages provide helpful information for current search query:** Present the information beginning with `**Final Information**` as shown below.
  83. - The language of query **MUST BE** as the same as 'Search Query' or 'Web Pages'.\n"
  84. **Final Information**
  85. [Helpful information]
  86. - **If the web pages do not provide any helpful information for current search query:** Output the following text.
  87. **Final Information**
  88. No helpful information found.
  89. **Inputs:**
  90. - **Previous Reasoning Steps:**
  91. {prev_reasoning}
  92. - **Current Search Query:**
  93. {search_query}
  94. - **Searched Web Pages:**
  95. {document}
  96. """