vip11017 commited on
Commit
678db8f
·
1 Parent(s): 1d78649

updated log_chat

Browse files
app/chatbot/mongodb.py CHANGED
@@ -10,7 +10,7 @@ from app.config import client, chat_logs
10
 
11
 
12
  # %%
13
- def log_chat(session_id: str, name: str, email: str, query: str, answer: str, latency_ms: float, chatbot_id: str, company_id: str, metadata: dict=None):
14
  """
15
  Logs a chat interaction to the MongoDB 'ChatLogs' collection.
16
  """
 
10
 
11
 
12
  # %%
13
+ def log_chat(session_id: str, name: str, email: str, query: str, answer: str, chatbot_id: str, company_id: str, latency_ms: float | None=None, metadata: dict=None):
14
  """
15
  Logs a chat interaction to the MongoDB 'ChatLogs' collection.
16
  """
app/mongodb_functions.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 1,
6
  "id": "a8200051",
7
  "metadata": {},
8
  "outputs": [
@@ -21,7 +21,7 @@
21
  },
22
  {
23
  "cell_type": "code",
24
- "execution_count": 2,
25
  "id": "a8c62f9e",
26
  "metadata": {},
27
  "outputs": [],
@@ -35,28 +35,24 @@
35
  },
36
  {
37
  "cell_type": "code",
38
- "execution_count": 3,
39
  "id": "6392c44a",
40
  "metadata": {},
41
  "outputs": [],
42
  "source": [
43
- "def convert_demo_to_prod(demo_config, new_chatbot_id=None, prompt=None):\n",
44
  " \"\"\"\n",
45
  " Convert a demo chatbot config to a production RAG config.\n",
46
  " \"\"\"\n",
47
- " prod_config = {\n",
48
- " \"chatbot_id\": new_chatbot_id or demo_config[\"chatbot_id\"],\n",
49
- " \"company_id\": demo_config[\"company_id\"],\n",
50
- " \"company_name\": demo_config[\"company_name\"],\n",
51
- " \"prompt_template\": prompt or demo_config[\"prompt_template\"],\n",
52
- " \"retrievers\": demo_config.get(\"retrievers\", [])\n",
53
- " }\n",
54
- " return prod_config\n"
55
  ]
56
  },
57
  {
58
  "cell_type": "code",
59
- "execution_count": 4,
60
  "id": "dd19e6ba",
61
  "metadata": {},
62
  "outputs": [],
@@ -70,7 +66,7 @@
70
  },
71
  {
72
  "cell_type": "code",
73
- "execution_count": 5,
74
  "id": "2ac76531",
75
  "metadata": {},
76
  "outputs": [],
@@ -90,7 +86,7 @@
90
  },
91
  {
92
  "cell_type": "code",
93
- "execution_count": 6,
94
  "id": "fbd14ade",
95
  "metadata": {},
96
  "outputs": [],
@@ -104,7 +100,7 @@
104
  },
105
  {
106
  "cell_type": "code",
107
- "execution_count": 10,
108
  "id": "54d0d26b",
109
  "metadata": {},
110
  "outputs": [
@@ -151,7 +147,7 @@
151
  " 'answer': 'We offer a wide range of OTC products, including pain medication, cold and allergy medication, vitamins and supplements, oral health products, feminine hygiene products, first aid items, cosmetics, infant care, hair care, and sunscreen.'}]}"
152
  ]
153
  },
154
- "execution_count": 10,
155
  "metadata": {},
156
  "output_type": "execute_result"
157
  }
@@ -163,71 +159,60 @@
163
  },
