File size: 28,135 Bytes
b676995
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:32:27.617760Z",
     "start_time": "2024-10-29T18:32:26.626308Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_community.tools import ArxivQueryRun, WikipediaQueryRun\n",
    "from langchain_community.utilities import ArxivAPIWrapper, WikipediaAPIWrapper"
   ],
   "id": "a435d5aeb3924884",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:32:27.686190Z",
     "start_time": "2024-10-29T18:32:27.629994Z"
    }
   },
   "cell_type": "code",
   "source": [
    "wiki_api = WikipediaAPIWrapper(top_k_results=1, max_tokens=500 )\n",
    "wiki_api = WikipediaQueryRun(api_wrapper=wiki_api)\n",
    "wiki_api.name"
   ],
   "id": "b14caadf6783a38a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'wikipedia'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:32:27.894026Z",
     "start_time": "2024-10-29T18:32:27.850869Z"
    }
   },
   "cell_type": "code",
   "source": [
    "arxiv_api = ArxivAPIWrapper(top_k_results=1, max_tokens=500 )\n",
    "arxiv_api = ArxivQueryRun(api_wrapper=arxiv_api)\n",
    "arxiv_api.name"
   ],
   "id": "26841fb3cc762f14",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'arxiv'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:32:33.606669Z",
     "start_time": "2024-10-29T18:32:33.591504Z"
    }
   },
   "cell_type": "code",
   "source": "tools = [wiki_api, arxiv_api]",
   "id": "41a663232fd8c090",
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:33:57.464755Z",
     "start_time": "2024-10-29T18:33:57.442645Z"
    }
   },
   "cell_type": "code",
   "source": [
    "## Custom tool\n",
    "from langchain.document_loaders import WebBaseLoader\n",
    "from langchain.vectorstores import FAISS\n",
    "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
    "from langchain_groq import ChatGroq\n",
    "from langchain_huggingface import HuggingFaceEmbeddings\n",
    "from dotenv import load_dotenv\n",
    "load_dotenv()"
   ],
   "id": "ae3e6152572b015a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:34:05.220937Z",
     "start_time": "2024-10-29T18:33:59.455568Z"
    }
   },
   "cell_type": "code",
   "source": [
    "webloader = WebBaseLoader(\"https://jalammar.github.io/illustrated-transformer/\")\n",
    "docs = webloader.load()\n",
    "splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)\n",
    "document = splitter.split_documents(docs)\n",
    "vectorstore = FAISS.from_documents(document, HuggingFaceEmbeddings())\n",
    "retriever = vectorstore.as_retriever()"
   ],
   "id": "d0c2eabc73039a74",
   "outputs": [],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:33:24.573845Z",
     "start_time": "2024-10-29T18:33:24.556040Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain.tools.retriever import create_retriever_tool\n",
    "retriever_tool = create_retriever_tool(retriever, \"Transformer Study\", \"Search anything about Transformers\")"
   ],
   "id": "11679e0bd4ca5d42",
   "outputs": [],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:34:06.409793Z",
     "start_time": "2024-10-29T18:34:05.908259Z"
    }
   },
   "cell_type": "code",
   "source": [
    "tools = [wiki_api, arxiv_api, retriever_tool]\n",
    "model = ChatGroq(model=\"Gemma2-9B-It\")"
   ],
   "id": "cf0ab84b67702818",
   "outputs": [],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:38:51.485068Z",
     "start_time": "2024-10-29T18:38:50.500300Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain import hub\n",
    "prompt = hub.pull(\"hwchase17/openai-functions-agent\")\n",
    "prompt.messages"
   ],
   "id": "e831cdeb54d5f34",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], input_types={}, partial_variables={}, template='You are a helpful assistant'), additional_kwargs={}),\n",
       " MessagesPlaceholder(variable_name='chat_history', optional=True),\n",
       " HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['input'], input_types={}, partial_variables={}, template='{input}'), additional_kwargs={}),\n",
       " MessagesPlaceholder(variable_name='agent_scratchpad')]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T18:34:20.708077Z",
     "start_time": "2024-10-29T18:34:20.437439Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain.agents import create_openai_tools_agent\n",
    "agent = create_openai_tools_agent(model, tools, prompt)"
   ],
   "id": "53dd0b6d56abefde",
   "outputs": [],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T20:42:26.355456Z",
     "start_time": "2024-10-29T20:42:26.330918Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain.agents import AgentExecutor\n",
    "agent_exe = AgentExecutor(agent = agent,tools =  tools, verbose = True)\n",
    "agent_exe"
   ],
   "id": "cbbab60dac13e8d9",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AgentExecutor(verbose=True, agent=RunnableMultiActionAgent(runnable=RunnableAssign(mapper={\n",
       "  agent_scratchpad: RunnableLambda(lambda x: format_to_openai_tool_messages(x['intermediate_steps']))\n",
       "})\n",
       "| ChatPromptTemplate(input_variables=['agent_scratchpad', 'input'], optional_variables=['chat_history'], input_types={'chat_history': list[typing.Annotated[typing.Union[typing.Annotated[langchain_core.messages.ai.AIMessage, Tag(tag='ai')], typing.Annotated[langchain_core.messages.human.HumanMessage, Tag(tag='human')], typing.Annotated[langchain_core.messages.chat.ChatMessage, Tag(tag='chat')], typing.Annotated[langchain_core.messages.system.SystemMessage, Tag(tag='system')], typing.Annotated[langchain_core.messages.function.FunctionMessage, Tag(tag='function')], typing.Annotated[langchain_core.messages.tool.ToolMessage, Tag(tag='tool')], typing.Annotated[langchain_core.messages.ai.AIMessageChunk, Tag(tag='AIMessageChunk')], typing.Annotated[langchain_core.messages.human.HumanMessageChunk, Tag(tag='HumanMessageChunk')], typing.Annotated[langchain_core.messages.chat.ChatMessageChunk, Tag(tag='ChatMessageChunk')], typing.Annotated[langchain_core.messages.system.SystemMessageChunk, Tag(tag='SystemMessageChunk')], typing.Annotated[langchain_core.messages.function.FunctionMessageChunk, Tag(tag='FunctionMessageChunk')], typing.Annotated[langchain_core.messages.tool.ToolMessageChunk, Tag(tag='ToolMessageChunk')]], FieldInfo(annotation=NoneType, required=True, discriminator=Discriminator(discriminator=<function _get_type at 0x0000028AF9CFADE0>, custom_error_type=None, custom_error_message=None, custom_error_context=None))]], 'agent_scratchpad': list[typing.Annotated[typing.Union[typing.Annotated[langchain_core.messages.ai.AIMessage, Tag(tag='ai')], typing.Annotated[langchain_core.messages.human.HumanMessage, Tag(tag='human')], typing.Annotated[langchain_core.messages.chat.ChatMessage, Tag(tag='chat')], typing.Annotated[langchain_core.messages.system.SystemMessage, Tag(tag='system')], typing.Annotated[langchain_core.messages.function.FunctionMessage, Tag(tag='function')], typing.Annotated[langchain_core.messages.tool.ToolMessage, Tag(tag='tool')], typing.Annotated[langchain_core.messages.ai.AIMessageChunk, Tag(tag='AIMessageChunk')], typing.Annotated[langchain_core.messages.human.HumanMessageChunk, Tag(tag='HumanMessageChunk')], typing.Annotated[langchain_core.messages.chat.ChatMessageChunk, Tag(tag='ChatMessageChunk')], typing.Annotated[langchain_core.messages.system.SystemMessageChunk, Tag(tag='SystemMessageChunk')], typing.Annotated[langchain_core.messages.function.FunctionMessageChunk, Tag(tag='FunctionMessageChunk')], typing.Annotated[langchain_core.messages.tool.ToolMessageChunk, Tag(tag='ToolMessageChunk')]], FieldInfo(annotation=NoneType, required=True, discriminator=Discriminator(discriminator=<function _get_type at 0x0000028AF9CFADE0>, custom_error_type=None, custom_error_message=None, custom_error_context=None))]]}, partial_variables={'chat_history': []}, metadata={'lc_hub_owner': 'hwchase17', 'lc_hub_repo': 'openai-functions-agent', 'lc_hub_commit_hash': 'a1655024b06afbd95d17449f21316291e0726f13dcfaf990cc0d18087ad689a5'}, messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], input_types={}, partial_variables={}, template='You are a helpful assistant'), additional_kwargs={}), MessagesPlaceholder(variable_name='chat_history', optional=True), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['input'], input_types={}, partial_variables={}, template='{input}'), additional_kwargs={}), MessagesPlaceholder(variable_name='agent_scratchpad')])\n",
       "| RunnableBinding(bound=ChatGroq(client=<groq.resources.chat.completions.Completions object at 0x0000028AEF40AED0>, async_client=<groq.resources.chat.completions.AsyncCompletions object at 0x0000028AEF40A210>, model_name='Gemma2-9B-It', model_kwargs={}, groq_api_key=SecretStr('**********')), kwargs={'tools': [{'type': 'function', 'function': {'name': 'wikipedia', 'description': 'A wrapper around Wikipedia. Useful for when you need to answer general questions about people, places, companies, facts, historical events, or other subjects. Input should be a search query.', 'parameters': {'properties': {'query': {'description': 'query to look up on wikipedia', 'type': 'string'}}, 'required': ['query'], 'type': 'object'}}}, {'type': 'function', 'function': {'name': 'arxiv', 'description': 'A wrapper around Arxiv.org Useful for when you need to answer questions about Physics, Mathematics, Computer Science, Quantitative Biology, Quantitative Finance, Statistics, Electrical Engineering, and Economics from scientific articles on arxiv.org. Input should be a search query.', 'parameters': {'properties': {'query': {'description': 'search query to look up', 'type': 'string'}}, 'required': ['query'], 'type': 'object'}}}, {'type': 'function', 'function': {'name': 'Transformer Study', 'description': 'Search anything about Transformers', 'parameters': {'properties': {'query': {'description': 'query to look up in retriever', 'type': 'string'}}, 'required': ['query'], 'type': 'object'}}}]}, config={}, config_factories=[])\n",
       "| OpenAIToolsAgentOutputParser(), input_keys_arg=[], return_keys_arg=[], stream_runnable=True), tools=[WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper(wiki_client=<module 'wikipedia' from 'C:\\\\Users\\\\ruchi\\\\PycharmProjects\\\\genai_env\\\\Lib\\\\site-packages\\\\wikipedia\\\\__init__.py'>, top_k_results=1, lang='en', load_all_available_meta=False, doc_content_chars_max=4000)), ArxivQueryRun(api_wrapper=ArxivAPIWrapper(arxiv_search=<class 'arxiv.Search'>, arxiv_exceptions=(<class 'arxiv.ArxivError'>, <class 'arxiv.UnexpectedEmptyPageError'>, <class 'arxiv.HTTPError'>), top_k_results=1, ARXIV_MAX_QUERY_LENGTH=300, continue_on_failure=False, load_max_docs=100, load_all_available_meta=False, doc_content_chars_max=4000)), Tool(name='Transformer Study', description='Search anything about Transformers', args_schema=<class 'langchain_core.tools.retriever.RetrieverInput'>, func=functools.partial(<function _get_relevant_documents at 0x0000028AFA80CEA0>, retriever=VectorStoreRetriever(tags=['FAISS', 'HuggingFaceEmbeddings'], vectorstore=<langchain_community.vectorstores.faiss.FAISS object at 0x0000028AD2CDD580>, search_kwargs={}), document_prompt=PromptTemplate(input_variables=['page_content'], input_types={}, partial_variables={}, template='{page_content}'), document_separator='\\n\\n'), coroutine=functools.partial(<function _aget_relevant_documents at 0x0000028AFAB6AD40>, retriever=VectorStoreRetriever(tags=['FAISS', 'HuggingFaceEmbeddings'], vectorstore=<langchain_community.vectorstores.faiss.FAISS object at 0x0000028AD2CDD580>, search_kwargs={}), document_prompt=PromptTemplate(input_variables=['page_content'], input_types={}, partial_variables={}, template='{page_content}'), document_separator='\\n\\n'))])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 16
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T20:45:17.698060Z",
     "start_time": "2024-10-29T20:45:16.439652Z"
    }
   },
   "cell_type": "code",
   "source": "response = agent_exe.invoke({\"input\" : \"Tell me about transformer\"})",
   "id": "51163b1023b7f93f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
      "\u001B[32;1m\u001B[1;3m\n",
      "Invoking: `Transformer Study` with `{'query': 'transformer'}`\n",
      "\n",
      "\n",
      "\u001B[0m\u001B[38;5;200m\u001B[1;3mAcknowledgements\n",
      "Thanks to Illia Polosukhin, Jakob Uszkoreit, Llion Jones , Lukasz Kaiser, Niki Parmar, and Noam Shazeer for providing feedback on earlier versions of this post.\n",
      "Please hit me up on Twitter for any corrections or feedback.\n",
      "\n",
      "\n",
      "    Written on June 27, 2018\n",
      "  \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Subscribe to get notified about upcoming posts by email\n",
      "\n",
      "Email Address \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      " \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.\n",
      "\n",
      "\n",
      "Attribution example:\n",
      "\n",
      "Alammar, J (2018). The Illustrated Transformer [Blog post]. Retrieved from https://jalammar.github.io/illustrated-transformer/\n",
      "\n",
      "Note: If you translate any of the posts, let me know so I can link your translation to the original post. My email is in the about page.\n",
      "\n",
      "Go Forth And Transform\n",
      "I hope you’ve found this a useful place to start to break the ice with the major concepts of the Transformer. If you want to go deeper, I’d suggest these next steps:\n",
      "\n",
      "The Transformer was proposed in the paper Attention is All You Need. A TensorFlow implementation of it is available as a part of the Tensor2Tensor package. Harvard’s NLP group created a guide annotating the paper with PyTorch implementation. In this post, we will attempt to oversimplify things a bit and introduce the concepts one by one to hopefully make it easier to understand to people without in-depth knowledge of the subject matter.\n",
      "2020 Update: I’ve created a “Narrated Transformer” video which is a gentler approach to the topic:\n",
      "\n",
      "The Illustrated Transformer – Jay Alammar – Visualizing machine learning one concept at a time.\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Jay Alammar\n",
      "Visualizing machine learning one concept at a time.@JayAlammar on Twitter. YouTube Channel\n",
      "\n",
      "\n",
      "Blog\n",
      "About\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "The Illustrated Transformer\n",
      "\n",
      "Discussions:\n",
      "Hacker News (65 points, 4 comments), Reddit r/MachineLearning (29 points, 3 comments)\n",
      "\n",
      "\n",
      "Translations: Arabic, Chinese (Simplified) 1, Chinese (Simplified) 2, French 1, French 2, Italian, Japanese, Korean, Persian, Russian, Spanish 1, Spanish 2, Vietnamese\n",
      "\n",
      "Watch: MIT’s Deep Learning State of the Art lecture referencing this post\u001B[0m\u001B[32;1m\u001B[1;3mThe Illustrated Transformer is a blog post by Jay Alammar that visualizes and explains the concepts of the Transformer model. \n",
      "\n",
      "\n",
      "\u001B[0m\n",
      "\n",
      "\u001B[1m> Finished chain.\u001B[0m\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T20:45:26.188517Z",
     "start_time": "2024-10-29T20:45:26.180377Z"
    }
   },
   "cell_type": "code",
   "source": "response",
   "id": "c6013c6493022641",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'input': 'Tell me about transformer',\n",
       " 'output': 'The Illustrated Transformer is a blog post by Jay Alammar that visualizes and explains the concepts of the Transformer model. \\n\\n\\n'}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T20:47:43.485054Z",
     "start_time": "2024-10-29T20:47:40.665170Z"
    }
   },
   "cell_type": "code",
   "source": "response = agent_exe.invoke({\"input\" : \"Tell me about Suchitra Sen\"})",
   "id": "25f808c54136151c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
      "\u001B[32;1m\u001B[1;3m\n",
      "Invoking: `wikipedia` with `{'query': 'Suchitra Sen'}`\n",
      "\n",
      "\n",
      "\u001B[0m\u001B[36;1m\u001B[1;3mPage: Suchitra Sen\n",
      "Summary: Suchitra Sen (Bengali: [ʃuˈt͡ʃitːra ˈʃen] ; born Roma Dasgupta, Bengali: [ˈrɔma ˈdaʃɡupto] ; 6 April 1931 – 17 January 2014), widely known as the Mahanayika (lit. 'Great actress'), was an Indian actress who worked in Bengali and Hindi cinema. The movies in which she was paired opposite Uttam Kumar became classics in the history of Bengali cinema.\n",
      "Sen was the first Indian actress to receive an award at an international film festival when, at the 1963 Moscow International Film Festival, she won the Silver Prize for Best Actress for Saat Pake Bandha.  She was catapulted to stardom after she was cast as Vishnupriya by Devaki Kumar Bose in his Bhagaban Shree Krishna Chaitanya (1953).\n",
      "In 1972, she was awarded the Padma Shri, the fourth highest civilian award in India. From 1979 on, she retreated from public life and shunned all forms of public contact; for this she is often compared to Greta Garbo. In 2005, she refused the Dadasaheb Phalke Award, the highest cinematic award in India, to stay out of the public eye. In 2012, she was conferred the West Bengal Government's highest honour: Banga Bibhushan. Her first official release was Sukumar Dasgupta's Saat Number Kayedi (1953).\n",
      "\n",
      "\u001B[0m\u001B[32;1m\u001B[1;3mSuchitra Sen was a renowned Indian actress known for her work in Bengali and Hindi cinema.  She is often referred to as the \"Mahanayika\" (Great actress). \n",
      "\u001B[0m\n",
      "\n",
      "\u001B[1m> Finished chain.\u001B[0m\n"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T20:48:10.067023Z",
     "start_time": "2024-10-29T20:48:10.060333Z"
    }
   },
   "cell_type": "code",
   "source": "response",
   "id": "187d9800533a7307",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'input': 'Tell me about Suchitra Sen',\n",
       " 'output': 'Suchitra Sen was a renowned Indian actress known for her work in Bengali and Hindi cinema.  She is often referred to as the \"Mahanayika\" (Great actress). \\n'}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 22
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T20:49:16.523064Z",
     "start_time": "2024-10-29T20:49:13.246455Z"
    }
   },
   "cell_type": "code",
   "source": "response = agent_exe.invoke({\"input\" : \"Tell me about llama index ?\"})",
   "id": "a6bb37f59ca20c9b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
      "\u001B[32;1m\u001B[1;3m\n",
      "Invoking: `wikipedia` with `{'query': 'Llama Index'}`\n",
      "\n",
      "\n",
      "\u001B[0m\u001B[36;1m\u001B[1;3mPage: Vector database\n",
      "Summary: A vector database, vector store or vector search engine is a database that can store vectors (fixed-length lists of numbers) along with other data items. Vector databases typically implement one or more Approximate Nearest Neighbor algorithms, so that one can search the database with a query vector to retrieve the closest matching database records.\n",
      "Vectors are mathematical representations of data in a high-dimensional space. In this space, each dimension corresponds to a feature of the data, with the number of dimensions ranging from a few hundred to tens of thousands, depending on the complexity of the data being represented. A vector's position in this space represents its characteristics. Words, phrases, or entire documents, as well as images, audio, and other types of data, can all be vectorized.\n",
      "These feature vectors may be computed from the raw data using machine learning methods such as feature extraction algorithms, word embeddings or deep learning networks. The goal is that semantically similar data items receive feature vectors close to each other.\n",
      "Vector databases can be used for similarity search, semantic search, multi-modal search, recommendations engines, large language models (LLMs), object detection,  etc.\n",
      "Vector databases are also often used to implement retrieval-augmented generation (RAG), a method to improve domain-specific responses of large language models. The retrieval component of a RAG can be any search system, but is most often implemented as a vector database. Text documents describing the domain of interest are collected, and for each document or document section, a feature vector (known as an \"embedding\") is computed, typically using a deep learning network, and stored in a vector database. Given a user prompt, the feature vector of the prompt is computed, and the database is queried to retrieve the most relevant documents. These are then automatically added into the context window of the large language model, and the large language model proceeds to create a response to the prompt given this context.\u001B[0m\u001B[32;1m\u001B[1;3mLlama Index is an open-source framework that makes it easy to build applications powered by large language models (LLMs). \n",
      "\n",
      "It simplifies the process of connecting LLMs to your own data, allowing them to access and understand information specific to your needs.\n",
      "\n",
      "Think of Llama Index as a bridge between your data and powerful LLMs like those from OpenAI or Google. \n",
      "\n",
      "\n",
      "\n",
      "It's designed to make working with LLMs more practical and accessible, especially for tasks like:\n",
      "\n",
      "* **Question Answering:** Build systems that can answer questions based on your own documents or datasets.\n",
      "* **Summarization:**  Generate concise summaries of large amounts of text.\n",
      "* **Code Generation:**  Use LLMs to assist in writing and understanding code.\n",
      "* **Data Analysis:**  Leverage LLMs to uncover insights and patterns in your data.\n",
      "\n",
      "\n",
      "\n",
      "Llama Index achieves this by:\n",
      "\n",
      "* **Indexing your data:**  It transforms your data (text, code, PDFs, etc.) into a format that LLMs can understand.\n",
      "* **Providing efficient search:**  It allows you to quickly retrieve relevant information from your indexed data.\n",
      "* **Integrating with LLMs:**  It seamlessly connects your data to various LLMs, enabling powerful applications.\n",
      "\n",
      "\n",
      "\n",
      "Essentially, Llama Index empowers you to harness the capabilities of LLMs for a wide range of tasks while keeping your data secure and under your control.\n",
      "\u001B[0m\n",
      "\n",
      "\u001B[1m> Finished chain.\u001B[0m\n"
     ]
    }
   ],
   "execution_count": 23
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-29T20:49:23.177361Z",
     "start_time": "2024-10-29T20:49:23.170856Z"
    }
   },
   "cell_type": "code",
   "source": "response",
   "id": "eda4ef8e765d9781",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'input': 'Tell me about llama index ?',\n",
       " 'output': \"Llama Index is an open-source framework that makes it easy to build applications powered by large language models (LLMs). \\n\\nIt simplifies the process of connecting LLMs to your own data, allowing them to access and understand information specific to your needs.\\n\\nThink of Llama Index as a bridge between your data and powerful LLMs like those from OpenAI or Google. \\n\\n\\n\\nIt's designed to make working with LLMs more practical and accessible, especially for tasks like:\\n\\n* **Question Answering:** Build systems that can answer questions based on your own documents or datasets.\\n* **Summarization:**  Generate concise summaries of large amounts of text.\\n* **Code Generation:**  Use LLMs to assist in writing and understanding code.\\n* **Data Analysis:**  Leverage LLMs to uncover insights and patterns in your data.\\n\\n\\n\\nLlama Index achieves this by:\\n\\n* **Indexing your data:**  It transforms your data (text, code, PDFs, etc.) into a format that LLMs can understand.\\n* **Providing efficient search:**  It allows you to quickly retrieve relevant information from your indexed data.\\n* **Integrating with LLMs:**  It seamlessly connects your data to various LLMs, enabling powerful applications.\\n\\n\\n\\nEssentially, Llama Index empowers you to harness the capabilities of LLMs for a wide range of tasks while keeping your data secure and under your control.\\n\"}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 24
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "6619ae4fd40179df"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}