Spaces:
Sleeping
Sleeping
File size: 1,798 Bytes
9c60c5f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# # crew.py file of design_to_code
from crewai import Agent, Crew, Process, Task, LLM
from crewai.project import CrewBase, agent, crew, task
from tools.custom_tool import landing_ai_document_analysis
from dotenv import load_dotenv
import os
# Load environment variables
load_dotenv()
@CrewBase
class DocProcessing():
"""DocProcessing crew"""
agents_config = 'config/agents.yaml'
tasks_config = 'config/tasks.yaml'
def __init__(self, anthropic_api_key: str = None):
"""
Initialize DocProcessing crew with API key
Args:
anthropic_api_key: The Anthropic API key to use for LLM
"""
# Use provided API key or fall back to environment variable
api_key = anthropic_api_key or os.getenv("ANTHROPIC_API_KEY")
if not api_key:
raise ValueError("Anthropic API key is required. Please provide it as parameter or set ANTHROPIC_API_KEY environment variable.")
self.llm = LLM(
model="claude-3-haiku-20240307",
api_key=api_key,
temperature=0,
)
@agent
def document_analyst(self) -> Agent:
return Agent(
config=self.agents_config['document_analyst'],
tools=[landing_ai_document_analysis],
llm=self.llm,
)
@agent
def developer_agent(self) -> Agent:
return Agent(
config=self.agents_config['developer_agent'],
llm=self.llm,
)
@task
def document_analysis(self) -> Task:
return Task(
config=self.tasks_config['document_analysis'],
)
@task
def code_implementation(self) -> Task:
return Task(
config=self.tasks_config['code_implementation'],
)
@crew
def crew(self) -> Crew:
"""Creates the DocProcessing crew"""
return Crew(
agents=self.agents, # Automatically created by the @agent decorator
tasks=self.tasks, # Automatically created by the @task decorator
process=Process.sequential,
verbose=True,
) |