created cli command for listing completed tasks ids

This commit is contained in:
Lorenze Jay
2024-07-12 15:08:53 -07:00
parent 96af6027bd
commit f39bce18a9
2 changed files with 41 additions and 0 deletions

View File

@@ -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()

View File

@@ -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)