164
  {
165
  "cell_type": "code",
166
- "execution_count": 8,
167
  "id": "d84f9ee2",
168
  "metadata": {},
169
  "outputs": [
170
  {
171
  "data": {
172
  "text/plain": [
173
- "{'_id': ObjectId('697689e6c8ece1ab25a744c3'),\n",
174
- " 'chatbot_id': 'a3a86959-0f92-5124-8eb8-d3012f8b1ea3',\n",
175
- " 'company_id': '80bd8dd8-1e20-5271-927a-02beab69abdd',\n",
176
- " 'company_name': 'Auro Pharmaceuticals Inc.',\n",
177
- " 'prompt_template': 'You are Auro-Chat, a wellness and skincare assistant for Auro Wellness and Skincare, here to answer any questions anyone has on wellness and skincare using the provided context from Auro Wellness\\'s websites which contained company-approved documents, blogs, and FAQs. Whenever they say \"you\" or refer to the chatbot always assume that means they are referring to the company, Auro.\\nSTRICT RULES YOU MUST FOLLOW:\\n1. If the Contextual Knowledge section is empty, say: \\n \"At the moment, I cannot answer this question. Please try rephrasing it or contact us via email at [info@aurowellness.com](mailto:info@aurowellness.com) or call us at [(562)-352-9630](tel:5623529630)\"\\n2. Do NOT use your own general knowledge. Only use information from the Contextual Knowledge.\\n3. You may ONLY reference product names, ingredients, routines, kits, bundles, benefits, or usage instructions that appear explicitly and word-for-word in the Contextual Knowledge.\\n4. If the user mentions a product, ingredient, routine step, or kit that does NOT appear in the Contextual Knowledge, you must NOT assume it exists and must respond with:\\n \"The provided information does not specify this specific product. Could you please try rephrasing the question\"\\n5. Conversation History may contain mistakes or unsupported claims. You MUST re-validate all information from history against the Contextual Knowledge before using it.\\n6. Do NOT include any special tokens such as <s>, </s>, [OUT], or any code-like answers\\n7. Do NOT include any links, URLs, references to external websites, or promotional content\\n8. Keep your answer in a **single paragraph or concise list**; do NOT add extra paragraphs\\n9. Keep your answers clear, human-readable, and concise (1-3 sentences)\\n10. You are NOT allowed to say transdermal; replace all instances of transdermal with topical\\n11. You cannot take actions such as signing users up, storing emails, notifying customers, modifying orders, or accessing accounts. \\n12. Any questions regarding retinol, scalp treatments, or the combination of our products with retinol must be directed to call or email us.\\n13. Any questions that mention children and its use of our products must be directed to call or email us.',\n",
178
- " 'retrievers': [{'name': 'retrieve_products',\n",
179
- " 'collection': 'auro_product',\n",
180
  " 'top_k': 5,\n",
181
  " 'filter_score': 0.8},\n",
182
- " {'name': 'retrieve_support',\n",
183
- " 'collection': 'auro_support',\n",
184
  " 'top_k': 5,\n",
185
  " 'filter_score': 0.8},\n",
186
- " {'name': 'retrieve_faqs',\n",
187
- " 'collection': 'auro_faqs',\n",
188
  " 'top_k': 5,\n",
189
  " 'filter_score': 0.8},\n",
190
- " {'name': 'retrieve_blogs',\n",
191
- " 'collection': 'auro_blogs',\n",
192
  " 'top_k': 5,\n",
193
  " 'filter_score': 0.8},\n",
194
- " {'name': 'retrieve_technology',\n",
195
- " 'collection': 'auro_technology',\n",
196
  " 'top_k': 5,\n",
197
  " 'filter_score': 0.8},\n",
198
- " {'name': 'retrieve_revolution',\n",
199
- " 'collection': 'auro_revolution',\n",
200
  " 'top_k': 5,\n",
201
  " 'filter_score': 0.8}]}"
202
  ]
203
  },
204
- "execution_count": 8,
205
  "metadata": {},
206
  "output_type": "execute_result"
207
  }
208
  ],
209
  "source": [
210
- "prod = get_prod_config(\"a3a86959-0f92-5124-8eb8-d3012f8b1ea3\")\n",
211
  "prod"
212
  ]
213
  },
