invincible-jha commited on
Commit
200a2c2
·
verified ·
1 Parent(s): c4c6959

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -94,8 +94,7 @@ communication_expert_crew = Agent(
94
  goal='Interpret and rephrase user queries with empathy and respect',
95
  backstory="""You are an expert in communication, specializing in understanding and rephrasing queries to ensure they are interpreted in the most positive and constructive light. Your role is crucial in setting the tone for respectful and empathetic interactions.""",
96
  verbose=True,
97
- allow_delegation=False,
98
- tools=[generate_response]
99
  )
100
 
101
  response_expert_crew = Agent(
@@ -103,8 +102,32 @@ response_expert_crew = Agent(
103
  goal='Provide accurate, helpful, and emotionally intelligent responses to user queries',
104
  backstory="""You are an expert in Zerodha's services and policies, with a keen ability to provide comprehensive and empathetic responses. Your role is to ensure that all user queries are addressed accurately while maintaining a respectful and supportive tone.""",
105
  verbose=True,
106
- allow_delegation=False,
107
- tools=[generate_response]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  )
109
 
110
  # Main function
@@ -119,17 +142,12 @@ async def zerodha_support(message, history, username):
119
 
120
  # Use crewAI for initial query rephrasing
121
  try:
122
- rephrase_task = Task(
123
- description=f"Rephrase the following user query with empathy and respect: '{sanitized_message}'",
124
- agent=communication_expert_crew
125
- )
126
-
127
  crew = Crew(
128
  agents=[communication_expert_crew],
129
  tasks=[rephrase_task],
130
  verbose=2
131
  )
132
-
133
  rephrased_query = await crew.kickoff()
134
  except Exception as e:
135
  logger.error(f"Error in CrewAI rephrasing: {e}")
@@ -137,17 +155,12 @@ async def zerodha_support(message, history, username):
137
 
138
  # Generate response using Response Expert
139
  try:
140
- response_task = Task(
141
- description=f"Provide an accurate and helpful response to the user query: '{rephrased_query}'",
142
- agent=response_expert_crew
143
- )
144
-
145
  crew = Crew(
146
  agents=[response_expert_crew],
147
  tasks=[response_task],
148
  verbose=2
149
  )
150
-
151
  response = await crew.kickoff()
152
  except Exception as e:
153
  logger.error(f"Error in CrewAI response generation: {e}")
 
94
  goal='Interpret and rephrase user queries with empathy and respect',
95
  backstory="""You are an expert in communication, specializing in understanding and rephrasing queries to ensure they are interpreted in the most positive and constructive light. Your role is crucial in setting the tone for respectful and empathetic interactions.""",
96
  verbose=True,
97
+ allow_delegation=False
 
98
  )
99
 
100
  response_expert_crew = Agent(
 
102
  goal='Provide accurate, helpful, and emotionally intelligent responses to user queries',
103
  backstory="""You are an expert in Zerodha's services and policies, with a keen ability to provide comprehensive and empathetic responses. Your role is to ensure that all user queries are addressed accurately while maintaining a respectful and supportive tone.""",
104
  verbose=True,
105
+ allow_delegation=False
106
+ )
107
+
108
+ # Task definitions
109
+ rephrase_task = Task(
110
+ description="Rephrase the user query with empathy and respect",
111
+ agent=communication_expert_crew,
112
+ async_execution=True,
113
+ context=[
114
+ {
115
+ "role": "system",
116
+ "content": SHARED_CONTEXT
117
+ }
118
+ ]
119
+ )
120
+
121
+ response_task = Task(
122
+ description="Provide an accurate and helpful response to the user query",
123
+ agent=response_expert_crew,
124
+ async_execution=True,
125
+ context=[
126
+ {
127
+ "role": "system",
128
+ "content": SHARED_CONTEXT
129
+ }
130
+ ]
131
  )
132
 
133
  # Main function
 
142
 
143
  # Use crewAI for initial query rephrasing
144
  try:
145
+ rephrase_task.update_task(f"Rephrase the following user query with empathy and respect: '{sanitized_message}'")
 
 
 
 
146
  crew = Crew(
147
  agents=[communication_expert_crew],
148
  tasks=[rephrase_task],
149
  verbose=2
150
  )
 
151
  rephrased_query = await crew.kickoff()
152
  except Exception as e:
153
  logger.error(f"Error in CrewAI rephrasing: {e}")
 
155
 
156
  # Generate response using Response Expert
157
  try:
158
+ response_task.update_task(f"Provide an accurate and helpful response to the user query: '{rephrased_query}'")
 
 
 
 
159
  crew = Crew(
160
  agents=[response_expert_crew],
161
  tasks=[response_task],
162
  verbose=2
163
  )
 
164
  response = await crew.kickoff()
165
  except Exception as e:
166
  logger.error(f"Error in CrewAI response generation: {e}")