invincible-jha commited on
Commit
1389b27
·
verified ·
1 Parent(s): b8fe2a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -53,7 +53,35 @@ X = vectorizer.fit_transform(approved_topics)
53
  classifier = MultinomialNB()
54
  classifier.fit(X, np.arange(len(approved_topics)))
55
 
56
- # [Include the updated agent class definitions here]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  # Instantiate agents
59
  communication_expert = CommunicationExpertAgent()
 
53
  classifier = MultinomialNB()
54
  classifier.fit(X, np.arange(len(approved_topics)))
55
 
56
+ class CommunicationExpertAgent(Agent):
57
+ role: Literal["Communication Expert"] = "Communication Expert"
58
+ goal: Literal["To interpret and rephrase user queries with empathy and respect"] = "To interpret and rephrase user queries with empathy and respect"
59
+ backstory: Literal["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."] = \
60
+ "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."
61
+
62
+ async def run(self, query):
63
+ sanitized_query = re.sub(r'[<>&\']', '', query)
64
+ topic_relevance = classifier.predict(vectorizer.transform([sanitized_query]))[0] in range(len(approved_topics))
65
+ if not topic_relevance:
66
+ return "Query not relevant to our services."
67
+ emotional_context = "Identified emotional context"
68
+ rephrased_query = f"Rephrased with empathy: {sanitized_query} - {emotional_context}"
69
+ return rephrased_query
70
+
71
+ class ResponseExpertAgent(Agent):
72
+ role: Literal["Response Expert"] = "Response Expert"
73
+ goal: Literal["To provide accurate, helpful, and emotionally intelligent responses to user queries"] = "To provide accurate, helpful, and emotionally intelligent responses to user queries"
74
+ backstory: Literal["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."] = \
75
+ "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."
76
+
77
+ async def run(self, rephrased_query):
78
+ response = await hf_client.text_generation(rephrased_query, max_new_tokens=500, temperature=0.7)
79
+ return response['generated_text']
80
+
81
+ class PostprocessingAgent(Agent):
82
+ def run(self, response):
83
+ response += "\n\nThank you for contacting Zerodha. Is there anything else we can help with?"
84
+ return response
85
 
86
  # Instantiate agents
87
  communication_expert = CommunicationExpertAgent()