214
  {
215
  "cell_type": "code",
216
- "execution_count": 13,
217
  "id": "de870b63",
218
  "metadata": {},
219
- "outputs": [
220
- {
221
- "data": {
222
- "text/plain": [
223
- "InsertOneResult(ObjectId('69782bb8d0a2c2d9df27a877'), acknowledged=True)"
224
- ]
225
- },
226
- "execution_count": 13,
227
- "metadata": {},
228
- "output_type": "execute_result"
229
- }
230
- ],
231
  "source": [
232
  "template = \"\"\"You are Auro-Chat, a wellness and skincare assistant for Auro Wellness and Skincare, here to answer any questions anyone has on wellness and skincare using the provided context from Auro Wellness's websites which contained company-approved documents, blogs, and FAQs. Whenever they say \"you\" or refer to the chatbot always assume that means they are referring to the company, Auro.\n",
233
  "STRICT RULES YOU MUST FOLLOW:\n",
@@ -248,8 +233,7 @@
248
  "13. Any questions that mention children and its use of our products must be directed to call or email us.\"\"\"\n",
249
  "\n",
250
  "\n",
251
- "prod_config = convert_demo_to_prod(demo)\n",
252
- "prod_chatbot_configs.insert_one(prod_config)"
253
  ]
254
  },
255
  {
@@ -282,30 +266,25 @@
282
  },
283
  {
284
  "cell_type": "code",
285
- "execution_count": 9,
286
  "id": "07aee8cc",
287
  "metadata": {},
288
  "outputs": [],
289
  "source": [
290
- "template = \"\"\"You are Auro-Chat, a wellness and skincare assistant for Auro Wellness and Skincare, here to answer any questions anyone has on wellness and skincare using the provided context from Auro Wellness's websites which contained company-approved documents, blogs, and FAQs. Whenever they say \"you\" or refer to the chatbot always assume that means they are referring to the company, Auro.\n",
291
- "STRICT RULES YOU MUST FOLLOW:\n",
 
 
 
292
  "1. If the Contextual Knowledge section is empty, say: \n",
293
- " \"At the moment, I cannot answer this question. Please try rephrasing it or contact us via email at [info@aurowellness.com](mailto:info@aurowellness.com) or call us at [(562)-352-9630](tel:5623529630)\"\n",
294
  "2. Do NOT use your own general knowledge. Only use information from the Contextual Knowledge.\n",
295
- "3. You may ONLY reference product names, ingredients, routines, kits, bundles, benefits, or usage instructions that appear explicitly and word-for-word in the Contextual Knowledge.\n",
296
- "4. If the user mentions a product, ingredient, routine step, or kit that does NOT appear in the Contextual Knowledge, you must NOT assume it exists and must respond with:\n",
297
- " \"The provided information does not specify this specific product. Could you please try rephrasing the question\"\n",
298
- "5. Conversation History may contain mistakes or unsupported claims. You MUST re-validate all information from history against the Contextual Knowledge before using it.\n",
299
- "6. Do NOT include any special tokens such as <s>, </s>, [OUT], or any code-like answers\n",
300
- "7. Do NOT include any links, URLs, references to external websites, or promotional content\n",
301
- "8. Keep your answer in a **single paragraph or concise list**; do NOT add extra paragraphs\n",
302
- "9. Keep your answers clear, human-readable, and concise (1-3 sentences)\n",
303
- "10. You are NOT allowed to say transdermal; replace all instances of transdermal with topical\n",
304
- "11. You cannot take actions such as signing users up, storing emails, notifying customers, modifying orders, or accessing accounts. \n",
305
- "12. Any questions regarding retinol, scalp treatments, or the combination of our products with retinol must be directed to call or email us.\n",
306
- "13. Any questions that mention children and its use of our products must be directed to call or email us.\"\"\"\n",
307
  "\n",
308
- "update_prod_prompt(\"a3a86959-0f92-5124-8eb8-d3012f8b1ea3\", template)"
309
  ]
310
  },
