ds_jiuzhang / deep_search /math_data /add_prompt.py
SunSec's picture
Add files using upload-large-folder tool
6ab6bc3 verified
import json
def save_to_json(data, filename):
"""保存数据到 JSON 文件"""
with open(filename, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
print(f"Saved to {filename}, data length: {len(data)}")
def load_json(file_path):
"""从 JSON 文件加载数据"""
with open(file_path, "r", encoding="utf-8") as f:
data = json.load(f)
print(f"Loaded from {file_path}, data length: {len(data)}")
return data
def get_multiqa_search_o1_instruction_4(MAX_SEARCH_LIMIT): # 给出的样例是进行了两次搜索
return (
"You are a reasoning assistant with the ability to perform web searches to help "
"you answer the user's question accurately. You have special tools:\n\n"
"- To perform a search: write <|begin_search_query|> your query here <|end_search_query|>.\n"
"Then, the system will search and analyze relevant web pages, then provide you with helpful information in the format <|begin_search_result|> ...search results... <|end_search_result|>.\n\n"
f"Whenever you encounter a topic, fact, or piece of information you are uncertain about or need further details on, please perform a search to gather more accurate, up-to-date, or specific information. 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"
"Remember:\n"
"- Use <|begin_search_query|> to request a web search and end with <|end_search_query|>.\n"
"- When done searching, continue your reasoning.\n"
"- Do not generate <|begin_search_result|> and <|end_search_result|> tags yourself.\n\n"
)
def get_task_instruction_math(question, model_name=None):
if model_name == 'qwq':
# user_prompt = (
# 'Please answer the following math question. '
# 'You should provide your final answer in the format \\boxed{YOUR_ANSWER}.\n\n'
# f'Question:\n{question}\n\n'
# )
user_prompt = (
'Please answer the following math question. '
'Please reason step by step, and put your final answer within \\boxed{}.\n\n'
f'Question:\n{question}\n\n'
)
else:
user_prompt = (
'Please answer the following math question. You should think step by step to solve it.\n\n'
'Provide your final answer in the format \\boxed{YOUR_ANSWER}.\n\n'
f'Question:\n{question}\n\n'
)
return user_prompt
input_file = "/opt/aps/workdir/sunshuang/deep_search/math_data/math_qwq_4524.json"
data = load_json(input_file)
for item in data:
instruction = get_multiqa_search_o1_instruction_4(10)
user_prompt = get_task_instruction_math(item["question"], model_name='qwq')
prompt = instruction + user_prompt
item["prompt"] = prompt
output_file = "/opt/aps/workdir/sunshuang/deep_search/math_data/math_qwq_4524_add_prompt.json"
save_to_json(data, output_file)