Skip to content

Commit

Permalink
remove redundant codes for llamaindex agent (#2298)
Browse files Browse the repository at this point in the history
  • Loading branch information
openvino-dev-samples authored Aug 16, 2024
1 parent 7626a9a commit cb99c7b
Showing 1 changed file with 47 additions and 70 deletions.
117 changes: 47 additions & 70 deletions notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "86fdc4ba-74c4-4869-898e-131f47827e8f",
"metadata": {
"test_replace": {
Expand Down Expand Up @@ -209,15 +209,22 @@
"id": "bca3764d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[31m[ERROR] 21:03:13.366 [NPUBackends] Cannot find backend for inference. Make sure the device is available.\u001b[0m\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "87d85d17bd4f49228648d945ac9db175",
"model_id": "e57e8e0dfabf40248642faafab390490",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Dropdown(description='Device:', options=('CPU', 'AUTO'), value='CPU')"
"Dropdown(description='Device:', options=('CPU', 'GPU', 'AUTO'), value='CPU')"
]
},
"execution_count": 4,
Expand Down Expand Up @@ -254,16 +261,15 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 13,
"id": "3c259c61-5eef-41a8-a9f7-462f27d0c7d4",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Compiling the model to CPU ...\n",
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
"Compiling the model to GPU ...\n"
]
}
],
Expand All @@ -272,18 +278,14 @@
"\n",
"ov_config = {\"PERFORMANCE_HINT\": \"LATENCY\", \"NUM_STREAMS\": \"1\", \"CACHE_DIR\": \"\"}\n",
"\n",
"\n",
"def completion_to_prompt(completion):\n",
" return f\"<|begin_of_text|><|start_header_id|>system<|end_header_id|><|eot_id|><|start_header_id|>user<|end_header_id|>{completion}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\"\n",
"\n",
"\n",
"llm = OpenVINOLLM(\n",
" model_id_or_path=str(llm_model_path),\n",
" context_window=3900,\n",
" max_new_tokens=1000,\n",
" model_kwargs={\"ov_config\": ov_config},\n",
" generate_kwargs={\"pad_token_id\": 128001, \"do_sample\": False, \"temperature\": None, \"top_p\": None},\n",
" device_map=llm_device.value,\n",
" completion_to_prompt=completion_to_prompt,\n",
" stopping_ids=[128001],\n",
")"
]
},
Expand All @@ -302,22 +304,22 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 14,
"id": "6e41705e",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8d3127cedece41f79a2fcdcdae21eb5d",
"model_id": "280fb93f3b8d4697b56292ac7262c24d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Dropdown(description='Device:', options=('CPU', 'AUTO'), value='CPU')"
"Dropdown(description='Device:', options=('CPU', 'GPU', 'AUTO'), value='CPU')"
]
},
"execution_count": 7,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -346,7 +348,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 19,
"id": "d3448c9f",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -379,7 +381,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 20,
"id": "f594cf18-8100-4207-9ec0-7ded996e85e3",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -417,7 +419,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 21,
"id": "eea245b9-73c5-431e-af47-3e676888bd5f",
"metadata": {},
"outputs": [],
Expand All @@ -444,7 +446,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 22,
"id": "9b8cd9c9-a595-4baf-9adc-77f740f19f1f",
"metadata": {},
"outputs": [],
Expand All @@ -453,7 +455,7 @@
"\n",
"rag_tool = QueryEngineTool.from_defaults(\n",
" query_engine,\n",
" name=\"Xeon6\",\n",
" name=\"vector_search\",\n",
" description=\"A RAG engine with some basic facts about Intel Xeon 6 processors with E-cores\",\n",
")"
]
Expand All @@ -473,7 +475,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 23,
"id": "c8aefd1d-be3c-46f9-bd67-5c8557f9b385",
"metadata": {},
"outputs": [],
Expand All @@ -492,68 +494,43 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 30,
"id": "cbf386c9-f74e-4948-9ea0-94b69b7b2e29",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n",
"Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"> Running step 6e04f9be-9df8-46be-b8e2-2df877c7b3fd. Step input: What's the maximum number of cores in 3600 sockets of Intel Xeon 6 processor ? Go step by step, using a tool to do any math.\n",
"\u001b[1;3;38;5;200mThought: The current language of the user is English. I need to use a tool to help me answer the question.\n",
"Action: Xeon6\n",
"Action Input: {'input': 'maximum cores in a single socket'}\n",
"\u001b[0m"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;3;34mObservation: \n",
"\n",
"According to the provided context information, the maximum cores in a single socket is 144.\n",
"\u001b[0m"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Action: vector_search\n",
"Action Input: {'input': 'Intel Xeon 6 processor'}\n",
"\u001b[0m\u001b[1;3;34mObservation: The Intel Xeon 6 processor is a high-performance processor designed for data-intensive workloads, such as 5G core networks, content delivery networks, and industrial automation. It features up to 144 cores per socket, improved power efficiency, and support for advanced security features like Intel QuickAssist Technology and Intel Software Guard Extensions. The processor is also designed for edge computing, with features like Intel Advanced Vector Extensions and Intel Trust Domain Extensions. It is available in select SKUs and supports various operating systems. However, it is important to note that performance may vary depending on the use case, configuration, and other factors. \n",
"\u001b[0m> Running step 1f551f6e-64fa-4687-8b89-3f896c9eaf35. Step input: None\n",
"\u001b[1;3;38;5;200mThought: The current language of the user is English. I need to use a tool to help me answer the question.\n",
"Action: multiply\n",
"Action Input: {'a': 144, 'b': 4}\n",
"\u001b[0m\u001b[1;3;34mObservation: 576\n",
"\u001b[0m\u001b[1;3;38;5;200mThought: The current language of the user is English. I can answer without using any more tools. I'll use the user's language to answer\n",
"Answer: The maximum number of cores in an Intel Xeon 6 processor server with 4 sockets is 576.\n",
"Action Input: {'a': 144, 'b': 3600}\n",
"\u001b[0m\u001b[1;3;34mObservation: 518400\n",
"\u001b[0m> Running step 88194e07-3d60-4e49-a64a-b93c65216124. Step input: None\n",
"\u001b[1;3;38;5;200mThought: The current language of the user is English. I can answer without using any more tools. I'll use the user's language to answer.\n",
"Answer: The maximum number of cores in 3600 sockets of Intel Xeon 6 processor is 518,400.\n",
"\u001b[0m"
]
}
],
"source": [
"response = agent.chat(\"What's the maximum number of cores in an Intel Xeon 6 processor server with 4 sockets ? Go step by step, using a tool to do any math.\")"
"response = agent.chat(\"What's the maximum number of cores in 3600 sockets of Intel Xeon 6 processor ? Go step by step, using a tool to do any math.\")"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "fd3211e2-4465-41e1-bbd6-b493a53ffccc",
"metadata": {},
"outputs": [],
"source": [
"agent.reset()"
]
}
],
Expand All @@ -573,7 +550,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.10.7"
},
"openvino_notebooks": {
"imageUrl": "https://github.com/openvinotoolkit/openvino_notebooks/assets/91237924/871cb90d-27fd-4a87-aa3c-f4cdb199a148",
Expand Down

0 comments on commit cb99c7b

Please sign in to comment.