File size: 2,112 Bytes
38980bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
from typing import List
from crewai import Agent, Crew, Process, Task, LLM
from crewai.project import CrewBase, agent, task, crew
from crewai_tools import SerperDevTool, ScrapeWebsiteTool

from pydantic import BaseModel, Field
from dotenv import load_dotenv

_ = load_dotenv()

llm = LLM(
    model="gemini/gemini-2.0-flash",
    temperature=0.7,
)

class EventProposal(BaseModel):
    title: str = Field(..., description="The event title")
    description: str = Field(..., description="Event description, max 200 words")
    tags: List[str] = Field(..., description="List of 5 suggested tags")


class EventProposals(BaseModel):
    proposals: List[EventProposal] = Field(..., description="List of event proposals")


@CrewBase
class EventContentCrew:
    """Crew for generating and validating event proposals"""

    agents_config = "config/agents.yaml"
    tasks_config = "config/tasks.yaml"

    @agent
    def event_generator(self) -> Agent:
        return Agent(
            config=self.agents_config["event_generator"],
            llm=llm,
            inject_date=True,
            tools=[
                SerperDevTool()
            ]
        )

    @agent
    def event_validator(self) -> Agent:
        return Agent(
            config=self.agents_config["event_validator"],
            llm=llm,
            inject_date=True,
        )

    @task
    def generate_event_content(self) -> Task:
        return Task(
            config=self.tasks_config["generate_event_content"],
            agent=self.event_generator(),
            output_json=EventProposals   
        )

    @task
    def validate_event_content(self) -> Task:
        return Task(
            config=self.tasks_config["validate_event_content"],
            agent=self.event_validator(),
            output_json=EventProposals   
        )


    @crew
    def eventcrew(self) -> Crew:
        """Creates the event crew"""
        return Crew(
            agents=self.agents,
            tasks=self.tasks,
            process=Process.sequential,
            verbose=True,
            planning=False,
            max_rpm=3,
        )