This commit is contained in:
Brandon Hancock
2024-08-02 09:02:27 -04:00
parent 8b7a1eadc3
commit 43e37444f3
8 changed files with 31 additions and 17 deletions

View File

@@ -1,9 +1,9 @@
import os
import shutil
from pathlib import Path from pathlib import Path
import click import click
from crewai.cli.utils import copy_template
def create_pipeline(name, router=False): def create_pipeline(name, router=False):
"""Create a new pipeline project.""" """Create a new pipeline project."""
@@ -42,28 +42,40 @@ def create_pipeline(name, router=False):
if router: if router:
crew_template_files.append("crews/write_linkedin_crew.py") crew_template_files.append("crews/write_linkedin_crew.py")
def process_file(src_file, dst_file):
with open(src_file, "r") as file:
content = file.read()
content = content.replace("{{name}}", name)
content = content.replace("{{crew_name}}", class_name)
content = content.replace("{{folder_name}}", folder_name)
content = content.replace("{{pipeline_name}}", class_name)
with open(dst_file, "w") as file:
file.write(content)
# Copy and process root template files # Copy and process root template files
for file_name in root_template_files: for file_name in root_template_files:
src_file = templates_dir / file_name src_file = templates_dir / file_name
dst_file = project_root / file_name dst_file = project_root / file_name
copy_template(src_file, dst_file, name, class_name, folder_name) process_file(src_file, dst_file)
# Copy and process src template files # Copy and process src template files
for file_name in src_template_files: for file_name in src_template_files:
src_file = templates_dir / file_name src_file = templates_dir / file_name
dst_file = project_root / "src" / folder_name / file_name dst_file = project_root / "src" / folder_name / file_name
copy_template(src_file, dst_file, name, class_name, folder_name) process_file(src_file, dst_file)
# Copy tools and config files # Copy tools and config files
for file_name in tools_template_files + config_template_files: for file_name in tools_template_files + config_template_files:
src_file = templates_dir / file_name src_file = templates_dir / file_name
dst_file = project_root / "src" / folder_name / file_name dst_file = project_root / "src" / folder_name / file_name
copy_template(src_file, dst_file, name, class_name, folder_name) shutil.copy(src_file, dst_file)
# Copy and process crew files # Copy and process crew files
for file_name in crew_template_files: for file_name in crew_template_files:
src_file = templates_dir / file_name src_file = templates_dir / file_name
dst_file = project_root / "src" / folder_name / file_name dst_file = project_root / "src" / folder_name / file_name
copy_template(src_file, dst_file, name, class_name, folder_name) process_file(src_file, dst_file)
click.secho(f"Pipeline {name} created successfully!", fg="green", bold=True) click.secho(f"Pipeline {name} created successfully!", fg="green", bold=True)

View File

@@ -17,8 +17,8 @@ class ResearchReport(BaseModel):
@CrewBase @CrewBase
class ResearchCrew(): class ResearchCrew():
"""Research Crew""" """Research Crew"""
agents_config = '../config/agents.yaml' agents_config = 'config/agents.yaml'
tasks_config = '../config/tasks.yaml' tasks_config = 'config/tasks.yaml'
@agent @agent
def researcher(self) -> Agent: def researcher(self) -> Agent:

View File

@@ -10,8 +10,8 @@ from crewai.project import CrewBase, agent, crew, task
@CrewBase @CrewBase
class WriteLinkedInCrew(): class WriteLinkedInCrew():
"""Research Crew""" """Research Crew"""
agents_config = '../config/agents.yaml' agents_config = 'config/agents.yaml'
tasks_config = '../config/tasks.yaml' tasks_config = 'config/tasks.yaml'
@agent @agent
def researcher(self) -> Agent: def researcher(self) -> Agent:

View File

@@ -10,8 +10,8 @@ from crewai.project import CrewBase, agent, crew, task
@CrewBase @CrewBase
class WriteXCrew(): class WriteXCrew():
"""Research Crew""" """Research Crew"""
agents_config = '../config/agents.yaml' agents_config = 'config/agents.yaml'
tasks_config = '../config/tasks.yaml' tasks_config = 'config/tasks.yaml'
@agent @agent
def x_writer_agent(self) -> Agent: def x_writer_agent(self) -> Agent:

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import asyncio import asyncio
from pipeline import {{pipeline_name}}Pipeline from {{folder_name}}.pipeline import {{pipeline_name}}Pipeline
async def run(): async def run():
""" """

View File

@@ -43,7 +43,7 @@ from .crews.write_x_crew import WriteXCrew
# Uncomment the following code block to use Example 1 # Uncomment the following code block to use Example 1
@PipelineBase @PipelineBase
class ContentPipeline: class {{pipeline_name}}Pipeline:
def __init__(self): def __init__(self):
# Initialize crews # Initialize crews
self.research_crew = ResearchCrew().crew() self.research_crew = ResearchCrew().crew()
@@ -64,12 +64,12 @@ class ContentPipeline:
return results return results
# EXAMPLE 2: Three-Stage Pipeline with Parallel Execution # EXAMPLE 2: Two-Stage Pipeline with Parallel Execution
# ------------------------------------------------------- # -------------------------------------------------------
# Uncomment the following code block to use Example 2 # Uncomment the following code block to use Example 2
# @PipelineBase # @PipelineBase
# class ContentPipeline: # class {{pipeline_name}}Pipeline:
# def __init__(self): # def __init__(self):
# # Initialize crews # # Initialize crews
# self.research_crew = ResearchCrew().crew() # self.research_crew = ResearchCrew().crew()

View File

@@ -11,7 +11,7 @@ crewai = { extras = ["tools"], path = "/Users/brandonhancock/Code/crewai/crewAI"
asyncio = "*" asyncio = "*"
[tool.poetry.scripts] [tool.poetry.scripts]
{{folder_name}} = "{{folder_name}}.src.{{folder_name}}.main:main" {{folder_name}} = "{{folder_name}}.main:main"
[build-system] [build-system]
requires = ["poetry-core"] requires = ["poetry-core"]

View File

@@ -34,6 +34,8 @@ def CrewBase(cls):
"Unable to dynamically determine the project's base directory, you must run it from the project's root directory." "Unable to dynamically determine the project's base directory, you must run it from the project's root directory."
) )
print("Base directory: ", self.base_directory)
self.agents_config = self.load_yaml( self.agents_config = self.load_yaml(
os.path.join(self.base_directory, self.original_agents_config_path) os.path.join(self.base_directory, self.original_agents_config_path)
) )