base_prompt.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. base_system_prompt = """<|system|>\n你是一位智能编程助手,你叫CodeGeeX。你会为用户回答关于编程、代码、计算机方面的任何问题,并提供格式规范、可以执行、准确安全的代码,并在必要时提供详细的解释。"""
  2. project_mermaid_prompt = """请你根据项目目录为这个项目生成一个架构图。请使用mermaid语言生成这个项目的核心架构图,请你确保mermaid的逻辑是正确的且能被解析的,只需要输出mermaid,需要graph LR形式,尽量精简节点,过滤掉对理解项目无关紧要的节点(ex:二进制文件,git文件,日志文件等等),只保留核心节点。"""
  3. file_summary_prompt = """请你为每个文件提供一句话的总结,描述这个文件的作用、内容、格式等等。输出格式:-filename: 文件名\n-summary: 文件总结 """
  4. web_search_prompy = """你将接收到一个用户提出的问题,并请撰写清晰、简洁且准确的答案。
  5. # Note
  6. - 您将获得与问题相关的多个上下文片段,每个上下文都以引用编号开头,例如[[citation:x]],其中x是一个数字。如果适用,请使用上下文并在每个句子的末尾引用上下文。
  7. - 您的答案必须是正确的、准确的,并且以专家的身份使用无偏见和专业的语调来撰写。
  8. - 请你的回答限制在2千字以内,不要提供与问题无关的信息,也不要重复。
  9. - 请以引用编号的格式[[citation:x]]来引用上下文。如果一个句子来自多个上下文,请列出所有适用的引用,例如[[citation:3]][[citation:5]]。
  10. - 若所有上下文均不相关,请以自己的理解回答用户提出的问题,此时回答中可以不带引用编号。
  11. - 除了代码和特定的名称和引用外,您的答案必须使用与问题相同的语言来撰写。
  12. """.lstrip()
  13. tools_choose_prompt = """<|user|>\nAs a tool selector, you'll provide users with suggestions on tool selection. Depending on the provided tool summary (tools_summary) and user input (input_text), you'll need to follow these steps:
  14. 1. Read and understand the tool summary (tools_summary):
  15. - Understand the features, suitcases, and limitations of each tool.
  16. 2. Analyze User Input (input_text):
  17. - Understand the user's needs or problems.
  18. - Identify keywords or phrases to determine which tool best suits the user's needs.
  19. 3. Decision-making logic:
  20. - Recommend a tool if the user's needs correspond to the tool's functionality.
  21. - If the user's needs are not suitable for any tool, or if the information is not sufficient to make a judgment, no tool is recommended.
  22. 4. Output:
  23. - If a tool is recommended, output the tool name (toolname).
  24. - If no tool is recommended, the output is empty.
  25. Note that recommendations for tool selection should be based on the user's needs and refer to the tool summary provided. Follow the steps above and make sure to provide accurate tool selection suggestions in the output.
  26. Here is some examples about tools choosing:
  27. Input:
  28. tools_summary: {
  29. "online_query": "Questions need to be queried on the Internet to ensure accurate answers",
  30. "project_qa": "Questions need to be answered specific to the project"
  31. }
  32. input_text: "今天星期几"
  33. Output:
  34. {
  35. "thoughts": {
  36. "text": "用户想知道今天是星期几。",
  37. "reasoning": "根据工具概要,'online_query' 是用来在互联网上查询问题以确保准确答案,这与用户的需求相符。",
  38. "criticism": "没有其他工具适合回答这类问题,因为这是一个需要实时信息的查询。",
  39. "speak": "让我在网上查一下今天是星期几。"
  40. },
  41. "tool": {
  42. "name": ["online_query"]
  43. }
  44. }
  45. Input:
  46. tools_summary: {
  47. "online_query": "Questions need to be queried on the Internet to ensure accurate answers",
  48. "project_qa": "Questions need to be answered specific to the project"
  49. }
  50. input_text: "你是谁"
  51. Output:
  52. {
  53. "thoughts": {
  54. "text": "用户问“你是谁”。",
  55. "reasoning": "用户的提问是一个通用问题,不涉及具体的工具功能需求。",
  56. "criticism": "这个问题不需要使用任何工具来回答,只需直接回答用户的问题即可。",
  57. "speak": "我是一个人工智能助手,随时为您提供帮助。"
  58. },
  59. "tool": {
  60. "name": []
  61. }
  62. }
  63. Input:
  64. tools_summary: {
  65. "online_query": "Questions need to be queried on the Internet to ensure accurate answers",
  66. "project_qa": "Questions need to be answered specific to the project"
  67. }
  68. input_text: "解释一下项目"
  69. Output:
  70. {
  71. "thoughts": {
  72. "text": "用户需要对项目进行解释。",
  73. "reasoning": "用户的需求是需要对项目进行解释,这通常涉及到具体项目的细节和背景。",
  74. "criticism": "目前的工具概要中,只有project_qa适用于与项目相关的问题解答。",
  75. "speak": "您能提供更多关于项目的信息吗?这将有助于提供更准确的解释。"
  76. },
  77. "tool": {
  78. "name": ["project_qa"]
  79. }
  80. }
  81. You should only respond in JSON format as described below
  82. Response Format:
  83. {
  84. "thoughts": {
  85. "text": "your thoughts in the current context",
  86. "reasoning": "reasoning for tool selection and input content",
  87. "criticism": "critical thinking on tool selection and input in current context",
  88. "speak": "words you want to speak to the user",
  89. },
  90. "tool": {
  91. "name": ['tool_name'],
  92. }
  93. }
  94. The strings corresponding to "text", "reasoning", "criticism", and "speak" in JSON should be described in Chinese.
  95. If you don't need to use a tool(like solely chat scene), or have already reasoned the final answer associated with user input from the tool, You must abide by the following rules:
  96. 1. The tool's name in json is [].
  97. Do not output any other information and do not contain quotation marks, such as `, \", \' and so on.
  98. Ensure the output can be parsed by Python json.loads.
  99. Don't output in markdown format, something like ```json or ```,just output in the corresponding string format.
  100. Input:
  101. tools_summary: {
  102. "online_query": "Questions need to be queried on the Internet to ensure accurate answers",
  103. "project_qa": "Questions need to be answered specific to the project"
  104. }
  105. """
  106. tools_input_prompt = """
  107. input_text: "{input_text}"
  108. Output:
  109. <|assistant|>\n"""
  110. def build_message_list(result):
  111. message_list = []
  112. segments = result.split("<|")
  113. for segment in segments:
  114. if segment.startswith("system|>"):
  115. message_list.append({"role": "system", "content": segment[8:]})
  116. elif segment.startswith("user|>"):
  117. message_list.append({"role": "user", "content": segment[6:]})
  118. elif segment.startswith("assistant|>"):
  119. message_list.append({"role": "assistant", "content": segment[11:]})
  120. return message_list
  121. def get_cur_base_user_prompt(message_history, index_prompt=None):
  122. user_prompt_tmp = """<|user|>\n{user_input}"""
  123. assistant_prompt_tmp = """<|assistant|>\n{assistant_input}"""
  124. history_prompt = ""
  125. for i, message in enumerate(message_history):
  126. if message["role"] == "user" or message["role"] == "tool":
  127. if i == 0 and index_prompt is not None:
  128. history_prompt += "<|user|>\n" + index_prompt + message["content"]
  129. else:
  130. history_prompt += user_prompt_tmp.format(user_input=message["content"])
  131. elif message["role"] == "assistant":
  132. history_prompt += assistant_prompt_tmp.format(
  133. assistant_input=message["content"]
  134. )
  135. result = base_system_prompt + history_prompt + """<|assistant|>\n"""
  136. message_list = build_message_list(result)
  137. # print(message_list)
  138. return message_list