From 7eb91f142a826c9642075d1c975cd45cdc8c7f76 Mon Sep 17 00:00:00 2001 From: qixucen <906372563@qq.com> Date: Wed, 10 Apr 2024 23:15:59 +0800 Subject: [PATCH 1/2] update inference --- math_ai/codebase/prompt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/math_ai/codebase/prompt.py b/math_ai/codebase/prompt.py index 575e9562b6..7516ae2d20 100644 --- a/math_ai/codebase/prompt.py +++ b/math_ai/codebase/prompt.py @@ -27,14 +27,14 @@ """ inference_prompt = """ -你是全球最杰出的数学竞赛选手,你已经掌握了足够多的数学知识,你对此数学解题有着非常丰富的经验,你无需纠结于解题的过程,你可以直接给出解题的结果。 +你是全球最杰出的数学竞赛选手,你已经掌握了足够多的数学知识,你对此数学解题有着非常丰富的经验,你无需纠结于解题的过程,因为很多经过繁杂的推理步骤才能得到的中间结论对你来说都是显而易见的,所以你可以直接给出解题的结果。 你现在要解决的任务是{problem_desc} 你的合作者已经完成了上游的一些推理,或许其中有一些能辅助到你对当前任务进行推理的内容{trajectory} -现在,你需要基于你的问题,结合你的经验,给出这个问题的推理和解答。 +现在,你需要基于你的问题,结合你的经验,给出这个问题的推理和解答。推理是一个字符串,描述你得到答案的思维过程,answer是一个字符串,描述你对于这个问题的直接答案。 最终结果,请你使用JSON格式进行返回,一个可以参考的格式如下: {{ - "inference": <"inference,指的是你得到答案的思维过程,">, - "answer": <"answer,对于{problem_desc}中所描述的问题的直接答案"> + "inference": <"inference">, + "answer": <"answer"> }} """ From 393337cf2af2facd4d0aa7e0b0e7d1fd1921acd9 Mon Sep 17 00:00:00 2001 From: didi <2020201387@ruc.edu.cn> Date: Wed, 10 Apr 2024 23:22:28 +0800 Subject: [PATCH 2/2] Update Math Resolver & Prompt --- math_ai/codebase/math_resovler.py | 20 ++++++++++------- math_ai/codebase/prompt.py | 37 +++++++++++++++++++------------ 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/math_ai/codebase/math_resovler.py b/math_ai/codebase/math_resovler.py index b698bbc4f1..74ef09618b 100644 --- a/math_ai/codebase/math_resovler.py +++ b/math_ai/codebase/math_resovler.py @@ -8,7 +8,7 @@ from typing import Dict from metagpt.roles.di.data_interpreter import DataInterpreter from math_ai.codebase.engine.llm import OpenAILLM -from math_ai.codebase.prompt import zero_shot_planner, resolver_planner, inference_prompt, di_prompt, result_validate_prompt +from math_ai.codebase.prompt import zero_shot_planner, resolver_planner, inference_prompt, di_prompt, result_validate_prompt, inference_final_prompt, logic_validate_prompt # TODO add different phase in codebase.phase @@ -61,6 +61,8 @@ async def single_run(self, problem: Dict, types: Dict) -> Dict: if self.result_validate(problem, current_trajectory): pass else: + current_trajectory += self.inference_final(problem, current_trajectory) + pass return {"current_trajectory": current_trajectory} @@ -72,15 +74,17 @@ async def di_run(self, problem, current_trajectory, subgoal): return "Hello world" def inference(self, problem, current_trajectory, subgoal): - self.llm.llm_response(prompt=result_validate_prompt.format(problem=problem, trajectoty=current_trajectory),json_mode=True) + inference_result = self.llm.llm_response(prompt=inference_prompt.format(problem=problem, trajectoty=current_trajectory),json_mode=True) + return inference_result def logic_validate(self, problem, current_trajectory, subgoal): - self.llm.llm_response(prompt=result_validate_prompt.format(problem=problem, trajectoty=current_trajectory),json_mode=True) - return "OK" + validate_result = self.llm.llm_response(prompt=logic_validate_prompt.format(problem=problem, trajectoty=current_trajectory),json_mode=True) + return validate_result def result_validate(self, problem, current_trajectory): - validate_result = self.llm.llm_response(prompt=result_validate_prompt.format(problem=problem, trajectoty=current_trajectory),json_mode=True) - return validate_result + result_validate_result = self.llm.llm_response(prompt=result_validate_prompt.format(problem=problem, trajectoty=current_trajectory),json_mode=True) + return result_validate_result - def inference_final(self, ): - pass \ No newline at end of file + def inference_final(self, problem, current_trajectory): + final_result = self.llm.llm_response(prompt=inference_final_prompt.format(problem=problem, trajectoty=current_trajectory)) + return final_result \ No newline at end of file diff --git a/math_ai/codebase/prompt.py b/math_ai/codebase/prompt.py index 7516ae2d20..c0a971788d 100644 --- a/math_ai/codebase/prompt.py +++ b/math_ai/codebase/prompt.py @@ -17,6 +17,7 @@ 一个可以参考的策略生成逻辑是{strategy}。 针对这一问题,一个基础的Plan{origin_plan} + 现在,你需要基于你的问题,与你的解题策略,生成一个针对这一问题的解题规划与原因。解题规划是一个列表,其中的元素是一个字典,包含两个键,一个为desc,也就是你生成的子任务的描述,一个为phase,也就是你认为这个子任务的生成是基于什么策略的。 最终结果,请你使用JSON格式进行返回,一个可以参考的格式如下: {{ @@ -42,27 +43,35 @@ 对当前结果与题目进行逻辑验证 """ -merge_inference_prompt = """ -重览当前轨迹,重新思考当前结果,并进行合并 -""" - result_validate_prompt = """ - -""" - -logic_validate_prompt = """ -对当前结果与题目进行逻辑验证 +你是全球最杰出的数学竞赛选手,你已经掌握了足够多的数学知识,你对此数学解题有着非常丰富的经验,你无需纠结于解题的过程,你可以直接给出解题的结果。 +你现在要解决的任务是{problem_desc} +你的合作者已经完成了上游的一些推理,或许其中有一些能辅助到你对当前任务进行推理的内容{trajectory} +但是这些内容并不是一个符合人类阅读规范的回答,而是你思考的逻辑与演算的过程。 +请你判断,当前你的解答,在经过整理后,是否满足题目的要求,也就是说在经过整理后是否能够给出一个符合人类阅读规范的答案。 +返回的结果格式为能够被Python解析的JSON格式,键为'result',值为布尔值。一个可供参考的例子如下: +{{ + "result": +}} """ -result_validate_prompt = """ -你是一个数学大师,xxxx -现在,针对问题{},你已经做出了以下解答{}。 -这些解答并不是一个符合人类阅读规范的回答,而是你思考的逻辑 -请你判断,这些轨迹 +inference_final_prompt = """ +你是全球最杰出的数学竞赛选手,你已经掌握了足够多的数学知识,你对此数学解题有着非常丰富的经验,你无需纠结于解题的过程,你可以直接给出解题的结果。 +你现在要解决的任务是{problem_desc} +你的合作者已经完成了上游的推理,但是还没有给出一个最终结果。或许其中有一些能辅助到你对当前任务进行推理的内容{trajectory} +你需要基于问题,与这些推理内容,直接给出最终的推理结果。 +最终结果,请你使用JSON格式进行返回,一个可以参考的格式如下: +{{ + "inference": <"inference,指的是你得到答案的思维过程,">, + "answer": <"answer,对于所描述的问题的直接答案"> +}} """ di_prompt = """ +在解决{problem}的过程中,你被指派解决这一子问题{subgoal}。 + + """