ysharma HF staff commited on
Commit
92d452d
β€’
1 Parent(s): 7428132

add more comments

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  from crewai import Agent, Task, Crew
3
  from crewai_tools import ScrapeWebsiteTool
@@ -7,6 +8,7 @@ import threading
7
  import asyncio
8
  from typing import List, Dict, Generator
9
 
 
10
  class SupportMessageQueue:
11
  def __init__(self):
12
  self.message_queue = queue.Queue()
@@ -22,6 +24,7 @@ class SupportMessageQueue:
22
  messages.append(self.message_queue.get())
23
  return messages
24
 
 
25
  class SupportCrew:
26
  def __init__(self, api_key: str = None):
27
  self.api_key = api_key
@@ -31,6 +34,7 @@ class SupportCrew:
31
  self.current_agent = None
32
  self.scrape_tool = None
33
 
 
34
  def initialize_agents(self, website_url: str):
35
  if not self.api_key:
36
  raise ValueError("OpenAI API key is required")
@@ -62,6 +66,7 @@ class SupportCrew:
62
  verbose=True
63
  )
64
 
 
65
  def create_tasks(self, inquiry: str) -> List[Task]:
66
  inquiry_resolution = Task(
67
  description=(
@@ -101,6 +106,7 @@ class SupportCrew:
101
 
102
  return [inquiry_resolution, quality_assurance_review]
103
 
 
104
  async def process_support(self, inquiry: str, website_url: str) -> Generator[List[Dict], None, None]:
105
  def add_agent_messages(agent_name: str, tasks: str, emoji: str = "πŸ€–"):
106
  self.message_queue.add_message({
@@ -115,6 +121,7 @@ class SupportCrew:
115
  "metadata": {"title": f"πŸ“‹ Task for {agent_name}"}
116
  })
117
 
 
118
  def setup_next_agent(current_agent: str) -> None:
119
  if current_agent == "Senior Support Representative":
120
  self.current_agent = "Support Quality Assurance Specialist"
 
1
+ # imports
2
  import gradio as gr
3
  from crewai import Agent, Task, Crew
4
  from crewai_tools import ScrapeWebsiteTool
 
8
  import asyncio
9
  from typing import List, Dict, Generator
10
 
11
+ # Message Queue System to manage flow of message
12
  class SupportMessageQueue:
13
  def __init__(self):
14
  self.message_queue = queue.Queue()
 
24
  messages.append(self.message_queue.get())
25
  return messages
26
 
27
+ # main class
28
  class SupportCrew:
29
  def __init__(self, api_key: str = None):
30
  self.api_key = api_key
 
34
  self.current_agent = None
35
  self.scrape_tool = None
36
 
37
+ # agent initialization with role, goal, and backstory
38
  def initialize_agents(self, website_url: str):
39
  if not self.api_key:
40
  raise ValueError("OpenAI API key is required")
 
66
  verbose=True
67
  )
68
 
69
+ # task creation with description and expected output format and tools
70
  def create_tasks(self, inquiry: str) -> List[Task]:
71
  inquiry_resolution = Task(
72
  description=(
 
106
 
107
  return [inquiry_resolution, quality_assurance_review]
108
 
109
+ # main processing function
110
  async def process_support(self, inquiry: str, website_url: str) -> Generator[List[Dict], None, None]:
111
  def add_agent_messages(agent_name: str, tasks: str, emoji: str = "πŸ€–"):
112
  self.message_queue.add_message({
 
121
  "metadata": {"title": f"πŸ“‹ Task for {agent_name}"}
122
  })
123
 
124
+ # Manages transition between agents
125
  def setup_next_agent(current_agent: str) -> None:
126
  if current_agent == "Senior Support Representative":
127
  self.current_agent = "Support Quality Assurance Specialist"