File size: 1,634 Bytes
a0c4684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, Body
from crewai import Crew, Process
from agents import SneakerAgents
from tasks import SneakerTasks
from tools.search_tools import SearchTools
from dotenv import load_dotenv
import os

# Load environment variables
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path)

# Initialize the SearchTools, SneakerAgents, and SneakerTasks once
search_tools = SearchTools()
agents = SneakerAgents(search_tools)
tasks = SneakerTasks()


class SneakerCrew:
    def __init__(self, brand, gender):
        self.brand = brand
        self.gender = gender

    def run(self):
        # Sequential initialization of agents
        sneaker_expert = agents.sneaker_expert()
        resale_expert = agents.resale_expert()

        # Sequential creation of tasks
        combined_task = tasks.suggest_and_fetch_upcoming_shoes(sneaker_expert, self.brand, self.gender)
        estimate_resale_value_task = tasks.estimate_resale_value(resale_expert, self.brand)

        # Initialize the crew sequentially
        crew = Crew(
            agents=[sneaker_expert, resale_expert],
            tasks=[combined_task, estimate_resale_value_task],
            verbose=True,
            process=Process.sequential
        )

        result = crew.kickoff()
        return result


app = FastAPI()


@app.post("/sneaker_worth_finder")
def sneaker_worth_finder(brand: str = Body(...), gender: str = Body(...)):
    sneaker_crew = SneakerCrew(brand, gender)
    result = sneaker_crew.run()
    return result


if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8002)