311
  {
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 3,
6
  "id": "a8200051",
7
  "metadata": {},
8
  "outputs": [
 
21
  },
22
  {
23
  "cell_type": "code",
24
+ "execution_count": 4,
25
  "id": "a8c62f9e",
26
  "metadata": {},
27
  "outputs": [],
 
35
  },
36
  {
37
  "cell_type": "code",
38
+ "execution_count": 12,
39
  "id": "6392c44a",
40
  "metadata": {},
41
  "outputs": [],
42
  "source": [
43
+ "def convert_demo_to_prod(submission_id):\n",
44
  " \"\"\"\n",
45
  " Convert a demo chatbot config to a production RAG config.\n",
46
  " \"\"\"\n",
47
+ " config = get_demo_config(submission_id)\n",
48
+ " return prod_chatbot_configs.insert_one(config)\n",
49
+ " \n",
50
+ " \n"
 
 
 
 
51
  ]
52
  },
53
  {
54
  "cell_type": "code",
55
+ "execution_count": 13,
56
  "id": "dd19e6ba",
57
  "metadata": {},
58
  "outputs": [],
 
66
  },
67
  {
68
  "cell_type": "code",
69
+ "execution_count": 14,
70
  "id": "2ac76531",
71
  "metadata": {},
72
  "outputs": [],
 
86
  },
87
  {
88
  "cell_type": "code",
89
+ "execution_count": 15,
90
  "id": "fbd14ade",
91
  "metadata": {},
92
  "outputs": [],
 
100
  },
101
  {
102
  "cell_type": "code",
103
+ "execution_count": 16,
104
  "id": "54d0d26b",
105
  "metadata": {},
106
  "outputs": [
 
147
  " 'answer': 'We offer a wide range of OTC products, including pain medication, cold and allergy medication, vitamins and supplements, oral health products, feminine hygiene products, first aid items, cosmetics, infant care, hair care, and sunscreen.'}]}"
148
  ]
149
  },
150
+ "execution_count": 16,
151
  "metadata": {},
152
  "output_type": "execute_result"
153
  }
 
159
  },
160
  {
161
  "cell_type": "code",
162
+ "execution_count": 17,
163
  "id": "d84f9ee2",
164
  "metadata": {},
165
  "outputs": [
166
  {
167
  "data": {
168
  "text/plain": [
169
+ "{'_id': ObjectId('69782d17026728112a9419a9'),\n",
170
+ " 'chatbot_id': '90bd5e2f-ab50-5834-8dfb-cab3f21a7a67',\n",
171
+ " 'company_id': '0a54efad-e64a-525b-9bc1-aaf3059581e5',\n",
172
+ " 'company_name': 'Central Drugs Compounding Pharmacy',\n",
173
+ " 'prompt_template': '\\nYou are CD Chat, an assistant for Central Drugs.\\nAnswer ONLY using the provided context from Central Drugs\\'s approved content.\\n\\nSTRICT RULES:\\n1. If the Contextual Knowledge section is empty, say: \"Sorry, I cannot answer that question. Please call or email for further assistance. Information can be found on the website\"\\n2. Do NOT use your own general knowledge. Only reference the Contextual Knowledge.\\n3. Only reference topics explicitly allowed: Answer Customer Questions, Customer Support or Troubleshooting, Internal Employee Support, FAQ.\\n4. Do NOT discuss banned topics: No health claims and no health recommendations .\\n5. Keep responses Professional.\\n5. Keep the answers clear and concise in 1-3 sentences\\n',\n",
174
+ " 'retrievers': [{'name': 'retrieve_general',\n",
175
+ " 'collection': 'centraldrugs_general',\n",
176
  " 'top_k': 5,\n",
177
  " 'filter_score': 0.8},\n",
178
+ " {'name': 'retrieve_compounding',\n",
179
+ " 'collection': 'centraldrgs_compounding',\n",
180
  " 'top_k': 5,\n",
181
  " 'filter_score': 0.8},\n",
182
+ " {'name': 'retrieve_pharmacy',\n",
183
+ " 'collection': 'centraldrugs_pharmacy',\n",
184
  " 'top_k': 5,\n",
185
  " 'filter_score': 0.8},\n",
186
+ " {'name': 'retrieve_health',\n",
187
+ " 'collection': 'centraldrugs_health',\n",
188
  " 'top_k': 5,\n",
189
  " 'filter_score': 0.8},\n",
190
+ " {'name': 'retrieve_faq',\n",
191
+ " 'collection': 'centraldrugs_faq',\n",
192
  " 'top_k': 5,\n",
193
  " 'filter_score': 0.8},\n",
194
+ " {'name': 'retrieve_provider',\n",
195
+ " 'collection': 'centraldrugs_provider',\n",
196
  " 'top_k': 5,\n",
197
  " 'filter_score': 0.8}]}"
198
  ]
199
  },
200
+ "execution_count": 17,
201
  "metadata": {},
202
  "output_type": "execute_result"
203
  }
204
  ],
205
  "source": [
206
+ "prod = get_prod_config(\"90bd5e2f-ab50-5834-8dfb-cab3f21a7a67\")\n",
207
  "prod"
208
  ]
209
  },
