Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,14 +10,17 @@ from sklearn.naive_bayes import MultinomialNB
|
|
10 |
import asyncio
|
11 |
from crewai import Agent as CrewAgent, Task, Crew
|
12 |
import autogen
|
13 |
-
import
|
14 |
|
15 |
# Set up logging
|
16 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
17 |
logger = logging.getLogger(__name__)
|
18 |
|
19 |
-
#
|
20 |
-
|
|
|
|
|
|
|
21 |
|
22 |
# Initialize the client with the Mistral-7B-Instruct-v0.2 model
|
23 |
try:
|
@@ -92,13 +95,15 @@ def post_process_response(response):
|
|
92 |
return response
|
93 |
|
94 |
# CrewAI and AutoGen setup
|
|
|
|
|
95 |
communication_expert_crew = CrewAgent(
|
96 |
role='Communication Expert',
|
97 |
goal='Interpret and rephrase user queries with empathy and respect',
|
98 |
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.""",
|
99 |
verbose=True,
|
100 |
allow_delegation=False,
|
101 |
-
|
102 |
)
|
103 |
|
104 |
response_expert_crew = CrewAgent(
|
@@ -107,11 +112,11 @@ response_expert_crew = CrewAgent(
|
|
107 |
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.""",
|
108 |
verbose=True,
|
109 |
allow_delegation=False,
|
110 |
-
|
111 |
)
|
112 |
|
113 |
llm_config = {
|
114 |
-
"config_list": [{"model": "gpt-3.5-turbo"
|
115 |
}
|
116 |
|
117 |
communication_expert_autogen = autogen.AssistantAgent(
|
@@ -180,39 +185,4 @@ async def zerodha_support(message, history):
|
|
180 |
)
|
181 |
return response_expert_autogen.last_message()["content"]
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
if not check_response_content(response):
|
186 |
-
response += "\n\nPlease note that I cannot provide specific investment advice or guarantee returns. For personalized guidance, please consult with a qualified financial advisor."
|
187 |
-
|
188 |
-
if not check_confidence(response):
|
189 |
-
return "I apologize, but I'm not confident in providing an accurate answer to this query. For the most up-to-date and accurate information, please contact Zerodha's customer support directly."
|
190 |
-
|
191 |
-
final_response = post_process_response(response)
|
192 |
-
|
193 |
-
return final_response
|
194 |
-
except Exception as e:
|
195 |
-
logger.error(f"Error in zerodha_support: {e}")
|
196 |
-
return "I apologize, but an error occurred while processing your request. Please try again later."
|
197 |
-
|
198 |
-
# Gradio interface setup
|
199 |
-
demo = gr.ChatInterface(
|
200 |
-
zerodha_support,
|
201 |
-
chatbot=gr.Chatbot(height=600),
|
202 |
-
textbox=gr.Textbox(placeholder="Ask your question about Zerodha here...", container=False, scale=7),
|
203 |
-
title="Zerodha Support Assistant",
|
204 |
-
description="Ask questions about Zerodha's services, trading, account management, and more. Our multi-agent system ensures respectful and empathetic responses.",
|
205 |
-
theme="soft",
|
206 |
-
examples=[
|
207 |
-
"How do I open a Zerodha account?",
|
208 |
-
"I'm frustrated with the recent changes to the Kite platform. Can you help?",
|
209 |
-
"What are the risks involved in F&O trading?",
|
210 |
-
"I think there's an error in my account statement. What should I do?",
|
211 |
-
"Can you explain Zerodha's policy on intraday trading margins?",
|
212 |
-
"I'm new to investing. What resources does Zerodha offer for beginners?",
|
213 |
-
"How does Zerodha ensure the security of my investments and personal data?"
|
214 |
-
],
|
215 |
-
)
|
216 |
-
|
217 |
-
if __name__ == "__main__":
|
218 |
-
demo.launch()
|
|
|
10 |
import asyncio
|
11 |
from crewai import Agent as CrewAgent, Task, Crew
|
12 |
import autogen
|
13 |
+
from langchain_openai import ChatOpenAI
|
14 |
|
15 |
# Set up logging
|
16 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
17 |
logger = logging.getLogger(__name__)
|
18 |
|
19 |
+
# Check for OpenAI API key
|
20 |
+
if 'OPENAI_API_KEY' not in os.environ:
|
21 |
+
logger.error("OPENAI_API_KEY environment variable is not set.")
|
22 |
+
logger.info("Please set the OPENAI_API_KEY environment variable before running this script.")
|
23 |
+
sys.exit(1)
|
24 |
|
25 |
# Initialize the client with the Mistral-7B-Instruct-v0.2 model
|
26 |
try:
|
|
|
95 |
return response
|
96 |
|
97 |
# CrewAI and AutoGen setup
|
98 |
+
chat_model = ChatOpenAI(model="gpt-3.5-turbo")
|
99 |
+
|
100 |
communication_expert_crew = CrewAgent(
|
101 |
role='Communication Expert',
|
102 |
goal='Interpret and rephrase user queries with empathy and respect',
|
103 |
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.""",
|
104 |
verbose=True,
|
105 |
allow_delegation=False,
|
106 |
+
llm=chat_model
|
107 |
)
|
108 |
|
109 |
response_expert_crew = CrewAgent(
|
|
|
112 |
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.""",
|
113 |
verbose=True,
|
114 |
allow_delegation=False,
|
115 |
+
llm=chat_model
|
116 |
)
|
117 |
|
118 |
llm_config = {
|
119 |
+
"config_list": [{"model": "gpt-3.5-turbo"}]
|
120 |
}
|
121 |
|
122 |
communication_expert_autogen = autogen.AssistantAgent(
|
|
|
185 |
)
|
186 |
return response_expert_autogen.last_message()["content"]
|
187 |
|
188 |
+
res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|