Spaces:
Sleeping
Sleeping
File size: 18,201 Bytes
b9b1114 678db8f b9b1114 678db8f b9b1114 678db8f b9b1114 678db8f b9b1114 678db8f b9b1114 678db8f 1d78649 678db8f b9b1114 678db8f b9b1114 678db8f b9b1114 52974f8 1d78649 52974f8 678db8f 52974f8 b9b1114 1d78649 b9b1114 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 b9b1114 678db8f b9b1114 678db8f b9b1114 678db8f b9b1114 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 678db8f 52974f8 b9b1114 1d78649 b9b1114 1d78649 b9b1114 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | {
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "a8200051",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pinged your deployment. You successfully connected to MongoDB!\n",
"Connected to MongoDB collection successfully!\n"
]
}
],
"source": [
"from config import demo_chatbot_configs, prod_chatbot_configs"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a8c62f9e",
"metadata": {},
"outputs": [],
"source": [
"def get_demo_config(submission_id):\n",
" return demo_chatbot_configs.find_one({\"submission_id\": submission_id})\n",
"\n",
"def get_prod_config(chatbot_id):\n",
" return prod_chatbot_configs.find_one({\"chatbot_id\": chatbot_id})"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "6392c44a",
"metadata": {},
"outputs": [],
"source": [
"def convert_demo_to_prod(submission_id):\n",
" \"\"\"\n",
" Convert a demo chatbot config to a production RAG config.\n",
" \"\"\"\n",
" config = get_demo_config(submission_id)\n",
" return prod_chatbot_configs.insert_one(config)\n",
" \n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "dd19e6ba",
"metadata": {},
"outputs": [],
"source": [
"def add_faq_demo(submission_id, faq):\n",
" demo_chatbot_configs.update_one(\n",
" {\"submission_id\": submission_id},\n",
" {\"$set\": {\"faqs\": faq}}\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "2ac76531",
"metadata": {},
"outputs": [],
"source": [
"def update_prod_prompt(chatbot_id, new_prompt):\n",
" prod_chatbot_configs.update_one(\n",
" {\"chatbot_id\": chatbot_id},\n",
" {\"$set\": {\"prompt_template\": new_prompt}}\n",
" )\n",
"\n",
"def update_prod_retrievers(chatbot_id, new_retrievers):\n",
" prod_chatbot_configs.update_one(\n",
" {\"chatbot_id\": chatbot_id},\n",
" {\"$set\": {\"retrievers\": new_retrievers}}\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "fbd14ade",
"metadata": {},
"outputs": [],
"source": [
"def override_demo_prompt(submission_id, new_prompt):\n",
" demo_chatbot_configs.update_one(\n",
" {\"submission_id\": submission_id},\n",
" {\"$set\": {\"prompt_template\": new_prompt}}\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "54d0d26b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'_id': ObjectId('697689a3c8ece1ab25a744c2'),\n",
" 'submission_id': 'q4rzyr8',\n",
" 'chatbot_id': '90bd5e2f-ab50-5834-8dfb-cab3f21a7a67',\n",
" 'company_id': '0a54efad-e64a-525b-9bc1-aaf3059581e5',\n",
" 'company_name': 'Central Drugs Compounding Pharmacy',\n",
" '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",
" 'retrievers': [{'name': 'retrieve_general',\n",
" 'collection': 'centraldrugs_general',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_compounding',\n",
" 'collection': 'centraldrgs_compounding',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_pharmacy',\n",
" 'collection': 'centraldrugs_pharmacy',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_health',\n",
" 'collection': 'centraldrugs_health',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_faq',\n",
" 'collection': 'centraldrugs_faq',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_provider',\n",
" 'collection': 'centraldrugs_provider',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8}],\n",
" 'faqs': [{'question': 'Where are you located?',\n",
" 'answer': 'We have 2 locations. Our La Habra Location is located at 520 W La Habra, CA 90631. Our Fullerton Location is located in 1955 Sunnycrest Dr Ste 100, Fullerton, CA 92835.'},\n",
" {'question': 'What shipping options are available?',\n",
" 'answer': 'We offer free shipping for 3+ compounded prescriptions. We use USPS as well as FedEx when requested and required.'},\n",
" {'question': 'Does the Pharmacy have automatic refills?',\n",
" 'answer': 'Yes, we have automatic refills on specific maintenance medications. If you would like to enlist in automatic refills, please contact one of our expert team members.'},\n",
" {'question': 'What OTC products do you offer',\n",
" '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.'}]}"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"demo = get_demo_config(\"q4rzyr8\")\n",
"demo"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "d84f9ee2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'_id': ObjectId('69782d17026728112a9419a9'),\n",
" 'chatbot_id': '90bd5e2f-ab50-5834-8dfb-cab3f21a7a67',\n",
" 'company_id': '0a54efad-e64a-525b-9bc1-aaf3059581e5',\n",
" 'company_name': 'Central Drugs Compounding Pharmacy',\n",
" '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",
" 'retrievers': [{'name': 'retrieve_general',\n",
" 'collection': 'centraldrugs_general',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_compounding',\n",
" 'collection': 'centraldrgs_compounding',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_pharmacy',\n",
" 'collection': 'centraldrugs_pharmacy',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_health',\n",
" 'collection': 'centraldrugs_health',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_faq',\n",
" 'collection': 'centraldrugs_faq',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8},\n",
" {'name': 'retrieve_provider',\n",
" 'collection': 'centraldrugs_provider',\n",
" 'top_k': 5,\n",
" 'filter_score': 0.8}]}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prod = get_prod_config(\"90bd5e2f-ab50-5834-8dfb-cab3f21a7a67\")\n",
"prod"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "de870b63",
"metadata": {},
"outputs": [],
"source": [
"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",
"STRICT RULES YOU MUST FOLLOW:\n",
"1. 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)\"\n",
"2. Do NOT use your own general knowledge. Only use information from the Contextual Knowledge.\n",
"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",
"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",
" \"The provided information does not specify this specific product. Could you please try rephrasing the question\"\n",
"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",
"6. Do NOT include any special tokens such as <s>, </s>, [OUT], or any code-like answers\n",
"7. Do NOT include any links, URLs, references to external websites, or promotional content\n",
"8. Keep your answer in a **single paragraph or concise list**; do NOT add extra paragraphs\n",
"9. Keep your answers clear, human-readable, and concise (1-3 sentences)\n",
"10. You are NOT allowed to say transdermal; replace all instances of transdermal with topical\n",
"11. You cannot take actions such as signing users up, storing emails, notifying customers, modifying orders, or accessing accounts. \n",
"12. Any questions regarding retinol, scalp treatments, or the combination of our products with retinol must be directed to call or email us.\n",
"13. Any questions that mention children and its use of our products must be directed to call or email us.\"\"\"\n",
"\n",
"\n",
"prod_config = convert_demo_to_prod(\"q4rzyr8\")\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "1332bd98",
"metadata": {},
"outputs": [],
"source": [
"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",
"STRICT RULES YOU MUST FOLLOW:\n",
"1. 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)\"\n",
"2. Do NOT use your own general knowledge. Only use information from the Contextual Knowledge.\n",
"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",
"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",
" \"The provided information does not specify this specific product. Could you please try rephrasing the question\"\n",
"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",
"6. Do NOT include any special tokens such as <s>, </s>, [OUT], or any code-like answers\n",
"7. Do NOT include any links, URLs, references to external websites, or promotional content\n",
"8. Keep your answer in a **single paragraph or concise list**; do NOT add extra paragraphs\n",
"9. Keep your answers clear, human-readable, and concise (1-3 sentences)\n",
"10. You are NOT allowed to say transdermal; replace all instances of transdermal with topical\n",
"11. You cannot take actions such as signing users up, storing emails, notifying customers, modifying orders, or accessing accounts. \n",
"12. Any questions regarding retinol, scalp treatments, or the combination of our products with retinol must be directed to call or email us.\n",
"13. Any questions that mention children and its use of our products must be directed to call or email us.\"\"\"\n",
"\n",
"override_demo_prompt(\"vGZzRy8\", template)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "07aee8cc",
"metadata": {},
"outputs": [],
"source": [
"template = \"\"\"You are CD Chat, the virtual assistant for Central Drugs Compounding Pharmacy. \n",
"You help patients, providers, and customers by answering questions related to our pharmacy services, \n",
"custom compounded medications, refills, shipping, and general pharmacy guidance using the provided contextual knowledge. \n",
"Your responses should always sound professional, accurate, and empathetic — similar to a trained pharmacy representative.STRICT RULES YOU MUST FOLLOW:\n",
"\n",
"1. If the Contextual Knowledge section is empty, say: \n",
" \"At the moment, I cannot answer this question. Please try rephrasing it or call us at [(877)-447-7077](tel:8774477077)\"\n",
"2. Do NOT use your own general knowledge. Only use information from the Contextual Knowledge.\n",
"3. Do NOT include any special tokens such as <s>, </s>, [OUT], or any code-like answers\n",
"4. Do NOT include any links, URLs, references to external websites, or promotional content\n",
"5. Keep your answer in a **single paragraph or concise list**; do NOT add extra paragraphs\n",
"6. Keep your answers clear, human-readable, and concise (1-3 sentences)\"\"\"\n",
"\n",
"update_prod_prompt(\"90bd5e2f-ab50-5834-8dfb-cab3f21a7a67\", template)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "891685c1",
"metadata": {},
"outputs": [],
"source": [
"\"retrievers\"= [\n",
" {\n",
" \"name\": \"retrieve_products\",\n",
" \"collection\": \"auro_product\",\n",
" \"top_k\": 5,\n",
" \"filter_score\": 0.8\n",
" },\n",
" {\n",
" \"name\": \"retrieve_support\",\n",
" \"collection\": \"auro_support\",\n",
" \"top_k\": 5,\n",
" \"filter_score\": 0.8\n",
" },\n",
" {\n",
" \"name\": \"retrieve_faqs\",\n",
" \"collection\": \"auro_faqs\",\n",
" \"top_k\": 5,\n",
" \"filter_score\": 0.8\n",
" },\n",
" {\n",
" \"name\": \"retrieve_blogs\",\n",
" \"collection\": \"auro_blogs\",\n",
" \"top_k\": 5,\n",
" \"filter_score\": 0.8\n",
" },\n",
" {\n",
" \"name\": \"retrieve_technology\",\n",
" \"collection\": \"auro_technology\",\n",
" \"top_k\": 5,\n",
" \"filter_score\": 0.8\n",
" },\n",
" {\n",
" \"name\": \"retrieve_revolution\",\n",
" \"collection\": \"auro_revolution\",\n",
" \"top_k\": 5,\n",
" \"filter_score\": 0.8\n",
" }\n",
" ]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3c975482",
"metadata": {},
"outputs": [],
"source": [
"faqs = [\n",
" {\n",
" \"question\": \"Where are you located?\",\n",
" \"answer\": \"We have 2 locations. Our La Habra Location is located at 520 W La Habra, CA 90631. Our Fullerton Location is located in 1955 Sunnycrest Dr Ste 100, Fullerton, CA 92835.\"\n",
" },\n",
" {\n",
" \"question\": \"What shipping options are available?\",\n",
" \"answer\": \"We offer free shipping for 3+ compounded prescriptions. We use USPS as well as FedEx when requested and required.\"\n",
" },\n",
" {\n",
" \"question\": \"Does the Pharmacy have automatic refills?\",\n",
" \"answer\": \"Yes, we have automatic refills on specific maintenance medications. If you would like to enlist in automatic refills, please contact one of our expert team members.\"\n",
" },\n",
" {'question': \"What OTC products do you offer\",\n",
" \"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.\"\n",
"\n",
" }\n",
"]\n",
"add_faq_demo(\"q4rzyr8\", faqs)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|