shashankkandimalla commited on
Commit
5d23558
·
1 Parent(s): a0c4684

Add application file

Browse files
Files changed (4) hide show
  1. Dockerfile +9 -0
  2. agents.py +60 -0
  3. tasks.py +48 -0
  4. tools/search_tools.py +37 -0
Dockerfile CHANGED
@@ -7,6 +7,15 @@ WORKDIR /code
7
  ## Copy the current directory contents in the container at /code
8
  COPY ./requirements.txt /code/requirements.txt
9
 
 
 
 
 
 
 
 
 
 
10
  ## Install the requirements.txt
11
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
 
 
7
  ## Copy the current directory contents in the container at /code
8
  COPY ./requirements.txt /code/requirements.txt
9
 
10
+ COPY ./agents.py /code/agents.py
11
+
12
+ COPY ./tasks.py /code/tasks.py
13
+
14
+ COPY ./tools/search_tools.py /code/tools/search_tools.py
15
+
16
+
17
+
18
+
19
  ## Install the requirements.txt
20
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
21
 
agents.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from crewai import Agent
3
+ from textwrap import dedent
4
+ from langchain_groq import ChatGroq
5
+ from tools.search_tools import SearchTools
6
+ from dotenv import load_dotenv
7
+
8
+ # Load environment variables
9
+ dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
10
+ load_dotenv(dotenv_path)
11
+
12
+ class SneakerAgents:
13
+ def __init__(self, search_tools):
14
+ groq_key = os.getenv("GROQ_API_KEY")
15
+ if not groq_key:
16
+ raise ValueError("GROQ_API_KEY environment variable is not set.")
17
+
18
+ self.LLaMA = ChatGroq(
19
+ model_name="llama3-8b-8192",
20
+ temperature=0.7,
21
+ groq_api_key=groq_key,
22
+ verbose=True
23
+ )
24
+ self.search_tools = search_tools
25
+
26
+ def sneaker_expert(self):
27
+ return Agent(
28
+ role="Sneaker Expert",
29
+ backstory=dedent(
30
+ """With a keen eye for hype and a pulse on the sneaker market, I've spent years navigating the world of reselling.
31
+ I'm well-versed in spotting potential grails, deciphering hype from bricks, and understanding what drives resale value.
32
+ From limited-edition drops to coveted collaborations, I can help you identify the next big thing and make informed decisions."""
33
+ ),
34
+ goal=dedent(
35
+ """I'm here to equip you with the knowledge to conquer the resell market.
36
+ Tell me about a specific sneaker, and I'll analyze its potential: current market price, estimated resale value,
37
+ factors influencing resell rating (hype, brand, scarcity), and any unique features that could impact its value."""
38
+ ),
39
+ tools=[self.search_tools.search_internet],
40
+ verbose=True,
41
+ llm=self.LLaMA
42
+ )
43
+
44
+ def resale_expert(self):
45
+ return Agent(
46
+ role="Resale Value Expert",
47
+ backstory=dedent(
48
+ """I'm a data-driven expert on the ever-fluctuating sneaker resale market.
49
+ I leverage market trends, historical data, and brand insights to predict a sneaker's potential resale value.
50
+ From analyzing hype levels to identifying deadstock opportunities, I can help you navigate the complexities of reselling."""
51
+ ),
52
+ goal=dedent(
53
+ """Let's talk about the resell potential of a specific sneaker.
54
+ I'll analyze market data, brand history, and hype levels to provide an estimated resale value and rating.
55
+ Additionally, I can help you identify potential risks like fufu (counterfeit) sneakers and suggest strategies to maximize your resale profit."""
56
+ ),
57
+ tools=[self.search_tools.search_internet],
58
+ verbose=True,
59
+ llm=self.LLaMA
60
+ )
tasks.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai import Task
2
+ from textwrap import dedent
3
+ from datetime import datetime, timedelta
4
+
5
+ class SneakerTasks:
6
+ def __init__(self):
7
+ self.tip_section = "If you do your BEST WORK, I'll give you a $10,000 commission!"
8
+
9
+ def suggest_and_fetch_upcoming_shoes(self, agent, brand, gender):
10
+ current_date = datetime.now().date()
11
+ suggestion_date = current_date + timedelta(days=30) # Suggesting shoes to be released within 30 days
12
+ release_date = current_date + timedelta(days=30) # Assuming upcoming releases within the next 30 days
13
+
14
+ return Task(
15
+ description=dedent(
16
+ f"""
17
+ **Task**: Suggest New Shoes and Fetch Upcoming Release Information
18
+ **Description**: Identify and suggest eupcoming {brand} {gender} sneaker releases from {current_date} to {suggestion_date},
19
+ and gather information about upcoming {brand} sneaker releases expected by {release_date}.
20
+
21
+ **Parameters**:
22
+ - Brand: {brand}
23
+ - Gender: {gender}
24
+
25
+ **Note**: {self.tip_section}
26
+ """
27
+ ),
28
+ agent=agent,
29
+ expected_output=f"List of upcoming releases for {brand} {gender} sneakers within the next {suggestion_date} days , with insights on potential hot sellers and the current hype surrounding them.."
30
+ )
31
+
32
+ def estimate_resale_value(self, agent, brand):
33
+ return Task(
34
+ description=dedent(
35
+ f"""
36
+ **Task**: Estimate Sneaker Resale Value
37
+ **Description**: Analyze and estimate the resale value of {brand} sneakers based on market trends,
38
+ historical data, and anticipated demand.
39
+
40
+ **Parameters**:
41
+ - Brand: {brand}
42
+
43
+ **Note**: {self.tip_section}
44
+ """
45
+ ),
46
+ agent=agent,
47
+ expected_output=f"Estimated resale value for {brand} sneakers,along with a breakdown of the factors affecting their value, such as brand popularity, rarity, and current market trends."
48
+ )
tools/search_tools.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ import requests
5
+ from langchain.tools import tool
6
+
7
+
8
+ class SearchTools():
9
+
10
+ @tool("Search the internet")
11
+ def search_internet(query):
12
+ """Useful to search the internet
13
+ about a a given topic and return relevant results"""
14
+ top_result_to_return = 10
15
+ url = "https://google.serper.dev/search"
16
+ payload = json.dumps({"q": query})
17
+ headers = {
18
+ 'X-API-KEY': os.environ['SERPER_API_KEY'],
19
+ 'content-type': 'application/json'
20
+ }
21
+ response = requests.request("POST", url, headers=headers, data=payload)
22
+ # check if there is an organic key
23
+ if 'organic' not in response.json():
24
+ return "Sorry, I couldn't find anything about that, there could be an error with you serper api key."
25
+ else:
26
+ results = response.json()['organic']
27
+ string = []
28
+ for result in results[:top_result_to_return]:
29
+ try:
30
+ string.append('\n'.join([
31
+ f"Title: {result['title']}", f"Link: {result['link']}",
32
+ f"Snippet: {result['snippet']}", "\n-----------------"
33
+ ]))
34
+ except KeyError:
35
+ next
36
+
37
+ return '\n'.join(string)