Skip to content

Commit

Permalink
add task decompose function
Browse files Browse the repository at this point in the history
  • Loading branch information
dahaipeng committed Aug 30, 2024
1 parent bd7d5d7 commit fff71ff
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions modelscope_agent/agents/data_science_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
```json
[
{{
"task_id": str = "unique identifier for a task in plan, can be an \
ordinal, should be unique and not conflict with previous task ids",
"task_id": str = "unique identifier for a task in plan, can be an ordinal, \
should be unique and not conflict with previous task ids",
"dependent_task_ids": list[str] = "ids of tasks prerequisite to this task",
"instruction": "what you should do in this task, one short phrase or sentence",
"task_type": "type of this task, should be one of Available Task Types",
Expand Down Expand Up @@ -633,8 +633,8 @@ def _judge_code(self, task, previous_code_blocks, code,
if 'incorrect' in judge_result.split('\n')[-1]:
success = False
failed_reason = (
'Though the code executes successfully, The code logic is incorrect, here is the reason: '
+ judge_result)
'Though the code executes successfully, The code logic is \
incorrect, here is the reason: ' + judge_result)
return success, failed_reason

else:
Expand Down Expand Up @@ -819,8 +819,14 @@ def _decompose_task(self, task):
'content':
DECOMPOSE_TASK_TEMPLATE.format(
context='User Request: ' + task.instruction + '\n',
previous_tasks='\n'.join(
[json.dumps(t.__dict__) for t in self.plan.tasks]),
previous_tasks='\n'.join([
json.dumps({
'task_id': t.task_id,
'dependent_task_ids': t.dependent_task_ids,
'instruction': t.instruction,
'task_type': t.task_type
}) for t in self.plan.tasks
]),
current_task=json.dumps(task.__dict__))
}]
resp = self._call_llm(prompt=None, messages=messages, stop=None)
Expand All @@ -829,7 +835,7 @@ def _decompose_task(self, task):
tasks_text += r
tasks_text = parse_code(text=tasks_text, lang='json')
logger.info(f'decomposed tasks: {tasks_text}')
print(f'decomposed tasks: {tasks_text}')

tasks = json5.loads(tasks_text)
tasks = [Task(**task) for task in tasks]
return tasks
Expand Down

0 comments on commit fff71ff

Please sign in to comment.