From f39bce18a93e29cab93b928f13c3d3cd501b17fb Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Fri, 12 Jul 2024 15:08:53 -0700 Subject: [PATCH] created cli command for listing completed tasks ids --- src/crewai/cli/cli.py | 7 ++++++ src/crewai/cli/list_task_outputs.py | 34 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/crewai/cli/list_task_outputs.py diff --git a/src/crewai/cli/cli.py b/src/crewai/cli/cli.py index eb6ef204b..ae8f8837c 100644 --- a/src/crewai/cli/cli.py +++ b/src/crewai/cli/cli.py @@ -5,6 +5,7 @@ import pkg_resources from .create_crew import create_crew from .train_crew import train_crew from .replay_from_task import replay_task_command +from .list_task_outputs import show_task_outputs @click.group() @@ -71,5 +72,11 @@ def replay(task_id: str) -> None: click.echo(f"An error occurred while replaying: {e}", err=True) +@crewai.command() +def list_completed_tasks_ids(): + """List all task outputs saved from crew_tasks_output.json.""" + show_task_outputs() + + if __name__ == "__main__": crewai() diff --git a/src/crewai/cli/list_task_outputs.py b/src/crewai/cli/list_task_outputs.py new file mode 100644 index 000000000..ab01901af --- /dev/null +++ b/src/crewai/cli/list_task_outputs.py @@ -0,0 +1,34 @@ +import subprocess +import click +from pathlib import Path +import json + + +def show_task_outputs() -> None: + """ + Replay the crew execution from a specific task. + + Args: + task_id (str): The ID of the task to replay from. + """ + + try: + file_path = Path("crew_tasks_output.json") + if not file_path.exists(): + click.echo("crew_tasks_output.json not found.") + return + + with open(file_path, "r") as f: + tasks = json.load(f) + + for index, task in enumerate(tasks): + click.echo(f"Task {index}: {task['task_id']}") + click.echo(f"Description: {task['output']['description']}") + click.echo("---") + + except subprocess.CalledProcessError as e: + click.echo(f"An error occurred while replaying the task: {e}", err=True) + click.echo(e.output, err=True) + + except Exception as e: + click.echo(f"An unexpected error occurred: {e}", err=True)