From e4ee3efeb89f24762baa2758a23962fb544e6df1 Mon Sep 17 00:00:00 2001 From: stellahsr Date: Thu, 14 Dec 2023 10:46:43 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=8C=89code=20step=20=E9=80=90?= =?UTF-8?q?=E4=B8=80=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/actions/write_analysis_code.py | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/metagpt/actions/write_analysis_code.py b/metagpt/actions/write_analysis_code.py index 3e91f4b14..1cfc28811 100644 --- a/metagpt/actions/write_analysis_code.py +++ b/metagpt/actions/write_analysis_code.py @@ -202,8 +202,34 @@ class WriteCodeWithTools(BaseWriteAnalysisCode): module_name=module_name, tool_catalog=tool_catalog, ) - - + code_steps_ = eval(code_steps) + print(code_steps_) + + new_code = "" + tool_context = "" + for idx, (step_id, step_instruction) in enumerate(code_steps_.items()): + prompt = TOOL_USAGE_PROMPT.format( + user_requirement=plan.goal, + history_code=code_context, + current_task=plan.current_task.instruction, + column_info=column_info, + special_prompt=special_prompt, + code_steps=step_instruction, + module_name=module_name, + tool_catalog=tool_catalog, + ) + + tool_config = create_func_config(CODE_GENERATOR_WITH_TOOLS) + + rsp = await self.llm.aask_code(prompt, **tool_config) + logger.info(f"rsp is: {rsp}") + new_code = new_code + "\n\n" + rsp["code"] + code_context = code_context + "\n\n" + new_code + tool_context = tool_context + "\n\n" + prompt + context = [Message(content=tool_context, role="user")] + return context, new_code + + else: prompt = GENERATE_CODE_PROMPT.format( user_requirement=plan.goal,