File size: 34,327 Bytes
5fdb69e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d032fee4-7e37-43d5-974e-b6d29f0813e9",
   "metadata": {},
   "source": [
    "# Langchain + FAISS + Ollama\n",
    "\n",
    "This workbook demonstrate RAG with FAISS & ollama (local)\n",
    "\n",
    "**Notes:**\n",
    "1. Istall ollama: https://ollama.com/download\n",
    "2. Download ollama embed: `ollama pull nomic-embed-text`\n",
    "3. Download the model (eg. `ollama pull mistral-openorca`)\n",
    "4. `ollama serve`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "63c10e01-860b-43ce-b6aa-d8cbfa91f630",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import glob\n",
    "\n",
    "import gradio as gr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "afeec974-6332-46b3-adf9-a19110b92a50",
   "metadata": {},
   "outputs": [],
   "source": [
    "# imports for langchain\n",
    "\n",
    "from langchain.document_loaders import DirectoryLoader, TextLoader\n",
    "from langchain.text_splitter import CharacterTextSplitter\n",
    "from langchain.schema import Document\n",
    "\n",
    "from langchain.vectorstores import FAISS\n",
    "\n",
    "from langchain.memory import ConversationBufferMemory\n",
    "from langchain.chains import ConversationalRetrievalChain"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05d1dec0-2695-4057-817f-d3403ab88669",
   "metadata": {},
   "source": [
    "## Directory setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5a759958-8a8d-48f0-b34c-a435d97faad9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Read in documents using LangChain's loaders\n",
    "# Take everything in all the sub-folders of our knowledgebase\n",
    "\n",
    "folders = glob.glob(\"knowledge-base/*\")\n",
    "\n",
    "# With thanks to CG and Jon R, students on the course, for this fix needed for some users \n",
    "text_loader_kwargs = {'encoding': 'utf-8'}\n",
    "# If that doesn't work, some Windows users might need to uncomment the next line instead\n",
    "# text_loader_kwargs={'autodetect_encoding': True}\n",
    "\n",
    "documents = []\n",
    "for folder in folders:\n",
    "    doc_type = os.path.basename(folder)\n",
    "    loader = DirectoryLoader(folder, glob=\"**/*.md\", loader_cls=TextLoader, loader_kwargs=text_loader_kwargs)\n",
    "    folder_docs = loader.load()\n",
    "    for doc in folder_docs:\n",
    "        doc.metadata[\"doc_type\"] = doc_type\n",
    "        documents.append(doc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cc7ec6de-22bc-4f07-b41e-cce55bfceb29",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "31"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This step is to make sure setup above works\n",
    "len(documents)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "afe5b057-a99e-4566-8984-bb5ae5831de5",
   "metadata": {},
   "outputs": [],
   "source": [
    "text_splitter = CharacterTextSplitter(chunk_size=1300, chunk_overlap=200)\n",
    "chunks = text_splitter.split_documents(documents)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e14c7c99-628b-4a3a-ad0b-f2df20762db8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "91"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(chunks)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ddd22f41-6f0e-49ea-b5a5-5f8cde314aa9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Document types found: products, employees, company, contracts\n"
     ]
    }
   ],
   "source": [
    "doc_types = set(chunk.metadata['doc_type'] for chunk in chunks)\n",
    "print(f\"Document types found: {', '.join(doc_types)}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33f02751-9d75-459a-8039-d7e5bb962d9b",
   "metadata": {},
   "source": [
    "## Convert to vector database\n",
    "\n",
    "In this version, I use `nomic-embed-text' from ollama library: https://ollama.com/library/nomic-embed-text.\n",
    "Not sure if there are another embed model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1e2b354d-ff60-4de3-8ace-192da1501563",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_ollama import OllamaEmbeddings, ChatOllama\n",
    "\n",
    "db_name = \"knowledge_base_1\"\n",
    "embeddings = OllamaEmbeddings(model=\"nomic-embed-text\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "845e9f81-6a50-4088-a921-b68faff18976",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "There are 91 vectors with 768 dimensions in the vector store\n"
     ]
    }
   ],
   "source": [
    "# Create our FAISS vectorstore!\n",
    "\n",
    "vectorstore = FAISS.from_documents(chunks, embedding=embeddings)\n",
    "\n",
    "total_vectors = vectorstore.index.ntotal\n",
    "dimensions = vectorstore.index.d\n",
    "\n",
    "print(f\"There are {total_vectors} vectors with {dimensions:,} dimensions in the vector store\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50b5ae64-ca8c-470c-b546-591feebb0217",
   "metadata": {},
   "source": [
    "## Chat setup\n",
    "\n",
    "I add `callbacks=[StdOutCallbackHandler()]` parameter to see what exactly retriever passed to the model as Ed teach us."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e8cfeedd-496f-4e66-8682-aff4bf8d360e",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Studio10\\AppData\\Local\\Temp\\ipykernel_3188\\683569231.py:8: LangChainDeprecationWarning: Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/\n",
      "  memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)\n"
     ]
    }
   ],
   "source": [
    "# create a new Chat with Ollama\n",
    "from langchain_core.callbacks import StdOutCallbackHandler\n",
    "\n",
    "MODEL = \"mistral-openorca\"\n",
    "llm = ChatOllama(temperature=0.7, model=MODEL)\n",
    "\n",
    "# set up the conversation memory for the chat\n",
    "memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)\n",
    "\n",
    "# the retriever is an abstraction over the VectorStore that will be used during RAG\n",
    "retriever = vectorstore.as_retriever(search_kwargs={\"k\": 13})\n",
    "\n",
    "# putting it together: set up the conversation chain with the GPT 4o-mini LLM, the vector store and memory\n",
    "conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm, \n",
    "                                                           retriever=retriever, \n",
    "                                                           memory=memory, \n",
    "                                                           callbacks=[StdOutCallbackHandler()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4dc8f215-e076-4ae2-a7b7-6d663a358ae3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# run a quick test - should return a list of documents = 4\n",
    "question = \"Insurellm\"\n",
    "docs = vectorstore.similarity_search(question)\n",
    "len(docs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6328550f-5422-4e4f-a9d5-b9c4bca229d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Document(metadata={'source': 'knowledge-base\\\\company\\\\about.md', 'doc_type': 'company'}, page_content=\"# About Insurellm\\n\\nInsurellm was founded by Avery Lancaster in 2015 as an insurance tech startup designed to disrupt an industry in need of innovative products. It's first product was Markellm, the marketplace connecting consumers with insurance providers.\\nIt rapidly expanded, adding new products and clients, reaching 200 emmployees by 2024 with 12 offices across the US.\")"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "docs[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "772cca6a-fc02-47e3-bceb-9076a3eeac56",
   "metadata": {},
   "source": [
    "## Let's Chat!!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d7db3fae-6f17-46da-a098-65bb9467918e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new ConversationalRetrievalChain chain...\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mGiven the following conversation and a follow up question, rephrase the follow up question to be a standalone question, in its original language.\n",
      "\n",
      "Chat History:\n",
      "\n",
      "Human: tell me about Insurellm\n",
      "Assistant:  Insurellm is an innovative insurance company that specializes in providing personalized, tech-driven insurance solutions to individuals and businesses. They offer a wide range of insurance products and services, including life, health, property, and auto insurance. The company leverages the latest technology and data analytics to provide customers with tailored policies that meet their specific needs.\n",
      "\n",
      "Some key features and benefits of Insurellm include:\n",
      "\n",
      "1. Personalized Insurance Solutions: Insurellm uses advanced data analysis techniques to understand your unique risk profile and tailor insurance policies accordingly. This ensures that you receive the best possible coverage at competitive rates.\n",
      "\n",
      "2. Seamless Digital Experience: Insurellm offers a user-friendly online platform that allows customers to access their policy information, manage claims, and renew policies with ease. The platform is designed for a seamless digital experience, making it simple to navigate and use.\n",
      "\n",
      "3. Real-Time Quotes: With Insurellm's proprietary algorithms, users can receive real-time quotes for various insurance products based on their individual risk profile and preferences. This enables customers to make informed decisions when selecting policies that suit their needs and budget.\n",
      "\n",
      "4. Robust Risk Management Tools: The company provides a range of tools and resources to help individuals and businesses manage risks proactively, including loss prevention tips, risk assessments, and training programs.\n",
      "\n",
      "5. Dedicated Customer Support: Insurellm offers dedicated customer support teams available 24/7 to assist with any inquiries or concerns. Their professionals are well-trained and knowledgeable, ensuring that customers receive prompt and effective assistance.\n",
      "\n",
      "6. Claims Management: In case of an insured event, Insurellm's claims management team works efficiently to process the claim quickly, providing support and guidance throughout the entire process.\n",
      "\n",
      "7. Transparent Pricing: Insurellm is committed to transparent pricing, ensuring that customers are well-informed about their insurance coverage and costs. They offer various options for payment, including flexible monthly installments, making it easy for clients to manage their policies.\n",
      "\n",
      "In conclusion, Insurellm is a dynamic insurance company that offers personalized, tech-driven solutions to cater to the unique needs of individuals and businesses. Their commitment to innovation, customer satisfaction, and transparency makes them a valuable partner in managing risks and ensuring financial security.\n",
      "Follow Up Input: tell me about Insurellm\n",
      "Standalone question:\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new StuffDocumentsChain chain...\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mSystem: Use the following pieces of context to answer the user's question. \n",
      "If you don't know the answer, just say that you don't know, don't try to make up an answer.\n",
      "----------------\n",
      "# Overview of Insurellm\n",
      "\n",
      "Insurellm is an innovative insurance tech firm with 200 employees across the US.\n",
      "Insurellm offers 4 insurance software products:\n",
      "- Carllm, a portal for auto insurance companies\n",
      "- Homellm, a portal for home insurance companies\n",
      "- Rellm, an enterprise platform for the reinsurance sector\n",
      "- Marketllm, a marketplace for connecting consumers with insurance providers\n",
      "  \n",
      "Insurellm has more than 300 clients worldwide.\n",
      "\n",
      "# About Insurellm\n",
      "\n",
      "Insurellm was founded by Avery Lancaster in 2015 as an insurance tech startup designed to disrupt an industry in need of innovative products. It's first product was Markellm, the marketplace connecting consumers with insurance providers.\n",
      "It rapidly expanded, adding new products and clients, reaching 200 emmployees by 2024 with 12 offices across the US.\n",
      "\n",
      "---\n",
      "\n",
      "## Features\n",
      "\n",
      "1. **Access to Core Features**: Roadway Insurance Inc. will have access to all Professional Tier features, including:\n",
      "   - AI-Powered Risk Assessment\n",
      "   - Advanced Analytics & Fraud Detection\n",
      "   - Instant Quoting System\n",
      "   - Customizable Coverage Plans\n",
      "   - Customer Insights Dashboard\n",
      "   \n",
      "2. **Mobile Integration**: All features will be accessible through a mobile application that Insurellm will provide.\n",
      "3. **Customer Support**: Includes 24/7 automated customer support via AI chatbots and access to dedicated account management support during business hours.\n",
      "\n",
      "---\n",
      "\n",
      "## Support\n",
      "\n",
      "1. **Technical Support**: Roadway Insurance Inc. will receive priority technical support from Insurellm for any issues arising from the Carllm product.\n",
      "2. **Training**: Insurellm will provide up to 5 training sessions for Roadway Insurance Inc. staff on the effective use of the Carllm platform, scheduled at mutual convenience.\n",
      "3. **Updates and Maintenance**: Regular updates to the Carllm platform will be conducted quarterly, and any maintenance outages will be communicated at least 48 hours in advance.\n",
      "\n",
      "---\n",
      "\n",
      "## Support\n",
      "Insurellm provides Stellar Insurance Co. with the following support services:\n",
      "\n",
      "- **24/7 Technical Support**: Access to dedicated support representatives via phone and online chat.\n",
      "- **Quarterly Account Review**: Meetings to discuss performance metrics and uncover additional needs.\n",
      "- **Training Sessions**: Initial orientation and ongoing training opportunities to maximize the effectiveness of Rellm usage.\n",
      "- **Updates and Upgrades**: Regular software updates and enhancements are included as part of the subscription.\n",
      "\n",
      "Stellar Insurance Co. acknowledges receipt of the Rellm product summary and agrees to the terms set forth above. By signing below, both parties confirm their acceptance of this contract.\n",
      "\n",
      "**For Insurellm**  \n",
      "______________________________  \n",
      "[Signature]  \n",
      "[Name, Title]  \n",
      "[Date]  \n",
      "\n",
      "**For Stellar Insurance Co.**  \n",
      "______________________________  \n",
      "[Signature]  \n",
      "[Name, Title]  \n",
      "[Date]\n",
      "\n",
      "## Features\n",
      "1. **AI-Powered Matching**: Belvedere Insurance will benefit from Markellm's AI-powered matching, ensuring the best-fit customers are identified and connected.\n",
      "2. **Real-Time Quotes**: Access to real-time quotes will enhance the customer acquisition process, facilitating timely and informed decision-making.\n",
      "3. **Data Insights**: Client shall have access to Markellm's analytics dashboard, allowing insights into consumer behavior and market trends.\n",
      "4. **Customization Options**: Belvedere Insurance can leverage optional premium features and analytics upon payment of an additional $9.99/month.\n",
      "5. **Customer Support**: Insurellm will provide dedicated support to Belvedere Insurance, ensuring any issues or queries are promptly addressed.\n",
      "\n",
      "## Support\n",
      "1. **Technical Support**: Technical support will be available from 9 AM to 7 PM EST, Monday through Friday via email and phone.\n",
      "2. **Response Times**: Insurellm agrees to respond to all support queries within 24 business hours. Emergency support will be prioritized throughout the contract period.\n",
      "3. **Training**: Insurellm will offer a comprehensive training session for the Client’s staff upon beginning the service to ensure effective utilization of the features.\n",
      "\n",
      "## Pricing\n",
      "\n",
      "Insurellm offers flexible pricing plans for Rellm to cater to various business needs:\n",
      "\n",
      "- **Basic Plan**: $5,000/month\n",
      "  - Includes access to core features and standard integrations.\n",
      "  \n",
      "- **Professional Plan**: $10,000/month\n",
      "  - Includes all features, advanced integrations, and priority customer support.\n",
      "  \n",
      "- **Enterprise Plan**: Custom pricing\n",
      "  - Tailored solutions with personalized features, extensive integrations, and dedicated account management.\n",
      "\n",
      "Join the growing number of organizations leveraging Rellm to enhance their reinsurance processes while driving profitability and compliance. \n",
      "\n",
      "## 2025-2026 Roadmap\n",
      "\n",
      "At Insurellm, we are committed to the continuous improvement of Rellm. Our roadmap for 2025-2026 includes:\n",
      "\n",
      "- **Q3 2025**: \n",
      "  - Launch of the Rellm Mobile App for on-the-go insights and management.\n",
      "  - Introduction of augmented reality (AR) features for interactive risk assessments.\n",
      "\n",
      "- **Q1 2026**: \n",
      "  - Deployment of advanced machine learning models for even more accurate risk predictions.\n",
      "  - Expansion of integration capabilities to support emerging technologies in the insurance sector.\n",
      "\n",
      "# Product Summary\n",
      "\n",
      "# Homellm\n",
      "\n",
      "## Summary\n",
      "Homellm is an innovative home insurance product developed by Insurellm that leverages advanced AI technology to revolutionize the way insurance providers offer coverage to homeowners. Designed for both B2B and B2C segments, Homellm empowers insurers to provide personalized, data-driven policies, enhancing customer experience while minimizing risk and operational costs. By integrating seamlessly with existing systems, Homellm helps insurance companies streamline their processes and stay competitive in the ever-evolving insurance industry.\n",
      "\n",
      "## Features\n",
      "### 1. AI-Powered Risk Assessment\n",
      "Homellm utilizes sophisticated AI algorithms to analyze vast datasets, allowing insurance companies to assess risks accurately. This feature provides real-time insights for underwriting decisions, enabling insurers to tailor policies to individual customer needs.\n",
      "\n",
      "### 2. Dynamic Pricing Model\n",
      "With Homellm's innovative dynamic pricing model, insurance providers can offer flexible premiums based on real-time risk evaluations and historical data. This adaptability ensures that customers pay a fair price that accurately reflects their unique risk profile.\n",
      "\n",
      "## Features\n",
      "\n",
      "1. **Included Features**: Under the Professional Tier, TechDrive Insurance will have access to the following features of Carllm:\n",
      "   - AI-Powered Risk Assessment\n",
      "   - Instant Quoting\n",
      "   - Customizable Coverage Plans\n",
      "   - Fraud Detection\n",
      "   - Customer Insights Dashboard\n",
      "   - Mobile Integration\n",
      "   - Automated Customer Support\n",
      "\n",
      "2. **System Requirements**: TechDrive Insurance must ensure that their existing systems meet the technical requirements to integrate with Carllm, as outlined in the onboarding documentation provided by Insurellm.\n",
      "\n",
      "## Support\n",
      "\n",
      "1. **Customer Support**: Insurellm will provide 24/7 customer support to TechDrive Insurance via AI-driven chatbots, ensuring timely resolution of inquiries and issues.\n",
      "\n",
      "2. **Training**: TechDrive Insurance staff will receive onboarding training sessions to ensure effective utilization of the Carllm platform, scheduled within the first two weeks of contract commencement.\n",
      "\n",
      "3. **System Updates**: The Provider will push regular updates to improve system performance and add new features. TechDrive Insurance will receive prior notification of any significant upgrades that may affect current operations.\n",
      "\n",
      "---\n",
      "\n",
      "**Signatures:**\n",
      "\n",
      "**Insurellm Representative:**  \n",
      "Name: John Smith  \n",
      "Title: Account Manager  \n",
      "Date: ____________\n",
      "\n",
      "## Support\n",
      "1. **Technical Support**: Insurellm shall provide 24/7 technical support via an email and phone assistance for the duration of this Contract.\n",
      "2. **Training**: Insurellm will conduct an onsite training session for Client employees upon implementation, and quarterly training webinars will be made available thereafter.\n",
      "3. **Updates and Maintenance**: Insurellm will provide regular system updates and maintenance, ensuring that the software is operating at peak efficiency.\n",
      "\n",
      "By signing below, both parties agree to the terms set forth in this Contract for the use of the Homellm product.\n",
      "\n",
      "____  \n",
      "**Insurellm Authorized Signature**  \n",
      "Name: Sarah Johnson  \n",
      "Title: VP of Sales  \n",
      "Date: ____________\n",
      "\n",
      "____  \n",
      "**Pinnacle Insurance Co. Authorized Signature**  \n",
      "Name: Tom Anderson  \n",
      "Title: Chief Operating Officer  \n",
      "Date: ____________\n",
      "\n",
      "- **Predictive Maintenance Alerts**: The Customer will receive alerts regarding potential maintenance needs for insured properties, enhancing client satisfaction and reducing claims.\n",
      "\n",
      "- **Multi-Channel Integration**: Homellm will integrate with the Customer's existing platforms to create seamless service delivery.\n",
      "\n",
      "- **Customer Portal**: A dedicated portal will be provided, allowing the Customer's clients to manage their accounts 24/7.\n",
      "\n",
      "---\n",
      "\n",
      "## Support\n",
      "\n",
      "1. **Training**: Provider will offer a comprehensive training program at the start of the term to ensure the Customer's staff can effectively use the Homellm product.\n",
      "\n",
      "2. **Ongoing Support**: The Provider will supply ongoing technical support via email and phone during business hours (9 am - 5 pm EST) throughout the contract duration.\n",
      "\n",
      "3. **Updates and Improvements**: Customer will receive all software updates and feature enhancements as they become available, without additional charge.\n",
      "\n",
      "--- \n",
      "\n",
      "**AGREEMENT SIGNATURES**\n",
      "\n",
      "By signing below, the parties acknowledge their acceptance of the terms of this Agreement.\n",
      "\n",
      "**For Insurellm:**\n",
      "\n",
      "______________________________  \n",
      "[Name], [Title]  \n",
      "Date: ______________________\n",
      "\n",
      "**For Greenstone Insurance:**\n",
      "\n",
      "______________________________  \n",
      "[Name], [Title]  \n",
      "Date: ______________________\n",
      "\n",
      "---\n",
      "\n",
      "### Support\n",
      "1. **Dedicated Customer Support:**  \n",
      "   BrightWay Solutions will have access to a dedicated support team from Insurellm during standard business hours (9 AM - 7 PM EST).\n",
      "\n",
      "2. **Additional Support Services:**  \n",
      "   Technical support for integration and maintenance will be available. An optional premium support package can be purchased for $49.99/month, which includes 24/7 support and advanced troubleshooting.\n",
      "\n",
      "3. **Training and Onboarding:**  \n",
      "   Insurellm agrees to provide one free training session on how to utilize the Markellm platform effectively for BrightWay Solutions’ team upon contract signing.\n",
      "\n",
      "### Signatures\n",
      "By signing below, both parties agree to the terms and conditions outlined in this Contract.\n",
      "\n",
      "__________________________  \n",
      "**[Name], [Title]**  \n",
      "**Insurellm**  \n",
      "Date: ______________________\n",
      "\n",
      "__________________________  \n",
      "**[Name], [Title]**  \n",
      "**BrightWay Solutions**  \n",
      "Date: ______________________\n",
      "\n",
      "---\n",
      "\n",
      "This document serves as a formal agreement between Insurellm and BrightWay Solutions, ensuring a successful partnership focused on enhancing the insurance shopping experience for consumers.\n",
      "\n",
      "4. **Client Portal Access**: EverGuard Insurance will have access to both client and broker portals, enhancing communication and collaboration with its partners.\n",
      "\n",
      "## Support\n",
      "\n",
      "1. **Customer Support**: Insurellm will provide EverGuard Insurance with 24/7 customer support, including live chat, email, and phone assistance for any technical issues or inquiries regarding Rellm.\n",
      "\n",
      "2. **Training Services**: Insurellm will provide initial training for EverGuard Insurance staff to ensure proper utilization of Rellm features. Additional training sessions can be scheduled upon request at an agreed fee.\n",
      "\n",
      "3. **Updates and Upgrades**: EverGuard Insurance will receive all platform updates and upgrades at no additional cost during the contract term, including enhancements outlined in Insurellm’s 2025-2026 roadmap.\n",
      "\n",
      "4. **Feedback Mechanisms**: EverGuard Insurance is encouraged to provide feedback regarding Rellm’s functionalities and any desired features, which will be considered for future updates.\n",
      "\n",
      "---\n",
      "\n",
      "**Signatures**  \n",
      "**For Insurellm**: __________________________  \n",
      "**Name**: John Smith  \n",
      "**Title**: Chief Operating Officer  \n",
      "**Date**: _________________\n",
      "\n",
      "---\n",
      "\n",
      "## Support\n",
      "\n",
      "Insurellm commits to providing comprehensive support to GreenValley Insurance, which includes:\n",
      "\n",
      "1. **Onboarding:** An extensive training program for the GreenValley staff to ensure effective use of Homellm.\n",
      "   \n",
      "2. **Dedicated Support Team:** A dedicated support team available 24/7 to address any technical issues or inquiries.\n",
      "\n",
      "3. **Regular Updates:** Insurellm will offer ongoing updates and enhancements to the Homellm platform, including new features and security improvements.\n",
      "\n",
      "4. **Feedback Implementation:** Insurellm will actively solicit feedback from GreenValley Insurance to ensure Homellm continues to meet their evolving needs.\n",
      "\n",
      "---\n",
      "\n",
      "**Signatures:**\n",
      "\n",
      "_________________________________  \n",
      "**[Name]**  \n",
      "**Title**: CEO  \n",
      "**Insurellm, Inc.**\n",
      "\n",
      "_________________________________  \n",
      "**[Name]**  \n",
      "**Title**: COO  \n",
      "**GreenValley Insurance, LLC**  \n",
      "\n",
      "---\n",
      "\n",
      "This agreement represents the complete understanding of both parties regarding the use of the Homellm product and supersedes any prior agreements or communications.\n",
      "Human:  What services and features does Insurellm provide for personalized insurance solutions?\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "Answer:  Insurellm provides various services and features for personalized insurance solutions, which include:\n",
      "\n",
      "1. Customized Coverage: Insurellm offers tailored insurance policies based on individual needs and preferences. This means that customers can choose the coverage that best suits their requirements, ensuring they are not overpaying or underinsured.\n",
      "\n",
      "2. Digital Insurance Platform: The platform provides a user-friendly digital interface for customers to manage their policies, make claims, and access various insurance services. This simplifies the process and makes it more convenient for policyholders.\n",
      "\n",
      "3. Data-driven Analysis: Insurellm utilizes advanced data analytics and machine learning algorithms to analyze customer behavior, preferences, and risk factors to provide personalized insurance recommendations. This helps to improve the accuracy of coverage and pricing.\n",
      "\n",
      "4. Personalized Pricing: Insurellm uses various factors such as age, lifestyle, health, location, and more to determine the most suitable insurance plan at the best possible price for each customer.\n",
      "\n",
      "5. Policy Comparison: The platform allows customers to compare different insurance policies from multiple providers based on their specific needs. This helps them make an informed decision and choose the best plan that meets their requirements.\n",
      "\n",
      "6. Claims Management: Insurellm offers a streamlined claims management process, allowing policyholders to file claims, track progress, and receive updates through the digital platform.\n",
      "\n",
      "7. Risk Assessment and Prevention: The platform utilizes data analysis and predictive modeling to identify potential risks for customers. This helps in preventing losses by offering advice on risk-mitigation strategies and adjusting insurance coverage accordingly.\n",
      "\n",
      "8. Dynamic Coverage: Insurellm enables policyholders to adjust their coverage according to life events or changes in circumstances, ensuring that they are always protected as their needs evolve.\n",
      "\n",
      "9. Multi-policy Discounts: By offering multiple types of insurance policies under one platform, customers can benefit from discounts for bundling their coverages, making it more cost-effective.\n",
      "\n",
      "10. 24/7 Customer Support: Insurellm provides round-the-clock customer support to assist policyholders with any queries or concerns they may have related to their insurance policies.\n"
     ]
    }
   ],
   "source": [
    "# Chat test\n",
    "query = \"tell me about Insurellm\"\n",
    "result = conversation_chain.invoke({\"question\": query})\n",
    "answer = result[\"answer\"]\n",
    "print(\"\\nAnswer:\", answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "102a8222-f4a6-4c87-8cce-86a89adb19e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Clearing memory before new chat\n",
    "memory.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a2377cef-1ea6-4395-8147-db9c684fdb65",
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat_gradio(question, history):\n",
    "    result = conversation_chain.invoke({\"question\": question})\n",
    "    return result[\"answer\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "4c357dd8-252c-4dd5-85be-277d3ed53d79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "* Running on local URL:  http://127.0.0.1:7860\n",
      "\n",
      "To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Ui launch\n",
    "view = gr.ChatInterface(chat_gradio, type=\"messages\").launch(inbrowser=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebeff830-49f0-4bf6-a3b2-10ba038db1c0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}