Arafath10 commited on
Commit
3ba2dcf
·
verified ·
1 Parent(s): 45c9e46

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +54 -124
main.py CHANGED
@@ -8,88 +8,7 @@ import google.generativeai as genai
8
  secret = os.environ["key"]
9
 
10
  genai.configure(api_key=secret)
11
- model = genai.GenerativeModel('gemini-pro')
12
-
13
- GOOD_BOY_URL = (
14
- "https://images.unsplash.com/photo-1518717758536-85ae29035b6d?ixlib=rb-1.2.1"
15
- "&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80"
16
- )
17
-
18
- prompt = """Certainly! Below is a chat conversation template for your AI company, Nuron, specialized in developing AI and ML solutions and chatbot systems. The conversation includes typical customer inquiries and responses that can be used during business hours (9 AM to 5 PM, Monday to Friday).
19
-
20
- ---
21
-
22
- **Customer**: Hi, I'm interested in learning more about your AI and ML solutions. Can you tell me more?
23
-
24
- **Nuron Support**: Hello! Thank you for reaching out to Nuron. We specialize in developing cutting-edge AI and ML solutions tailored to meet your business needs. Our services include predictive analytics, natural language processing, computer vision, and custom chatbot systems. How can we assist you today?
25
-
26
- ---
27
-
28
- **Customer**: Who is behind Nuron?
29
-
30
- **Nuron Support**: Nuron was founded by Arafath, our CEO, who has extensive experience in AI and ML technologies. Under his leadership, we have delivered numerous successful projects across various industries.
31
-
32
- ---
33
-
34
- **Customer**: What are your working hours?
35
-
36
- **Nuron Support**: Our working hours are from 9 AM to 5 PM, Monday to Friday. During these hours, our team is available to assist you with any inquiries or support you might need.
37
-
38
- ---
39
-
40
- **Customer**: Can you develop a custom chatbot for my business?
41
-
42
- **Nuron Support**: Absolutely! We specialize in creating custom chatbot systems designed to enhance customer engagement and streamline business processes. Please provide us with some details about your requirements, and we'll be happy to discuss how we can help.
43
-
44
- ---
45
-
46
- **Customer**: How can I get in touch with Arafath?
47
-
48
- **Nuron Support**: You can reach out to Arafath by emailing our support team at [email protected], and we will ensure your message is forwarded to him. Alternatively, you can schedule a meeting through our website.
49
-
50
- ---
51
-
52
- **Customer**: What industries do you serve?
53
-
54
- **Nuron Support**: We have experience working with a diverse range of industries including healthcare, finance, retail, and manufacturing. Our AI and ML solutions are adaptable and can be customized to fit the unique needs of any sector.
55
-
56
- ---
57
-
58
- **Customer**: How do I get started with a project at Nuron?
59
-
60
- **Nuron Support**: To get started, simply contact us through our website or email us at [email protected] with a brief description of your project. We'll arrange a consultation to understand your requirements and provide you with a tailored proposal.
61
-
62
- ---
63
-
64
- **Customer**: What is the process for developing an AI solution with Nuron?
65
-
66
- **Nuron Support**: Our process typically involves the following steps:
67
- 1. Initial consultation to understand your needs.
68
- 2. Proposal and project planning.
69
- 3. Data collection and analysis.
70
- 4. Model development and training.
71
- 5. Implementation and integration.
72
- 6. Testing and validation.
73
- 7. Deployment and support.
74
-
75
- We ensure to keep you updated at each stage and incorporate your feedback to deliver the best solution.
76
-
77
- ---
78
-
79
- **Customer**: Can you provide support after the project is completed?
80
-
81
- **Nuron Support**: Yes, we offer comprehensive post-deployment support and maintenance services to ensure that your AI and ML solutions continue to perform optimally. Our team is always here to assist you with any updates or issues you may encounter.
82
-
83
- ---
84
-
85
- **Customer**: Thank you for the information!
86
-
87
- **Nuron Support**: You're welcome! If you have any more questions or need further assistance, feel free to contact us. Have a great day!
88
-
89
- ---
90
-
91
- use this details to give answer for my questio.only give system response only(not include customer message)
92
- question : """
93
 
94
  import user_guide_sync
95
 
@@ -112,6 +31,7 @@ async def update_user_guide_data():
112
  global query_engine,index
113
  index = user_guide_sync.update_user_guide()
114
  query_engine = index.as_query_engine()
 
115
 
116
  @app.post("/whatsapp")
117
  async def reply_whatsapp(request: Request):
@@ -121,52 +41,62 @@ async def reply_whatsapp(request: Request):
121
  message_body = form_data.get("Body")
122
  user_query = message_body
123
 
124
- gen_response = model.generate_content(str(prompt)+message_body)
125
-
126
  response = MessagingResponse()
127
-
128
-
129
  #msg.media(GOOD_BOY_URL)
