update code locally

This commit is contained in:
stellahsr 2023-12-13 14:33:50 +08:00
parent 1da4409475
commit ea0b93d2b9
2 changed files with 21 additions and 17 deletions

View file

@ -63,18 +63,22 @@ class WriteCodeSteps(Action):
def get_context(self, plan: Plan):
user_requirement = plan.goal
select_task_keys = ['task_id', 'instruction', 'is_finished', 'code']
# select_task_keys = ['task_id', 'instruction', 'is_finished', 'code']
select_task_keys = ['task_id','code']
def process_task(task):
task_dict = task.dict()
ptask = {k: task_dict[k] for k in task_dict if k in select_task_keys}
ptask = {k: task_dict[k] for k in task_dict if k in select_task_keys }
return ptask
tasks = json.dumps(
[process_task(task) for task in plan.tasks], indent=4, ensure_ascii=False
[process_task(task) for task in plan.tasks if task.is_finished==True], indent=4, ensure_ascii=False
)
current_task = json.dumps(process_task(plan.current_task)) if plan.current_task else {}
context = STRUCTURAL_CONTEXT.format(
user_requirement=user_requirement, tasks=tasks, current_task=current_task
)
print(context)
# print(context)
return context

View file

@ -148,7 +148,7 @@ class MLEngineer(Role):
while self.plan.current_task:
task = self.plan.current_task
logger.info(f"ready to take on task {task}")
logger.info(f"ready to take on task: {task}")
# take on current task
code, result, success, code_steps = await self._write_and_exec_code()
@ -157,9 +157,11 @@ class MLEngineer(Role):
task_result_confirmed = await self._ask_review()
# 针对当前task进行单独plan
if not success or not task_result_confirmed:
# fixme: 增加对应plan
self.state.plan()
# if not success or not task_result_confirmed:
# # fixme: 增加对应plan
# logger.info(task.result)
# # import pdb;pdb.set_trace()
# # self.state.plan()
if success and task_result_confirmed:
# tick off this task and record progress
@ -175,13 +177,13 @@ class MLEngineer(Role):
# update plan according to user's feedback and to take on changed tasks
await self._update_plan()
finished_tasks = self.plan.get_finished_tasks()
if len(finished_tasks) == len(self.plan.tasks):
code_context = [task.code for task in finished_tasks]
code_context = "\n\n".join(code_context)
result, success = await self.execute_code.run(code_context)
# truncated the result
print(truncate(result))
# finished_tasks = self.plan.get_finished_tasks()
# if len(finished_tasks) == len(self.plan.tasks):
# code_context = [task.code for task in finished_tasks]
# code_context = "\n\n".join(code_context)
# result, success = await self.execute_code.run(code_context)
# # truncated the result
# print(truncate(result))
async def _generate_data_desc(self):
data_desc = await GenerateDataDesc().run(self.data_path)
@ -258,8 +260,6 @@ class MLEngineer(Role):
counter += 1
success = False
return code, result, success, code_steps
async def _ask_review(self):