diff --git a/.ci/ignore_treon_docker.txt b/.ci/ignore_treon_docker.txt index e87ff699026..509d7013110 100644 --- a/.ci/ignore_treon_docker.txt +++ b/.ci/ignore_treon_docker.txt @@ -80,4 +80,5 @@ notebooks/mllama-3.2/mllama-3.2.ipynb notebooks/sam2-image-segmentation/segment-anything-2-image.ipynb notebooks/pixtral/pixtral.ipynb notebooks/llm-agent-react/llm-agent-react.ipynb -notebooks/multilora-image-generation/multilora-image-generation.ipynb \ No newline at end of file +notebooks/multilora-image-generation/multilora-image-generation.ipynb +notebooks/llm-agent-react/llm-agent-react-langchain.ipynb \ No newline at end of file diff --git a/.ci/skipped_notebooks.yml b/.ci/skipped_notebooks.yml index d7fa99d06c9..15b1fb8db7b 100644 --- a/.ci/skipped_notebooks.yml +++ b/.ci/skipped_notebooks.yml @@ -555,4 +555,11 @@ - notebook: notebooks/mobileclip-video-search/mobileclip-video-search.ipynb skips: - os: - - macos-12 \ No newline at end of file + - macos-12 +- notebook: notebooks/llm-agent-react/llm-agent-react-langchain.ipynb + skips: + - os: + - macos-12 + - ubuntu-20.04 + - ubuntu-22.04 + - windows-2019 \ No newline at end of file diff --git a/notebooks/llm-agent-react/README.md b/notebooks/llm-agent-react/README.md index 9e4fad5e2f4..83ab9414cca 100644 --- a/notebooks/llm-agent-react/README.md +++ b/notebooks/llm-agent-react/README.md @@ -4,7 +4,7 @@ LLM are limited to the knowledge on which they have been trained and the additio The core idea of agents is to use a language model to choose a sequence of actions to take. In agents, a language model is used as a reasoning engine to determine which actions to take and in which order. Agents can be seen as applications powered by LLMs and integrated with a set of tools like search engines, databases, websites, and so on. Within an agent, the LLM is the reasoning engine that, based on the user input, is able to plan and execute a set of actions that are needed to fulfill the request. -![agent ui](https://github.com/openvinotoolkit/openvino_notebooks/assets/91237924/2abb2389-e612-4599-82c6-64cdac259120) +![image](https://github.com/user-attachments/assets/b656adab-a448-4784-a6df-a068e0cb45bb) This notebook explores how to create an ReAct Agent step by step using OpenVINO. [ReAct](https://arxiv.org/abs/2210.03629) is an approach to combine reasoning (e.g. chain-of-thought prompting) and acting. ReAct overcomes issues of hallucination and error propagation prevalent in chain-of-thought reasoning by interacting with a simple Wikipedia API, and generates human-like task-solving trajectories that are more interpretable than baselines without reasoning traces. diff --git a/notebooks/llm-agent-react/gradio_helper.py b/notebooks/llm-agent-react/gradio_helper.py index 0406c5e7099..37bfbaecd0c 100644 --- a/notebooks/llm-agent-react/gradio_helper.py +++ b/notebooks/llm-agent-react/gradio_helper.py @@ -31,7 +31,7 @@ def make_demo(run_fn: Callable, stop_fn: Callable): css=".disclaimer {font-variant-caps: all-small-caps;}", ) as demo: gr.Markdown(f"""

AI Agent with OpenVINO and LangChain

""") - chatbot = gr.Chatbot(height=500) + chatbot = gr.Chatbot(height=800) with gr.Row(): with gr.Column(): msg = gr.Textbox( diff --git a/notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb b/notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb index 7353c9068be..59ef8265c2e 100644 --- a/notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb +++ b/notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb @@ -203,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": null, "id": "86fdc4ba-74c4-4869-898e-131f47827e8f", "metadata": { "test_replace": {} diff --git a/notebooks/llm-agent-react/llm-agent-react-langchain.ipynb b/notebooks/llm-agent-react/llm-agent-react-langchain.ipynb index d92e39294f0..044740157cf 100644 --- a/notebooks/llm-agent-react/llm-agent-react-langchain.ipynb +++ b/notebooks/llm-agent-react/llm-agent-react-langchain.ipynb @@ -59,7 +59,51 @@ "execution_count": null, "id": "47d43de7-9946-482d-84cb-222294c1cda8", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1491" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import requests\n", + "from pathlib import Path\n", + "\n", + "r = requests.get(\n", + " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n", + ")\n", + "open(\"notebook_utils.py\", \"w\").write(r.text)\n", + "\n", + "if not Path(\"cmd_helper.py\").exists():\n", + " r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py\")\n", + " open(\"cmd_helper.py\", \"w\", encoding=\"utf-8\").write(r.text)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b772846d-d559-4ad9-bb7a-d2164732964a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Note: you may need to restart the kernel to use updated packages.\n", + "Note: you may need to restart the kernel to use updated packages.\n", + "Note: you may need to restart the kernel to use updated packages.\n", + "Note: you may need to restart the kernel to use updated packages.\n", + "Note: you may need to restart the kernel to use updated packages.\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], "source": [ "import os\n", "\n", @@ -67,13 +111,13 @@ "\n", "%pip install -Uq pip\n", "%pip uninstall -q -y optimum optimum-intel\n", - "%pip install --pre -Uq \"openvino>=2024.2.0\" openvino-tokenizers[transformers] --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly\n", - "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu \\\n", + "%pip install --pre -Uq \"openvino>=2024.5.0\" openvino-tokenizers[transformers] --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly\n", + "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu \"transformers>=4.38.1\" \"langchain>=0.2.3\" \"langchain-huggingface>=0.1.2\" \"langchain-community>=0.2.4\" \"Wikipedia\" \\\n", "\"torch>=2.1\" \\\n", "\"datasets\" \\\n", "\"accelerate\" \\\n", + "\"pydantic<2.10.0\" \\\n", "\"gradio>=4.19\"\n", - "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu \"transformers>=4.38.1\" \"langchain>=0.2.3\" \"langchain-community>=0.2.4\" \"Wikipedia\"\n", "%pip install -q \"git+https://github.com/huggingface/optimum-intel.git\" \\\n", "\"git+https://github.com/openvinotoolkit/nncf.git\"" ] @@ -93,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 104, "id": "e8bfe609-1823-4df7-9a68-f210a58a0d38", "metadata": {}, "outputs": [], @@ -121,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 105, "id": "5ea4ce13", "metadata": {}, "outputs": [ @@ -165,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 106, "id": "a5c41830", "metadata": {}, "outputs": [], @@ -196,12 +240,12 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 107, "id": "107f040a-e859-475c-9422-f980ac593fcf", "metadata": {}, "outputs": [], "source": [ - "PREFIX = \"\"\"[INST]Respond to the human as helpfully and accurately as possible. You have access to the following tools:\"\"\"\n", + "PREFIX = \"\"\"Respond to the human as helpfully and accurately as possible. You have access to the following tools:\"\"\"\n", "\n", "FORMAT_INSTRUCTIONS = \"\"\"Use a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input).\n", "\n", @@ -233,10 +277,10 @@ " \"action\": \"Final Answer\",\n", " \"action_input\": \"Final response to human\"\n", "}}}}\n", - "```[/INST]\"\"\"\n", + "```\"\"\"\n", "\n", "SUFFIX = \"\"\"Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation:.\n", - "Thought:[INST]\"\"\"\n", + "Thought:\"\"\"\n", "\n", "HUMAN_MESSAGE_TEMPLATE = \"{input}\\n\\n{agent_scratchpad}\"" ] @@ -251,11 +295,14 @@ "\n", "[back to top ⬆️](#Table-of-contents:)\n", "\n", - "Large Language Models (LLMs) are a core component of LangChain. LangChain does not serve its own LLMs, but rather provides a standard interface for interacting with many different LLMs. In this example, we select `Mistral-7B-Instruct-v0.3` as LLM in agent pipeline.\n", + "Large Language Models (LLMs) are a core component of LangChain. LangChain does not serve its own LLMs, but rather provides a standard interface for interacting with many different LLMs. In this example, we select following models as LLM in agent pipeline.\n", "\n", - "* **Mistral-7B-Instruct-v0.3** - The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3. You can find more details about model in the [model card](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3), [paper](https://arxiv.org/abs/2310.06825) and [release blog post](https://mistral.ai/news/announcing-mistral-7b/).\n", + "\n", + "* **qwen2.5-3b-instruct/qwen2.5-7b-instruct/qwen2.5-14b-instruct** - Qwen2.5 is the latest series of Qwen large language models. Comparing with Qwen2, Qwen2.5 series brings significant improvements in coding, mathematics and general knowledge skills. Additionally, it brings long-context and multiple languages support including Chinese, English, French, Spanish, Portuguese, German, Italian, Russian, Japanese, Korean, Vietnamese, Thai, Arabic, and more. \n", + "For more details, please refer to [model_card](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct), [blog](https://qwenlm.github.io/blog/qwen2.5/), [GitHub](https://github.com/QwenLM/Qwen2.5), and [Documentation](https://qwen.readthedocs.io/en/latest/).\n", + "* **llama-3.1-8b-instruct** - The Llama 3.1 instruction tuned text only models (8B, 70B, 405B) are optimized for multilingual dialogue use cases and outperform many of the available open source and closed chat models on common industry benchmarks. More details about model can be found in [Meta blog post](https://ai.meta.com/blog/meta-llama-3-1/), [model website](https://llama.meta.com) and [model card](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct).\n", ">**Note**: run model with demo, you will need to accept license agreement. \n", - ">You must be a registered user in 🤗 Hugging Face Hub. Please visit [HuggingFace model card](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3), carefully read terms of usage and click accept button. You will need to use an access token for the code below to run. For more information on access tokens, refer to [this section of the documentation](https://huggingface.co/docs/hub/security-tokens).\n", + ">You must be a registered user in 🤗 Hugging Face Hub. Please visit [HuggingFace model card](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct), carefully read terms of usage and click accept button. You will need to use an access token for the code below to run. For more information on access tokens, refer to [this section of the documentation](https://huggingface.co/docs/hub/security-tokens).\n", ">You can login on Hugging Face Hub in notebook environment, using following code:\n", " \n", "```python\n", @@ -279,22 +326,61 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 111, "id": "981df8fe-cfcf-455a-919e-dda36f3b5dfb", "metadata": { "test_replace": { - "mistralai/Mistral-7B-Instruct-v0.3": "TinyLlama/TinyLlama-1.1B-Chat-v1.0" + "Qwen/Qwen2.5-7B-Instruct": "Qwen/Qwen2.5-3B-Instruct" } }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "d69cabffc0bd4af9989f43fbad0bac5e", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Dropdown(description='Model:', options=('Qwen/Qwen2.5-7B-Instruct', 'Qwen/Qwen2.5-3B-Instruct', 'Qwen/qwen2.5-…" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import ipywidgets as widgets\n", + "\n", + "llm_model_ids = [\"Qwen/Qwen2.5-7B-Instruct\", \"Qwen/Qwen2.5-3B-Instruct\", \"Qwen/qwen2.5-14b-instruct\", \"meta-llama/Meta-Llama-3.1-8B-Instruct\"]\n", + "\n", + "llm_model_id = widgets.Dropdown(\n", + " options=llm_model_ids,\n", + " value=llm_model_ids[0],\n", + " description=\"Model:\",\n", + " disabled=False,\n", + ")\n", + "\n", + "llm_model_id" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d90a485-2823-47c3-958f-6d2d09a06ecf", + "metadata": {}, "outputs": [], "source": [ - "from pathlib import Path\n", + "from cmd_helper import optimum_cli\n", "\n", - "model_id = \"mistralai/Mistral-7B-Instruct-v0.3\"\n", - "model_path = \"Mistral-7B-Instruct-v0.3-ov-int4\"\n", + "llm_model_path = llm_model_id.value.split(\"/\")[-1]\n", + "repo_name = llm_model_id.value.split(\"/\")[0]\n", "\n", - "if not Path(model_path).exists():\n", - " !optimum-cli export openvino --model {model_id} --task text-generation-with-past --trust-remote-code --weight-format int4 {model_path}" + "if not Path(llm_model_path).exists():\n", + " optimum_cli(\n", + " llm_model_id.value, llm_model_path, additional_args={\"task\": \"text-generation-with-past\", \"weight-format\": \"int4\", \"group-size\": \"128\", \"ratio\": \"1.0\"}\n", + " )" ] }, { @@ -310,14 +396,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 115, "id": "a1ea3bdb-f97c-4374-880a-2b62abb5baaa", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "d5800b83c43743a0ad22f585edb6044a", + "model_id": "35dee5b9643942ef91abd549e132a36f", "version_major": 2, "version_minor": 0 }, @@ -325,22 +411,17 @@ "Dropdown(description='Device:', options=('CPU', 'GPU', 'AUTO'), value='CPU')" ] }, - "execution_count": 6, + "execution_count": 115, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "import requests\n", - "\n", - "r = requests.get(\n", - " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n", - ")\n", - "open(\"notebook_utils.py\", \"w\").write(r.text)\n", - "\n", "from notebook_utils import device_widget\n", "\n", - "device = device_widget(\"CPU\", exclude=[\"NPU\"])" + "device = device_widget(\"CPU\", exclude=[\"NPU\"])\n", + "\n", + "device" ] }, { @@ -354,30 +435,12 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 116, "id": "abfaab28-fd5b-46cd-88ad-b60ea5a3cdd6", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-06-07 23:17:16.804739: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n", - "2024-06-07 23:17:16.807973: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.\n", - "2024-06-07 23:17:16.850235: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n", - "2024-06-07 23:17:16.850258: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n", - "2024-06-07 23:17:16.850290: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n", - "2024-06-07 23:17:16.859334: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", - "To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n", - "2024-06-07 23:17:17.692415: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n", - "You set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizers\n", - "The argument `trust_remote_code` is to be used along with export=True. It will be ignored.\n", - "Compiling the model to GPU ...\n" - ] - } - ], + "outputs": [], "source": [ - "from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline\n", + "from langchain_huggingface import HuggingFacePipeline\n", "from transformers.generation.stopping_criteria import StoppingCriteriaList, StoppingCriteria\n", "\n", "import openvino.properties as props\n", @@ -411,7 +474,7 @@ "stop_tokens = [\"Observation:\"]\n", "\n", "ov_llm = HuggingFacePipeline.from_model_id(\n", - " model_id=model_path,\n", + " model_id=llm_model_path,\n", " task=\"text-generation\",\n", " backend=\"openvino\",\n", " model_kwargs={\n", @@ -421,12 +484,24 @@ " },\n", " pipeline_kwargs={\"max_new_tokens\": 2048},\n", ")\n", - "ov_llm = ov_llm.bind(skip_prompt=True, stop=[\"Observation:\"])\n", "\n", "tokenizer = ov_llm.pipeline.tokenizer\n", "ov_llm.pipeline._forward_params[\"stopping_criteria\"] = StoppingCriteriaList([StopSequenceCriteria(stop_tokens, tokenizer)])" ] }, + { + "cell_type": "code", + "execution_count": 117, + "id": "f5cae381-417f-4984-8873-9a6ad46c4eed", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_huggingface import ChatHuggingFace\n", + "\n", + "ov_chat = ChatHuggingFace(llm=ov_llm, verbose=True)\n", + "ov_chat = ov_chat.bind(skip_prompt=True, stop=[\"Observation:\"])" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -438,7 +513,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 118, "id": "17c2d285-e8bb-4da1-baa6-682a7851d333", "metadata": {}, "outputs": [], @@ -469,7 +544,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 119, "id": "4799540b-eee0-491f-a5b6-5bae68c22af9", "metadata": {}, "outputs": [], @@ -477,7 +552,7 @@ "from langchain.agents import AgentExecutor, StructuredChatAgent\n", "\n", "agent = StructuredChatAgent.from_llm_and_tools(\n", - " ov_llm,\n", + " ov_chat,\n", " tools,\n", " prefix=PREFIX,\n", " suffix=SUFFIX,\n", @@ -502,7 +577,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 120, "id": "eebc8f67-8107-4a6b-90bf-ea9256c64ee5", "metadata": {}, "outputs": [ @@ -513,57 +588,68 @@ "\n", "\n", "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mThought: I can use the exponentiate and add tools to solve the first part, and then use the multiply tool for the second part, and finally the exponentiate tool again to square the result.\n", + "\u001b[32;1m\u001b[1;3mThought: First, we need to take 3 to the fifth power. Then we will find the sum of twelve and three. After that, we multiply the first result by the second result. Finally, we'll square the whole result.\n", "\n", "Action:\n", "```\n", "{\n", " \"action\": \"exponentiate\",\n", - " \"action_input\": {\"base\": 3, \"exponent\": 5}\n", + " \"action_input\": {\n", + " \"base\": 3,\n", + " \"exponent\": 5\n", + " }\n", "}\n", "```\n", "Observation:\u001b[0m\n", "Observation: \u001b[38;5;200m\u001b[1;3m243\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m Now I need to add twelve and three\n", + "Thought:\u001b[32;1m\u001b[1;3mNext, let's find the sum of twelve and three.\n", "\n", "Action:\n", "```\n", "{\n", " \"action\": \"add\",\n", - " \"action_input\": {\"first_int\": 12, \"second_int\": 3}\n", + " \"action_input\": {\n", + " \"first_int\": 12,\n", + " \"second_int\": 3\n", + " }\n", "}\n", "```\n", "Observation:\u001b[0m\n", "Observation: \u001b[33;1m\u001b[1;3m15\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m Now I need to multiply the result by 243\n", + "Thought:\u001b[32;1m\u001b[1;3mNow, we will multiply the result of \\(3^5\\) (which is 243) by the sum of 12 and 3 (which is 15).\n", "\n", "Action:\n", "```\n", "{\n", " \"action\": \"multiply\",\n", - " \"action_input\": {\"first_int\": 243, \"second_int\": 15}\n", + " \"action_input\": {\n", + " \"first_int\": 243,\n", + " \"second_int\": 15\n", + " }\n", "}\n", "```\n", "Observation:\u001b[0m\n", "Observation: \u001b[36;1m\u001b[1;3m3645\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m Finally, I need to square the result\n", + "Thought:\u001b[32;1m\u001b[1;3mThought: Now, we need to square the result of the multiplication (3645). \n", "\n", "Action:\n", "```\n", "{\n", " \"action\": \"exponentiate\",\n", - " \"action_input\": {\"base\": 3645, \"exponent\": 2}\n", + " \"action_input\": {\n", + " \"base\": 3645,\n", + " \"exponent\": 2\n", + " }\n", "}\n", - "```\n", - "Observation:\u001b[0m\n", + "```\u001b[0m\n", "Observation: \u001b[38;5;200m\u001b[1;3m13286025\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I know what to respond\n", + "Thought:\u001b[32;1m\u001b[1;3mThought: I know what to respond\n", "\n", "Action:\n", "```\n", "{\n", " \"action\": \"Final Answer\",\n", - " \"action_input\": \"The final answer is 13286025\"\n", + " \"action_input\": \"The final result is 13286025.\"\n", "}\n", "```\u001b[0m\n", "\n", @@ -574,10 +660,10 @@ "data": { "text/plain": [ "{'input': 'Take 3 to the fifth power and multiply that by the sum of twelve and three, then square the whole result',\n", - " 'output': 'The final answer is 13286025'}" + " 'output': 'The final result is 13286025.'}" ] }, - "execution_count": 10, + "execution_count": 120, "metadata": {}, "output_type": "execute_result" } @@ -614,7 +700,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 121, "id": "1f64b67c-1259-4fe6-bfc3-af317bfe04f6", "metadata": {}, "outputs": [], @@ -655,17 +741,17 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 122, "id": "ea649d2f-ab4b-4228-8f32-75b01a98d9a7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'Page: OpenVINO\\nSummary: OpenVINO is an open-source software toolkit for optimizing and deploying deep learning models. It enables programmers to develop scalable and efficient AI solutions with relatively few lines of code. It supports several popular model formats and categories, such as large language models, computer vision, and generative AI.\\nActively developed by Intel, it prioritizes high-performance inference on Intel hardware but also supports ARM/ARM64 processors and encourages contributors to add new devices to the portfolio.\\nBased in C++, it offers the following APIs: C/C++, Python, and Node.js (an early preview).\\nOpenVINO is cross-platform and free for use under Apache License 2.0.\\n\\nPage: Stable Diffusion\\nSummary: Stable Diffusion is a deep learning, text-to-image model released in 2022 based on diffusion techniques. It is considered to be a part of the ongoing artificial intelligence boom.\\nIt is primarily used to generate detailed images conditioned on text descriptions, t'" + "'Page: OpenVINO\\nSummary: OpenVINO is an open-source software toolkit for optimizing and deploying deep learning models. It enables programmers to develop scalable and efficient AI solutions with relatively few lines of code. It supports several popular model formats and categories, such as large language models, computer vision, and generative AI.\\nActively developed by Intel, it prioritizes high-performance inference on Intel hardware but also supports ARM/ARM64 processors and encourages contributors to add new devices to the portfolio.\\nBased in C++, it offers the following APIs: C/C++, Python, and Node.js (an early preview).\\nOpenVINO is cross-platform and free for use under Apache License 2.0.\\n\\nPage: Audacity (audio editor)\\nSummary: Audacity is a free and open-source digital audio editor and recording application software, available for Windows, macOS, Linux, and other Unix-like operating systems. \\nAs of December 6, 2022, Audacity is the most popular download at FossHub, with over 114.'" ] }, - "execution_count": 12, + "execution_count": 122, "metadata": {}, "output_type": "execute_result" } @@ -689,7 +775,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 123, "id": "318acd7b-d022-4bdf-b65c-b4fdcc015048", "metadata": {}, "outputs": [ @@ -699,7 +785,7 @@ "'{image_url: \"https://image.pollinations.ai/prompt/a%20cat\"}'" ] }, - "execution_count": 13, + "execution_count": 123, "metadata": {}, "output_type": "execute_result" } @@ -723,17 +809,17 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 124, "id": "96e9f671-1680-402c-a799-0e45b731f63e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "\"{'current_condition': {'temp_C': '9', 'FeelsLikeC': '8', 'humidity': '93', 'weatherDesc': [{'value': 'Sunny'}], 'observation_time': '04:39 AM'}}\"" + "\"{'current_condition': {'temp_C': '0', 'FeelsLikeC': '-4', 'humidity': '86', 'weatherDesc': [{'value': 'Clear'}], 'observation_time': '12:16 AM'}}\"" ] }, - "execution_count": 14, + "execution_count": 124, "metadata": {}, "output_type": "execute_result" } @@ -785,7 +871,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 125, "id": "ce703b35-6396-409c-bf4f-d4bc4dd584b4", "metadata": {}, "outputs": [], @@ -793,7 +879,7 @@ "tools = [wikipedia, painting, weather]\n", "\n", "agent = StructuredChatAgent.from_llm_and_tools(\n", - " ov_llm,\n", + " ov_chat,\n", " tools,\n", " prefix=PREFIX,\n", " suffix=SUFFIX,\n", @@ -805,7 +891,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 129, "id": "d6b24449", "metadata": {}, "outputs": [], @@ -845,7 +931,7 @@ "\n", "\n", "def request_cancel():\n", - " ov_llm.pipeline.model.request.cancel()" + " ov_chat.llm.pipeline.model.request.cancel()" ] }, { @@ -853,53 +939,7 @@ "execution_count": null, "id": "ff5a60fb-e13e-4eaf-a2f3-999e4e3109bf", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mThought: I need to use the weather tool to get the current weather in London, then use the painting tool to generate a picture of Big Ben based on the weather information.\n", - "\n", - "Action:\n", - "```\n", - "{\n", - " \"action\": \"weather\",\n", - " \"action_input\": \"London\"\n", - "}\n", - "```\n", - "\n", - "Observation:\u001b[0m\n", - "Observation: \u001b[38;5;200m\u001b[1;3m{'current_condition': {'temp_C': '9', 'FeelsLikeC': '8', 'humidity': '93', 'weatherDesc': [{'value': 'Sunny'}], 'observation_time': '04:39 AM'}}\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I have the current weather in London. Now I can use the painting tool to generate a picture of Big Ben based on the weather information.\n", - "\n", - "Action:\n", - "```\n", - "{\n", - " \"action\": \"painting\",\n", - " \"action_input\": \"Big Ben, sunny day\"\n", - "}\n", - "```\n", - "\n", - "Observation:\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3m{image_url: \"https://image.pollinations.ai/prompt/Big%20Ben%2C%20sunny%20day\"}\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I have the image URL of Big Ben on a sunny day. Now I can respond to the human with the image URL.\n", - "\n", - "Action:\n", - "```\n", - "{\n", - " \"action\": \"Final Answer\",\n", - " \"action_input\": \"Here is the image of Big Ben on a sunny day: https://image.pollinations.ai/prompt/Big%20Ben%2C%20sunny%20day\"\n", - "}\n", - "```\n", - "Observation:\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - } - ], + "outputs": [], "source": [ "if not Path(\"gradio_helper.py\").exists():\n", " r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/llm-agent-react/gradio_helper.py\")\n", @@ -932,7 +972,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -946,7 +986,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/2abb2389-e612-4599-82c6-64cdac259120",