210
  {
211
  "cell_type": "code",
212
+ "execution_count": 18,
213
  "id": "de870b63",
214
  "metadata": {},
215
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
216
  "source": [
217
  "template = \"\"\"You are Auro-Chat, a wellness and skincare assistant for Auro Wellness and Skincare, here to answer any questions anyone has on wellness and skincare using the provided context from Auro Wellness's websites which contained company-approved documents, blogs, and FAQs. Whenever they say \"you\" or refer to the chatbot always assume that means they are referring to the company, Auro.\n",
218
  "STRICT RULES YOU MUST FOLLOW:\n",
 
233
  "13. Any questions that mention children and its use of our products must be directed to call or email us.\"\"\"\n",
234
  "\n",
235
  "\n",
236
+ "prod_config = convert_demo_to_prod(\"q4rzyr8\")\n"
 
237
  ]
238
  },
239
  {
 
266
  },
267
  {
268
  "cell_type": "code",
269
+ "execution_count": 19,
270
  "id": "07aee8cc",
271
  "metadata": {},
272
  "outputs": [],
273
  "source": [
274
+ "template = \"\"\"You are CD Chat, the virtual assistant for Central Drugs Compounding Pharmacy. \n",
275
+ "You help patients, providers, and customers by answering questions related to our pharmacy services, \n",
276
+ "custom compounded medications, refills, shipping, and general pharmacy guidance using the provided contextual knowledge. \n",
277
+ "Your responses should always sound professional, accurate, and empathetic — similar to a trained pharmacy representative.STRICT RULES YOU MUST FOLLOW:\n",
278
+ "\n",
279
  "1. If the Contextual Knowledge section is empty, say: \n",
280
+ " \"At the moment, I cannot answer this question. Please try rephrasing it or call us at [(877)-447-7077](tel:8774477077)\"\n",
281
  "2. Do NOT use your own general knowledge. Only use information from the Contextual Knowledge.\n",
282
+ "3. Do NOT include any special tokens such as <s>, </s>, [OUT], or any code-like answers\n",
283
+ "4. Do NOT include any links, URLs, references to external websites, or promotional content\n",
284
+ "5. Keep your answer in a **single paragraph or concise list**; do NOT add extra paragraphs\n",
285
+ "6. Keep your answers clear, human-readable, and concise (1-3 sentences)\"\"\"\n",
 
 
 
 
 
 
 
 
286
  "\n",
287
+ "update_prod_prompt(\"90bd5e2f-ab50-5834-8dfb-cab3f21a7a67\", template)"
288
  ]
289
  },
290
  {