Skip to content

Commit

Permalink
Merge branch 'feat_math_sovler' of https://github.com/didiforgithub/M…
Browse files Browse the repository at this point in the history
…etaGPT into feat_math_sovler
  • Loading branch information
Ceaglex committed Apr 10, 2024
2 parents 509a3b2 + 393337c commit f7d13cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
20 changes: 12 additions & 8 deletions math_ai/codebase/math_resovler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}

Expand All @@ -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
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
45 changes: 27 additions & 18 deletions math_ai/codebase/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
一个可以参考的策略生成逻辑是{strategy}。
针对这一问题,一个基础的Plan{origin_plan}
现在,你需要基于你的问题,与你的解题策略,生成一个针对这一问题的解题规划与原因。解题规划是一个列表,其中的元素是一个字典,包含两个键,一个为desc,也就是你生成的子任务的描述,一个为phase,也就是你认为这个子任务的生成是基于什么策略的。
最终结果,请你使用JSON格式进行返回,一个可以参考的格式如下:
{{
Expand All @@ -27,42 +28,50 @@
"""

inference_prompt = """
你是全球最杰出的数学竞赛选手,你已经掌握了足够多的数学知识,你对此数学解题有着非常丰富的经验,你无需纠结于解题的过程,你可以直接给出解题的结果
你是全球最杰出的数学竞赛选手,你已经掌握了足够多的数学知识,你对此数学解题有着非常丰富的经验,你无需纠结于解题的过程,因为很多经过繁杂的推理步骤才能得到的中间结论对你来说都是显而易见的,所以你可以直接给出解题的结果
你现在要解决的任务是{problem_desc}
你的合作者已经完成了上游的一些推理,或许其中有一些能辅助到你对当前任务进行推理的内容{trajectory}
现在,你需要基于你的问题,结合你的经验,给出这个问题的推理和解答。
现在,你需要基于你的问题,结合你的经验,给出这个问题的推理和解答。推理是一个字符串,描述你得到答案的思维过程,answer是一个字符串,描述你对于这个问题的直接答案。
最终结果,请你使用JSON格式进行返回,一个可以参考的格式如下:
{{
"inference": <"inference,指的是你得到答案的思维过程,">,
"answer": <"answer,对于{problem_desc}中所描述的问题的直接答案">
"inference": <"inference">,
"answer": <"answer">
}}
"""

logic_validate_prompt = """
对当前结果与题目进行逻辑验证
"""

merge_inference_prompt = """
重览当前轨迹,重新思考当前结果,并进行合并
"""

result_validate_prompt = """
"""

logic_validate_prompt = """
对当前结果与题目进行逻辑验证
你是全球最杰出的数学竞赛选手,你已经掌握了足够多的数学知识,你对此数学解题有着非常丰富的经验,你无需纠结于解题的过程,你可以直接给出解题的结果。
你现在要解决的任务是{problem_desc}
你的合作者已经完成了上游的一些推理,或许其中有一些能辅助到你对当前任务进行推理的内容{trajectory}
但是这些内容并不是一个符合人类阅读规范的回答,而是你思考的逻辑与演算的过程。
请你判断,当前你的解答,在经过整理后,是否满足题目的要求,也就是说在经过整理后是否能够给出一个符合人类阅读规范的答案。
返回的结果格式为能够被Python解析的JSON格式,键为'result',值为布尔值。一个可供参考的例子如下:
{{
"result":<bool>
}}
"""

result_validate_prompt = """
你是一个数学大师,xxxx
现在,针对问题{},你已经做出了以下解答{}。
这些解答并不是一个符合人类阅读规范的回答,而是你思考的逻辑
请你判断,这些轨迹
inference_final_prompt = """
你是全球最杰出的数学竞赛选手,你已经掌握了足够多的数学知识,你对此数学解题有着非常丰富的经验,你无需纠结于解题的过程,你可以直接给出解题的结果。
你现在要解决的任务是{problem_desc}
你的合作者已经完成了上游的推理,但是还没有给出一个最终结果。或许其中有一些能辅助到你对当前任务进行推理的内容{trajectory}
你需要基于问题,与这些推理内容,直接给出最终的推理结果。
最终结果,请你使用JSON格式进行返回,一个可以参考的格式如下:
{{
"inference": <"inference,指的是你得到答案的思维过程,">,
"answer": <"answer,对于所描述的问题的直接答案">
}}
"""

di_prompt = """
在解决{problem}的过程中,你被指派解决这一子问题{subgoal}。
"""


0 comments on commit f7d13cb

Please sign in to comment.