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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "25350da1",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stderr",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"You are using the default legacy behaviour of the <class 'transformers.models.t5.tokenization_t5.T5Tokenizer'>. If you see this, DO NOT PANIC! This is expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set `legacy=True`. This should only be set if you understand what it means, and thouroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565\n",
|
14 |
+
"C:\\Users\\SudheerRChinthala\\anaconda3\\Lib\\site-packages\\transformers\\utils\\generic.py:260: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.\n",
|
15 |
+
" torch.utils._pytree._register_pytree_node(\n",
|
16 |
+
"C:\\Users\\SudheerRChinthala\\anaconda3\\Lib\\site-packages\\transformers\\utils\\generic.py:260: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.\n",
|
17 |
+
" torch.utils._pytree._register_pytree_node(\n"
|
18 |
+
]
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"source": [
|
22 |
+
"import transformers\n",
|
23 |
+
"from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n",
|
24 |
+
"\n",
|
25 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"lmsys/fastchat-t5-3b-v1.0\")\n",
|
26 |
+
"\n",
|
27 |
+
"model = AutoModelForSeq2SeqLM.from_pretrained(\"lmsys/fastchat-t5-3b-v1.0\")"
|
28 |
+
]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"cell_type": "code",
|
32 |
+
"execution_count": 2,
|
33 |
+
"id": "d012cfa8",
|
34 |
+
"metadata": {},
|
35 |
+
"outputs": [],
|
36 |
+
"source": [
|
37 |
+
"from transformers import pipeline\n",
|
38 |
+
"from langchain.llms import HuggingFacePipeline\n",
|
39 |
+
"import torch\n",
|
40 |
+
"\n",
|
41 |
+
"pipe = pipeline(\n",
|
42 |
+
" \"text2text-generation\",\n",
|
43 |
+
" model=model, \n",
|
44 |
+
" tokenizer=tokenizer, \n",
|
45 |
+
" max_length=256\n",
|
46 |
+
")\n",
|
47 |
+
"\n",
|
48 |
+
"local_llm = HuggingFacePipeline(pipeline=pipe)"
|
49 |
+
]
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"cell_type": "code",
|
53 |
+
"execution_count": 3,
|
54 |
+
"id": "f0493f3f",
|
55 |
+
"metadata": {},
|
56 |
+
"outputs": [
|
57 |
+
{
|
58 |
+
"name": "stderr",
|
59 |
+
"output_type": "stream",
|
60 |
+
"text": [
|
61 |
+
"C:\\Users\\SudheerRChinthala\\anaconda3\\Lib\\site-packages\\langchain_core\\_api\\deprecation.py:117: LangChainDeprecationWarning: The function `__call__` was deprecated in LangChain 0.1.7 and will be removed in 0.2.0. Use invoke instead.\n",
|
62 |
+
" warn_deprecated(\n"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"name": "stdout",
|
67 |
+
"output_type": "stream",
|
68 |
+
"text": [
|
69 |
+
"<pad> hyderabad\n"
|
70 |
+
]
|
71 |
+
}
|
72 |
+
],
|
73 |
+
"source": [
|
74 |
+
"print(local_llm('What is the capital of Telangana?'))"
|
75 |
+
]
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"cell_type": "code",
|
79 |
+
"execution_count": 4,
|
80 |
+
"id": "71c47e16",
|
81 |
+
"metadata": {},
|
82 |
+
"outputs": [],
|
83 |
+
"source": [
|
84 |
+
"import os"
|
85 |
+
]
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"cell_type": "code",
|
89 |
+
"execution_count": 5,
|
90 |
+
"id": "3bc5dcfa",
|
91 |
+
"metadata": {},
|
92 |
+
"outputs": [],
|
93 |
+
"source": [
|
94 |
+
"from langchain.vectorstores import Chroma\n",
|
95 |
+
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
|
96 |
+
"\n",
|
97 |
+
"from langchain.chains import RetrievalQA\n",
|
98 |
+
"from langchain.document_loaders import TextLoader\n",
|
99 |
+
"from langchain.document_loaders import PyPDFLoader\n",
|
100 |
+
"from langchain.document_loaders import DirectoryLoader\n",
|
101 |
+
"\n",
|
102 |
+
"\n",
|
103 |
+
"from InstructorEmbedding import INSTRUCTOR\n",
|
104 |
+
"from langchain.embeddings import HuggingFaceInstructEmbeddings"
|
105 |
+
]
|
106 |
+
},
|
107 |
+
{
|
108 |
+
"cell_type": "code",
|
109 |
+
"execution_count": 17,
|
110 |
+
"id": "7d8598c8",
|
111 |
+
"metadata": {
|
112 |
+
"scrolled": true
|
113 |
+
},
|
114 |
+
"outputs": [
|
115 |
+
{
|
116 |
+
"name": "stdout",
|
117 |
+
"output_type": "stream",
|
118 |
+
"text": [
|
119 |
+
"Collecting SQLAlchemy==1.4.46\n",
|
120 |
+
" Using cached SQLAlchemy-1.4.46-cp311-cp311-win_amd64.whl (1.6 MB)\n",
|
121 |
+
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\sudheerrchinthala\\anaconda3\\lib\\site-packages (from SQLAlchemy==1.4.46) (2.0.1)\n",
|
122 |
+
"Installing collected packages: SQLAlchemy\n",
|
123 |
+
" Attempting uninstall: SQLAlchemy\n",
|
124 |
+
" Found existing installation: SQLAlchemy 2.0.25\n",
|
125 |
+
" Uninstalling SQLAlchemy-2.0.25:\n",
|
126 |
+
" Successfully uninstalled SQLAlchemy-2.0.25\n"
|
127 |
+
]
|
128 |
+
},
|
129 |
+
{
|
130 |
+
"name": "stderr",
|
131 |
+
"output_type": "stream",
|
132 |
+
"text": [
|
133 |
+
"ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: 'C:\\\\Users\\\\SudheerRChinthala\\\\anaconda3\\\\Lib\\\\site-packages\\\\~-lalchemy\\\\cyextension\\\\collections.cp311-win_amd64.pyd'\n",
|
134 |
+
"Consider using the `--user` option or check the permissions.\n",
|
135 |
+
"\n"
|
136 |
+
]
|
137 |
+
}
|
138 |
+
],
|
139 |
+
"source": [
|
140 |
+
"#!pip install SQLAlchemy==1.4.46"
|
141 |
+
]
|
142 |
+
},
|
143 |
+
{
|
144 |
+
"cell_type": "code",
|
145 |
+
"execution_count": 6,
|
146 |
+
"id": "4eaf8c4c",
|
147 |
+
"metadata": {},
|
148 |
+
"outputs": [],
|
149 |
+
"source": [
|
150 |
+
"# Load and process the text files\n",
|
151 |
+
"# loader = TextLoader('single_text_file.txt')\n",
|
152 |
+
"loader = DirectoryLoader('C:/Users/SudheerRChinthala/sivallm/new_papers', glob=\"./*.pdf\", loader_cls=PyPDFLoader)\n",
|
153 |
+
"\n",
|
154 |
+
"#documents = loader.load()"
|
155 |
+
]
|
156 |
+
},
|
157 |
+
{
|
158 |
+
"cell_type": "code",
|
159 |
+
"execution_count": 7,
|
160 |
+
"id": "f02c8c70",
|
161 |
+
"metadata": {},
|
162 |
+
"outputs": [],
|
163 |
+
"source": [
|
164 |
+
"documents = loader.load()"
|
165 |
+
]
|
166 |
+
},
|
167 |
+
{
|
168 |
+
"cell_type": "code",
|
169 |
+
"execution_count": 8,
|
170 |
+
"id": "483bc67a",
|
171 |
+
"metadata": {},
|
172 |
+
"outputs": [
|
173 |
+
{
|
174 |
+
"data": {
|
175 |
+
"text/plain": [
|
176 |
+
"25"
|
177 |
+
]
|
178 |
+
},
|
179 |
+
"execution_count": 8,
|
180 |
+
"metadata": {},
|
181 |
+
"output_type": "execute_result"
|
182 |
+
}
|
183 |
+
],
|
184 |
+
"source": [
|
185 |
+
"len(documents)"
|
186 |
+
]
|
187 |
+
},
|
188 |
+
{
|
189 |
+
"cell_type": "code",
|
190 |
+
"execution_count": 9,
|
191 |
+
"id": "11b461c5",
|
192 |
+
"metadata": {},
|
193 |
+
"outputs": [],
|
194 |
+
"source": [
|
195 |
+
"text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)\n",
|
196 |
+
"texts = text_splitter.split_documents(documents)"
|
197 |
+
]
|
198 |
+
},
|
199 |
+
{
|
200 |
+
"cell_type": "code",
|
201 |
+
"execution_count": 10,
|
202 |
+
"id": "7d3f6a0e",
|
203 |
+
"metadata": {},
|
204 |
+
"outputs": [
|
205 |
+
{
|
206 |
+
"data": {
|
207 |
+
"text/plain": [
|
208 |
+
"43"
|
209 |
+
]
|
210 |
+
},
|
211 |
+
"execution_count": 10,
|
212 |
+
"metadata": {},
|
213 |
+
"output_type": "execute_result"
|
214 |
+
}
|
215 |
+
],
|
216 |
+
"source": [
|
217 |
+
"len(texts)"
|
218 |
+
]
|
219 |
+
},
|
220 |
+
{
|
221 |
+
"cell_type": "code",
|
222 |
+
"execution_count": 11,
|
223 |
+
"id": "9bc9c5c2",
|
224 |
+
"metadata": {},
|
225 |
+
"outputs": [
|
226 |
+
{
|
227 |
+
"data": {
|
228 |
+
"text/plain": [
|
229 |
+
"Document(page_content='Release N otes for ICORE and INSTAR Release Dec 2023 Feature \\n3 \\n Purpose \\n \\nThe purpose of this document is to provide release notes for the ICORE and INSTAR portion of the Nov \\nand Dec 2023 release. \\n \\nDocument History \\nVersion Issue Date Author(s) Identification of Changes \\n .01', metadata={'source': 'C:\\\\Users\\\\SudheerRChinthala\\\\sivallm\\\\new_papers\\\\ICORE_INSTAR_Dec_2003_Release_Notes.pdf', 'page': 2})"
|
230 |
+
]
|
231 |
+
},
|
232 |
+
"execution_count": 11,
|
233 |
+
"metadata": {},
|
234 |
+
"output_type": "execute_result"
|
235 |
+
}
|
236 |
+
],
|
237 |
+
"source": [
|
238 |
+
"texts[3]"
|
239 |
+
]
|
240 |
+
},
|
241 |
+
{
|
242 |
+
"cell_type": "code",
|
243 |
+
"execution_count": 12,
|
244 |
+
"id": "f5c23330",
|
245 |
+
"metadata": {},
|
246 |
+
"outputs": [],
|
247 |
+
"source": [
|
248 |
+
"from langchain.embeddings import HuggingFaceInstructEmbeddings"
|
249 |
+
]
|
250 |
+
},
|
251 |
+
{
|
252 |
+
"cell_type": "code",
|
253 |
+
"execution_count": 13,
|
254 |
+
"id": "0ff3dd0f",
|
255 |
+
"metadata": {},
|
256 |
+
"outputs": [],
|
257 |
+
"source": [
|
258 |
+
"from langchain_community.embeddings import HuggingFaceInstructEmbeddings"
|
259 |
+
]
|
260 |
+
},
|
261 |
+
{
|
262 |
+
"cell_type": "code",
|
263 |
+
"execution_count": 5,
|
264 |
+
"id": "10e390aa",
|
265 |
+
"metadata": {},
|
266 |
+
"outputs": [
|
267 |
+
{
|
268 |
+
"name": "stdout",
|
269 |
+
"output_type": "stream",
|
270 |
+
"text": [
|
271 |
+
"Requirement already satisfied: InstructorEmbedding in c:\\users\\sudheerrchinthala\\anaconda3\\lib\\site-packages (1.0.1)\n"
|
272 |
+
]
|
273 |
+
}
|
274 |
+
],
|
275 |
+
"source": [
|
276 |
+
"!pip install InstructorEmbedding"
|
277 |
+
]
|
278 |
+
},
|
279 |
+
{
|
280 |
+
"cell_type": "code",
|
281 |
+
"execution_count": 14,
|
282 |
+
"id": "24977cc7",
|
283 |
+
"metadata": {
|
284 |
+
"scrolled": true
|
285 |
+
},
|
286 |
+
"outputs": [],
|
287 |
+
"source": [
|
288 |
+
"#from InstructorEmbedding import INSTRUCTOR\n",
|
289 |
+
"from langchain.embeddings import HuggingFaceInstructEmbeddings"
|
290 |
+
]
|
291 |
+
},
|
292 |
+
{
|
293 |
+
"cell_type": "code",
|
294 |
+
"execution_count": 16,
|
295 |
+
"id": "5762c0bb",
|
296 |
+
"metadata": {},
|
297 |
+
"outputs": [],
|
298 |
+
"source": [
|
299 |
+
"from langchain_community.vectorstores import Chroma"
|
300 |
+
]
|
301 |
+
},
|
302 |
+
{
|
303 |
+
"cell_type": "code",
|
304 |
+
"execution_count": 17,
|
305 |
+
"id": "bedd0a78",
|
306 |
+
"metadata": {},
|
307 |
+
"outputs": [
|
308 |
+
{
|
309 |
+
"name": "stdout",
|
310 |
+
"output_type": "stream",
|
311 |
+
"text": [
|
312 |
+
"load INSTRUCTOR_Transformer\n",
|
313 |
+
"max_seq_length 512\n"
|
314 |
+
]
|
315 |
+
}
|
316 |
+
],
|
317 |
+
"source": [
|
318 |
+
"instructor_embeddings = HuggingFaceInstructEmbeddings(model_name=\"hkunlp/instructor-base\") \n",
|
319 |
+
" "
|
320 |
+
]
|
321 |
+
},
|
322 |
+
{
|
323 |
+
"cell_type": "code",
|
324 |
+
"execution_count": 18,
|
325 |
+
"id": "3468b96f",
|
326 |
+
"metadata": {},
|
327 |
+
"outputs": [],
|
328 |
+
"source": [
|
329 |
+
"persist_directory = 'db'\n",
|
330 |
+
"## Here is the nmew embeddings being used\n",
|
331 |
+
"embedding = instructor_embeddings"
|
332 |
+
]
|
333 |
+
},
|
334 |
+
{
|
335 |
+
"cell_type": "code",
|
336 |
+
"execution_count": 19,
|
337 |
+
"id": "c5a25bea",
|
338 |
+
"metadata": {},
|
339 |
+
"outputs": [],
|
340 |
+
"source": [
|
341 |
+
"vectordb = Chroma.from_documents(documents=texts, \n",
|
342 |
+
" embedding=embedding,\n",
|
343 |
+
" persist_directory=persist_directory)"
|
344 |
+
]
|
345 |
+
},
|
346 |
+
{
|
347 |
+
"cell_type": "code",
|
348 |
+
"execution_count": 20,
|
349 |
+
"id": "76fa58a0",
|
350 |
+
"metadata": {},
|
351 |
+
"outputs": [],
|
352 |
+
"source": [
|
353 |
+
"retriever = vectordb.as_retriever(search_kwargs={\"k\": 3})"
|
354 |
+
]
|
355 |
+
},
|
356 |
+
{
|
357 |
+
"cell_type": "code",
|
358 |
+
"execution_count": 69,
|
359 |
+
"id": "8c07129e",
|
360 |
+
"metadata": {},
|
361 |
+
"outputs": [],
|
362 |
+
"source": [
|
363 |
+
"import textwrap\n",
|
364 |
+
"\n",
|
365 |
+
"def wrap_text_preserve_newlines(text, width=110):\n",
|
366 |
+
" # Split the input text into lines based on newline characters\n",
|
367 |
+
" lines = text.split('\\n')\n",
|
368 |
+
"\n",
|
369 |
+
" # Wrap each line individually\n",
|
370 |
+
" wrapped_lines = [textwrap.fill(line, width=width) for line in lines]\n",
|
371 |
+
"\n",
|
372 |
+
" # Join the wrapped lines back together using newline characters\n",
|
373 |
+
" wrapped_text = '\\n'.join(wrapped_lines)\n",
|
374 |
+
"\n",
|
375 |
+
" return wrapped_text\n",
|
376 |
+
"\n",
|
377 |
+
"def process_llm_response(llm_response):\n",
|
378 |
+
" print(wrap_text_preserve_newlines(llm_response['result']))\n",
|
379 |
+
" print('\\n\\nSources:')\n",
|
380 |
+
" for source in llm_response[\"source_documents\"]:\n",
|
381 |
+
" print(source.metadata['source'])"
|
382 |
+
]
|
383 |
+
},
|
384 |
+
{
|
385 |
+
"cell_type": "code",
|
386 |
+
"execution_count": 71,
|
387 |
+
"id": "8c434e49",
|
388 |
+
"metadata": {},
|
389 |
+
"outputs": [],
|
390 |
+
"source": [
|
391 |
+
"qa_chain = RetrievalQA.from_chain_type(llm=local_llm, \n",
|
392 |
+
" chain_type=\"stuff\", \n",
|
393 |
+
" retriever=retriever, \n",
|
394 |
+
" return_source_documents=True)"
|
395 |
+
]
|
396 |
+
},
|
397 |
+
{
|
398 |
+
"cell_type": "code",
|
399 |
+
"execution_count": 72,
|
400 |
+
"id": "de1319cb",
|
401 |
+
"metadata": {},
|
402 |
+
"outputs": [
|
403 |
+
{
|
404 |
+
"name": "stderr",
|
405 |
+
"output_type": "stream",
|
406 |
+
"text": [
|
407 |
+
"C:\\Users\\SudheerRChinthala\\anaconda3\\Lib\\site-packages\\langchain_core\\_api\\deprecation.py:117: LangChainDeprecationWarning: The function `__call__` was deprecated in LangChain 0.1.0 and will be removed in 0.2.0. Use invoke instead.\n",
|
408 |
+
" warn_deprecated(\n"
|
409 |
+
]
|
410 |
+
},
|
411 |
+
{
|
412 |
+
"name": "stdout",
|
413 |
+
"output_type": "stream",
|
414 |
+
"text": [
|
415 |
+
"<pad> No, Service Options are not ordered from USRP.\n",
|
416 |
+
"\n",
|
417 |
+
"\n",
|
418 |
+
"\n",
|
419 |
+
"Sources:\n",
|
420 |
+
"C:\\Users\\SudheerRChinthala\\sivallm\\new_papers\\ICORE_INSTAR_Release_Notes.pdf\n",
|
421 |
+
"C:\\Users\\SudheerRChinthala\\sivallm\\new_papers\\ICORE_INSTAR_Release_Notes.pdf\n",
|
422 |
+
"C:\\Users\\SudheerRChinthala\\sivallm\\new_papers\\ICORE_INSTAR_Release_Notes.pdf\n"
|
423 |
+
]
|
424 |
+
}
|
425 |
+
],
|
426 |
+
"source": [
|
427 |
+
"query = \"Are Service Options ordered from USRP\"\n",
|
428 |
+
"llm_response = qa_chain(query)\n",
|
429 |
+
"print(llm_response)\n",
|
430 |
+
"process_llm_response(llm_response)"
|
431 |
+
]
|
432 |
+
},
|
433 |
+
{
|
434 |
+
"cell_type": "code",
|
435 |
+
"execution_count": 73,
|
436 |
+
"id": "5e5f2f93",
|
437 |
+
"metadata": {},
|
438 |
+
"outputs": [],
|
439 |
+
"source": [
|
440 |
+
"vectordb.persist()\n",
|
441 |
+
"vectordb = None"
|
442 |
+
]
|
443 |
+
},
|
444 |
+
{
|
445 |
+
"cell_type": "code",
|
446 |
+
"execution_count": 74,
|
447 |
+
"id": "e649ed71",
|
448 |
+
"metadata": {},
|
449 |
+
"outputs": [],
|
450 |
+
"source": [
|
451 |
+
"vectordb = Chroma(persist_directory=persist_directory, \n",
|
452 |
+
" embedding_function=embedding)"
|
453 |
+
]
|
454 |
+
},
|
455 |
+
{
|
456 |
+
"cell_type": "code",
|
457 |
+
"execution_count": 75,
|
458 |
+
"id": "e729fbba",
|
459 |
+
"metadata": {},
|
460 |
+
"outputs": [],
|
461 |
+
"source": [
|
462 |
+
"retriever = vectordb.as_retriever()"
|
463 |
+
]
|
464 |
+
},
|
465 |
+
{
|
466 |
+
"cell_type": "code",
|
467 |
+
"execution_count": 76,
|
468 |
+
"id": "b9c687ea",
|
469 |
+
"metadata": {},
|
470 |
+
"outputs": [],
|
471 |
+
"source": [
|
472 |
+
"qa_chain = RetrievalQA.from_chain_type(llm=local_llm, \n",
|
473 |
+
" chain_type=\"stuff\", \n",
|
474 |
+
" retriever=retriever, \n",
|
475 |
+
" return_source_documents=True)"
|
476 |
+
]
|
477 |
+
},
|
478 |
+
{
|
479 |
+
"cell_type": "code",
|
480 |
+
"execution_count": 21,
|
481 |
+
"id": "8d40db5c",
|
482 |
+
"metadata": {
|
483 |
+
"scrolled": true
|
484 |
+
},
|
485 |
+
"outputs": [
|
486 |
+
{
|
487 |
+
"ename": "NameError",
|
488 |
+
"evalue": "name 'qa_chain' is not defined",
|
489 |
+
"output_type": "error",
|
490 |
+
"traceback": [
|
491 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
492 |
+
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
493 |
+
"Cell \u001b[1;32mIn[21], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m query \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCan you give me information about Shared, Port tagging No\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 2\u001b[0m llm_response \u001b[38;5;241m=\u001b[39m qa_chain(query)\n\u001b[0;32m 3\u001b[0m process_llm_response(llm_response)\n",
|
494 |
+
"\u001b[1;31mNameError\u001b[0m: name 'qa_chain' is not defined"
|
495 |
+
]
|
496 |
+
}
|
497 |
+
],
|
498 |
+
"source": [
|
499 |
+
"query = \"Can you give me information about Shared, Port tagging No\"\n",
|
500 |
+
"llm_response = qa_chain(query)\n",
|
501 |
+
"process_llm_response(llm_response)"
|
502 |
+
]
|
503 |
+
},
|
504 |
+
{
|
505 |
+
"cell_type": "code",
|
506 |
+
"execution_count": null,
|
507 |
+
"id": "3b31a07c",
|
508 |
+
"metadata": {},
|
509 |
+
"outputs": [],
|
510 |
+
"source": []
|
511 |
+
}
|
512 |
+
],
|
513 |
+
"metadata": {
|
514 |
+
"kernelspec": {
|
515 |
+
"display_name": "Python 3 (ipykernel)",
|
516 |
+
"language": "python",
|
517 |
+
"name": "python3"
|
518 |
+
},
|
519 |
+
"language_info": {
|
520 |
+
"codemirror_mode": {
|
521 |
+
"name": "ipython",
|
522 |
+
"version": 3
|
523 |
+
},
|
524 |
+
"file_extension": ".py",
|
525 |
+
"mimetype": "text/x-python",
|
526 |
+
"name": "python",
|
527 |
+
"nbconvert_exporter": "python",
|
528 |
+
"pygments_lexer": "ipython3",
|
529 |
+
"version": "3.11.5"
|
530 |
+
}
|
531 |
+
},
|
532 |
+
"nbformat": 4,
|
533 |
+
"nbformat_minor": 5
|
534 |
+
}
|