130
- gpt_response = query_engine.query(f"""
131
- if you find the answer from provided data then give the realistic(like real human) answer with steps and add the more details link and propper line breaks(\n).
132
- if not find the answer from provided data then say 'please contact our helpdesk'
133
-
134
- user question : {user_query}""")
135
-
136
- default = """Dear\n\nIf you have a specific question or need assistance, please feel free to submit a ticket, and our support team will be happy to help you \n\nSubmit a Ticket: \n\tEmail: [email protected]\n\tHotline: 0114 226 999\nThank You """
137
-
138
- print(str(gpt_response).lower())
139
- if "please contact our helpdesk" in str(gpt_response).lower() or "please contact" in str(gpt_response).lower():
140
- print("help desk option")
141
-
142
- openai.api_key = os.environ["OPENAI_API_KEY"]
143
-
144
- messages = [
145
- {"role": "system", "content": "you are parallax technologies chatbot design for answer the user question like a real human"},
146
- {"role": "user", "content": user_query+". always give small and realistic response"}
147
- ]
148
 
149
- # gpt_response = openai.chat.completions.create(
150
-
151
- # model="gpt-3.5-turbo",
152
-
153
- # messages=messages,
154
-
155
- # temperature=0,
156
-
157
- # )
158
-
159
- # response.message(str(gpt_response.choices[0].message.content))
160
- response.message(str(default))
161
- return PlainTextResponse(str(response), media_type="application/xml")
 
 
 
 
 
 
 
 
162
 
163
- #result = ""
164
- #for lines in str(gpt_response).split("\n"):
165
- #result = result +"<p>"+lines+"</p><br>"
166
- response.message(str(gpt_response))
167
- #response.message("https://storemate.lk")
168
- return PlainTextResponse(str(response), media_type="application/xml")
169
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
 
172
  # Run the application (Make sure you have the necessary setup to run FastAPI)
 
8
  secret = os.environ["key"]
9
 
10
  genai.configure(api_key=secret)
11
+ model = genai.GenerativeModel('gemini-1.5-pro')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  import user_guide_sync
14
 
 
31
  global query_engine,index
32
  index = user_guide_sync.update_user_guide()
33
  query_engine = index.as_query_engine()
34
+ return "guide updated"
35
 
36
  @app.post("/whatsapp")
37
  async def reply_whatsapp(request: Request):
 
41
  message_body = form_data.get("Body")
42
  user_query = message_body
43
 
 
 
44
  response = MessagingResponse()
 
 
45
  #msg.media(GOOD_BOY_URL)
46
+ try:
47
+ gpt_response = query_engine.query(f"""
48
+ if you find the answer from provided data then give the realistic(like real human) answer with steps and add the more details link and propper line breaks(\n).
49
+ if not find the answer from provided data then say 'please contact our helpdesk'
50
+
51
+ user question : {user_query}""")
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
+ default = """Dear\n\nIf you have a specific question or need assistance, please feel free to submit a ticket, and our support team will be happy to help you \n\nSubmit a Ticket: \n\tEmail: support@storemate.lk\n\tHotline: 0114 226 999\nThank You """
54
+
55
+ print(str(gpt_response).lower())
56
+ if "please contact our helpdesk" in str(gpt_response).lower() or "please contact" in str(gpt_response).lower():
57
+ print("help desk option")
58
+
59
+ openai.api_key = os.environ["OPENAI_API_KEY"]
60
+
61
+ messages = [
62
+ {"role": "system", "content": "you are parallax technologies chatbot design for answer the user question like a real human"},
63
+ {"role": "user", "content": user_query+". always give small and realistic response"}
64
+ ]
65
+ prompt = f"""
66
+ system:
67
+ you are parallax technologies chatbot design for answer the user question like a real human for only greedings.
68
+ if user ask other questions say "i don't know"
69
+ only give single short & small answer
70
+
71
+ user:{user_query}
72
+ """
73
+ gen_response = model.generate_content(prompt)
74
 
75
+ # gpt_response = openai.chat.completions.create(
76
+
77
+ # model="gpt-3.5-turbo",
78
+
79
+ # messages=messages,
80
+
81
+ # temperature=0,
82
+
83
+ # )
84
+
85
+ # response.message(str(gpt_response.choices[0].message.content))
86
+ response.message(gen_response.text)
87
+ response.message(str(default))
88
+ return PlainTextResponse(str(response), media_type="application/xml")
89
+
90
+ #result = ""
91
+ #for lines in str(gpt_response).split("\n"):
92
+ #result = result +"<p>"+lines+"</p><br>"
93
+ response.message(str(gpt_response))
94
+ #response.message("https://storemate.lk")
95
+ return PlainTextResponse(str(response), media_type="application/xml")
96
+ except Exception as e:
97
+ print(str(e))
98
+ response.message("please ask again...!")
99
+ return PlainTextResponse(str(response), media_type="application/xml")
100
 
101
 
102
  # Run the application (Make sure you have the necessary setup to run FastAPI)