From 231a833ad002d2414c93570ac44e6ca7b19a8744 Mon Sep 17 00:00:00 2001 From: Eduardo Chiarotti Date: Sat, 17 Aug 2024 08:41:53 -0300 Subject: [PATCH] feat: Add crewai install CLI command (#1203) * feat: Add crewai install CLI command * feat: Add crewai install to the docs and force now crewai run --- ...e-a-New-CrewAI-Pipeline-Template-Method.md | 9 +------- ...rt-a-New-CrewAI-Project-Template-Method.md | 8 +------ src/crewai/cli/cli.py | 11 ++++++++-- src/crewai/cli/install_crew.py | 21 +++++++++++++++++++ src/crewai/cli/templates/crew/README.md | 11 ++-------- src/crewai/cli/templates/pipeline/README.md | 8 ++----- .../cli/templates/pipeline_router/README.md | 7 ++----- 7 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 src/crewai/cli/install_crew.py diff --git a/docs/getting-started/Create-a-New-CrewAI-Pipeline-Template-Method.md b/docs/getting-started/Create-a-New-CrewAI-Pipeline-Template-Method.md index f3859779aa..3f9fa46a14 100644 --- a/docs/getting-started/Create-a-New-CrewAI-Pipeline-Template-Method.md +++ b/docs/getting-started/Create-a-New-CrewAI-Pipeline-Template-Method.md @@ -109,8 +109,7 @@ To install the dependencies for your project, use Poetry: ```shell $ cd -$ poetry lock -$ poetry install +$ crewai install ``` ## Running Your Pipeline Project @@ -121,12 +120,6 @@ To run your pipeline project, use the following command: $ crewai run ``` -or - -```shell -$ poetry run -``` - This will initialize your pipeline and begin task execution as defined in your `main.py` file. ## Deploying Your Pipeline Project diff --git a/docs/getting-started/Start-a-New-CrewAI-Project-Template-Method.md b/docs/getting-started/Start-a-New-CrewAI-Project-Template-Method.md index d3792413b8..d873d5ee76 100644 --- a/docs/getting-started/Start-a-New-CrewAI-Project-Template-Method.md +++ b/docs/getting-started/Start-a-New-CrewAI-Project-Template-Method.md @@ -191,8 +191,7 @@ To install the dependencies for your project, you can use Poetry. First, navigat ```shell $ cd my_project -$ poetry lock -$ poetry install +$ crewai install ``` This will install the dependencies specified in the `pyproject.toml` file. @@ -233,11 +232,6 @@ To run your project, use the following command: ```shell $ crewai run ``` -or -```shell -$ poetry run my_project -``` - This will initialize your crew of AI agents and begin task execution as defined in your configuration in the `main.py` file. ### Replay Tasks from Latest Crew Kickoff diff --git a/src/crewai/cli/cli.py b/src/crewai/cli/cli.py index bc6d5c21de..2ca4000003 100644 --- a/src/crewai/cli/cli.py +++ b/src/crewai/cli/cli.py @@ -8,6 +8,7 @@ ) from .evaluate_crew import evaluate_crew +from .install_crew import install_crew from .replay_from_task import replay_task_command from .reset_memories_command import reset_memories_command from .run_crew import run_crew @@ -165,10 +166,16 @@ def test(n_iterations: int, model: str): evaluate_crew(n_iterations, model) +@crewai.command() +def install(): + """Install the Crew.""" + install_crew() + + @crewai.command() def run(): - """Run the crew.""" - click.echo("Running the crew") + """Run the Crew.""" + click.echo("Running the Crew") run_crew() diff --git a/src/crewai/cli/install_crew.py b/src/crewai/cli/install_crew.py new file mode 100644 index 0000000000..bbafdad6fc --- /dev/null +++ b/src/crewai/cli/install_crew.py @@ -0,0 +1,21 @@ +import subprocess + +import click + + +def install_crew() -> None: + """ + Install the crew by running the Poetry command to lock and install. + """ + try: + subprocess.run(["poetry", "lock"], check=True, capture_output=False, text=True) + subprocess.run( + ["poetry", "install"], check=True, capture_output=False, text=True + ) + + except subprocess.CalledProcessError as e: + click.echo(f"An error occurred while running the crew: {e}", err=True) + click.echo(e.output, err=True) + + except Exception as e: + click.echo(f"An unexpected error occurred: {e}", err=True) diff --git a/src/crewai/cli/templates/crew/README.md b/src/crewai/cli/templates/crew/README.md index 0914be2097..5b4f02e067 100644 --- a/src/crewai/cli/templates/crew/README.md +++ b/src/crewai/cli/templates/crew/README.md @@ -14,12 +14,9 @@ pip install poetry Next, navigate to your project directory and install the dependencies: -1. First lock the dependencies and then install them: +1. First lock the dependencies and install them by using the CLI command: ```bash -poetry lock -``` -```bash -poetry install +crewai install ``` ### Customizing @@ -37,10 +34,6 @@ To kickstart your crew of AI agents and begin task execution, run this from the ```bash $ crewai run ``` -or -```bash -poetry run {{folder_name}} -``` This command initializes the {{name}} Crew, assembling the agents and assigning them tasks as defined in your configuration. diff --git a/src/crewai/cli/templates/pipeline/README.md b/src/crewai/cli/templates/pipeline/README.md index 3bb1bef6cb..433e43abed 100644 --- a/src/crewai/cli/templates/pipeline/README.md +++ b/src/crewai/cli/templates/pipeline/README.md @@ -17,11 +17,7 @@ Next, navigate to your project directory and install the dependencies: 1. First lock the dependencies and then install them: ```bash -poetry lock -``` - -```bash -poetry install +crewai install ``` ### Customizing @@ -38,7 +34,7 @@ poetry install To kickstart your crew of AI agents and begin task execution, run this from the root folder of your project: ```bash -poetry run {{folder_name}} +crewai run ``` This command initializes the {{name}} Crew, assembling the agents and assigning them tasks as defined in your configuration. diff --git a/src/crewai/cli/templates/pipeline_router/README.md b/src/crewai/cli/templates/pipeline_router/README.md index 60dc617e9d..d710c341a0 100644 --- a/src/crewai/cli/templates/pipeline_router/README.md +++ b/src/crewai/cli/templates/pipeline_router/README.md @@ -16,10 +16,7 @@ Next, navigate to your project directory and install the dependencies: 1. First lock the dependencies and then install them: ```bash -poetry lock -``` -```bash -poetry install +crewai install ``` ### Customizing @@ -35,7 +32,7 @@ poetry install To kickstart your crew of AI agents and begin task execution, run this from the root folder of your project: ```bash -poetry run {{folder_name}} +crewai run ``` This command initializes the {{name}} Crew, assembling the agents and assigning them tasks as defined in your configuration.