diff --git a/artificial_intelligence_with_python_tutorial.pdf b/artificial_intelligence_with_python_tutorial.pdf new file mode 100644 index 0000000..ba8e943 Binary files /dev/null and b/artificial_intelligence_with_python_tutorial.pdf differ diff --git a/your-code/main.ipynb b/your-code/main.ipynb index e3a225a..1770528 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -59,9 +59,178 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: langchain in c:\\users\\vigus\\anaconda3\\lib\\site-packages (1.2.7)\n", + "Requirement already satisfied: langchain_community in c:\\users\\vigus\\anaconda3\\lib\\site-packages (0.4.1)\n", + "Requirement already satisfied: pypdf in c:\\users\\vigus\\anaconda3\\lib\\site-packages (6.6.0)\n", + "Requirement already satisfied: langchain-core<2.0.0,>=1.2.7 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain) (1.2.7)\n", + "Requirement already satisfied: langgraph<1.1.0,>=1.0.7 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain) (1.0.7)\n", + "Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain) (2.10.3)\n", + "Requirement already satisfied: jsonpatch<2.0.0,>=1.33.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.7->langchain) (1.33)\n", + "Requirement already satisfied: langsmith<1.0.0,>=0.3.45 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.7->langchain) (0.6.4)\n", + "Requirement already satisfied: packaging<26.0.0,>=23.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.7->langchain) (24.2)\n", + "Requirement already satisfied: pyyaml<7.0.0,>=5.3.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.7->langchain) (6.0.2)\n", + "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.7->langchain) (9.0.0)\n", + "Requirement already satisfied: typing-extensions<5.0.0,>=4.7.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.7->langchain) (4.12.2)\n", + "Requirement already satisfied: uuid-utils<1.0,>=0.12.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.7->langchain) (0.14.0)\n", + "Requirement already satisfied: jsonpointer>=1.9 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from jsonpatch<2.0.0,>=1.33.0->langchain-core<2.0.0,>=1.2.7->langchain) (2.1)\n", + "Requirement already satisfied: langgraph-checkpoint<5.0.0,>=2.1.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langgraph<1.1.0,>=1.0.7->langchain) (4.0.0)\n", + "Requirement already satisfied: langgraph-prebuilt<1.1.0,>=1.0.7 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langgraph<1.1.0,>=1.0.7->langchain) (1.0.7)\n", + "Requirement already satisfied: langgraph-sdk<0.4.0,>=0.3.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langgraph<1.1.0,>=1.0.7->langchain) (0.3.3)\n", + "Requirement already satisfied: xxhash>=3.5.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langgraph<1.1.0,>=1.0.7->langchain) (3.6.0)\n", + "Requirement already satisfied: ormsgpack>=1.12.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langgraph-checkpoint<5.0.0,>=2.1.0->langgraph<1.1.0,>=1.0.7->langchain) (1.12.2)\n", + "Requirement already satisfied: httpx>=0.25.2 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.7->langchain) (0.28.1)\n", + "Requirement already satisfied: orjson>=3.10.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.7->langchain) (3.11.5)\n", + "Requirement already satisfied: requests-toolbelt>=1.0.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.7->langchain) (1.0.0)\n", + "Requirement already satisfied: requests>=2.0.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.7->langchain) (2.32.5)\n", + "Requirement already satisfied: zstandard>=0.23.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.7->langchain) (0.23.0)\n", + "Requirement already satisfied: anyio in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.7->langchain) (4.7.0)\n", + "Requirement already satisfied: certifi in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.7->langchain) (2025.8.3)\n", + "Requirement already satisfied: httpcore==1.* in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.7->langchain) (1.0.9)\n", + "Requirement already satisfied: idna in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.7->langchain) (3.7)\n", + "Requirement already satisfied: h11>=0.16 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from httpcore==1.*->httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.7->langchain) (0.16.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.27.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (2.27.1)\n", + "Requirement already satisfied: langchain-classic<2.0.0,>=1.0.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain_community) (1.0.1)\n", + "Requirement already satisfied: SQLAlchemy<3.0.0,>=1.4.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain_community) (2.0.39)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain_community) (3.11.10)\n", + "Requirement already satisfied: dataclasses-json<0.7.0,>=0.6.7 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain_community) (0.6.7)\n", + "Requirement already satisfied: pydantic-settings<3.0.0,>=2.10.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain_community) (2.12.0)\n", + "Requirement already satisfied: httpx-sse<1.0.0,>=0.4.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain_community) (0.4.3)\n", + "Requirement already satisfied: numpy>=2.1.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain_community) (2.1.3)\n", + "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (2.4.4)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.2.0)\n", + "Requirement already satisfied: attrs>=17.3.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (24.3.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.5.0)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (6.1.0)\n", + "Requirement already satisfied: propcache>=0.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (0.3.1)\n", + "Requirement already satisfied: yarl<2.0,>=1.17.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.18.0)\n", + "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from dataclasses-json<0.7.0,>=0.6.7->langchain_community) (3.26.2)\n", + "Requirement already satisfied: typing-inspect<1,>=0.4.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from dataclasses-json<0.7.0,>=0.6.7->langchain_community) (0.9.0)\n", + "Requirement already satisfied: langchain-text-splitters<2.0.0,>=1.1.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-classic<2.0.0,>=1.0.0->langchain_community) (1.1.0)\n", + "Requirement already satisfied: python-dotenv>=0.21.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from pydantic-settings<3.0.0,>=2.10.1->langchain_community) (1.2.1)\n", + "Requirement already satisfied: typing-inspection>=0.4.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from pydantic-settings<3.0.0,>=2.10.1->langchain_community) (0.4.2)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from requests>=2.0.0->langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.7->langchain) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from requests>=2.0.0->langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.7->langchain) (2.3.0)\n", + "Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from SQLAlchemy<3.0.0,>=1.4.0->langchain_community) (3.1.1)\n", + "Requirement already satisfied: mypy-extensions>=0.3.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7.0,>=0.6.7->langchain_community) (1.0.0)\n", + "Requirement already satisfied: sniffio>=1.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from anyio->httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.7->langchain) (1.3.0)\n", + "Note: you may need to restart the kernel to use updated packages.\n", + "Requirement already satisfied: termcolor in c:\\users\\vigus\\anaconda3\\lib\\site-packages (3.2.0)\n", + "Requirement already satisfied: langchain_openai in c:\\users\\vigus\\anaconda3\\lib\\site-packages (1.1.7)\n", + "Requirement already satisfied: langchain-huggingface in c:\\users\\vigus\\anaconda3\\lib\\site-packages (1.2.0)\n", + "Requirement already satisfied: sentence-transformers in c:\\users\\vigus\\anaconda3\\lib\\site-packages (5.2.0)\n", + "Requirement already satisfied: chromadb in c:\\users\\vigus\\anaconda3\\lib\\site-packages (1.4.1)\n", + "Requirement already satisfied: langchain_chroma in c:\\users\\vigus\\anaconda3\\lib\\site-packages (1.1.0)\n", + "Requirement already satisfied: tiktoken in c:\\users\\vigus\\anaconda3\\lib\\site-packages (0.12.0)\n", + "Requirement already satisfied: openai in c:\\users\\vigus\\anaconda3\\lib\\site-packages (2.15.0)\n", + "Requirement already satisfied: python-dotenv in c:\\users\\vigus\\anaconda3\\lib\\site-packages (1.2.1)\n", + "Requirement already satisfied: langchain-core<2.0.0,>=1.2.6 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain_openai) (1.2.7)\n", + "Requirement already satisfied: regex>=2022.1.18 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from tiktoken) (2024.11.6)\n", + "Requirement already satisfied: requests>=2.26.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from tiktoken) (2.32.5)\n", + "Requirement already satisfied: anyio<5,>=3.5.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from openai) (4.7.0)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from openai) (1.9.0)\n", + "Requirement already satisfied: httpx<1,>=0.23.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from openai) (0.28.1)\n", + "Requirement already satisfied: jiter<1,>=0.10.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from openai) (0.12.0)\n", + "Requirement already satisfied: pydantic<3,>=1.9.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from openai) (2.10.3)\n", + "Requirement already satisfied: sniffio in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from openai) (1.3.0)\n", + "Requirement already satisfied: tqdm>4 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from openai) (4.67.1)\n", + "Requirement already satisfied: typing-extensions<5,>=4.11 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from openai) (4.12.2)\n", + "Requirement already satisfied: idna>=2.8 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from anyio<5,>=3.5.0->openai) (3.7)\n", + "Requirement already satisfied: certifi in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from httpx<1,>=0.23.0->openai) (2025.8.3)\n", + "Requirement already satisfied: httpcore==1.* in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from httpx<1,>=0.23.0->openai) (1.0.9)\n", + "Requirement already satisfied: h11>=0.16 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.16.0)\n", + "Requirement already satisfied: jsonpatch<2.0.0,>=1.33.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.6->langchain_openai) (1.33)\n", + "Requirement already satisfied: langsmith<1.0.0,>=0.3.45 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.6->langchain_openai) (0.6.4)\n", + "Requirement already satisfied: packaging<26.0.0,>=23.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.6->langchain_openai) (24.2)\n", + "Requirement already satisfied: pyyaml<7.0.0,>=5.3.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.6->langchain_openai) (6.0.2)\n", + "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.6->langchain_openai) (9.0.0)\n", + "Requirement already satisfied: uuid-utils<1.0,>=0.12.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-core<2.0.0,>=1.2.6->langchain_openai) (0.14.0)\n", + "Requirement already satisfied: jsonpointer>=1.9 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from jsonpatch<2.0.0,>=1.33.0->langchain-core<2.0.0,>=1.2.6->langchain_openai) (2.1)\n", + "Requirement already satisfied: orjson>=3.9.14 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.6->langchain_openai) (3.11.5)\n", + "Requirement already satisfied: requests-toolbelt>=1.0.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.6->langchain_openai) (1.0.0)\n", + "Requirement already satisfied: zstandard>=0.23.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.6->langchain_openai) (0.23.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from pydantic<3,>=1.9.0->openai) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.27.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from pydantic<3,>=1.9.0->openai) (2.27.1)\n", + "Requirement already satisfied: huggingface-hub<1.0.0,>=0.33.4 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-huggingface) (0.36.0)\n", + "Requirement already satisfied: tokenizers<1.0.0,>=0.19.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from langchain-huggingface) (0.22.2)\n", + "Requirement already satisfied: filelock in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from huggingface-hub<1.0.0,>=0.33.4->langchain-huggingface) (3.17.0)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from huggingface-hub<1.0.0,>=0.33.4->langchain-huggingface) (2025.3.2)\n", + "Requirement already satisfied: transformers<6.0.0,>=4.41.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from sentence-transformers) (4.57.6)\n", + "Requirement already satisfied: torch>=1.11.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from sentence-transformers) (2.9.1)\n", + "Requirement already satisfied: scikit-learn in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from sentence-transformers) (1.6.1)\n", + "Requirement already satisfied: scipy in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from sentence-transformers) (1.16.3)\n", + "Requirement already satisfied: numpy>=1.17 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from transformers<6.0.0,>=4.41.0->sentence-transformers) (2.1.3)\n", + "Requirement already satisfied: safetensors>=0.4.3 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from transformers<6.0.0,>=4.41.0->sentence-transformers) (0.7.0)\n", + "Requirement already satisfied: build>=1.0.3 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (1.4.0)\n", + "Requirement already satisfied: pybase64>=1.4.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (1.4.3)\n", + "Requirement already satisfied: uvicorn>=0.18.3 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.40.0)\n", + "Requirement already satisfied: posthog<6.0.0,>=2.4.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (5.4.0)\n", + "Requirement already satisfied: onnxruntime>=1.14.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (1.23.2)\n", + "Requirement already satisfied: opentelemetry-api>=1.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (1.39.1)\n", + "Requirement already satisfied: opentelemetry-exporter-otlp-proto-grpc>=1.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (1.39.1)\n", + "Requirement already satisfied: opentelemetry-sdk>=1.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (1.39.1)\n", + "Requirement already satisfied: pypika>=0.48.9 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (0.50.0)\n", + "Requirement already satisfied: overrides>=7.3.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (7.4.0)\n", + "Requirement already satisfied: importlib-resources in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (6.5.2)\n", + "Requirement already satisfied: grpcio>=1.58.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (1.76.0)\n", + "Requirement already satisfied: bcrypt>=4.0.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (4.3.0)\n", + "Requirement already satisfied: typer>=0.9.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (0.9.0)\n", + "Requirement already satisfied: kubernetes>=28.1.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (35.0.0)\n", + "Requirement already satisfied: mmh3>=4.0.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (5.2.0)\n", + "Requirement already satisfied: rich>=10.11.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (13.9.4)\n", + "Requirement already satisfied: jsonschema>=4.19.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from chromadb) (4.23.0)\n", + "Requirement already satisfied: six>=1.5 in c:\\users\\vigus\\appdata\\roaming\\python\\python313\\site-packages (from posthog<6.0.0,>=2.4.0->chromadb) (1.17.0)\n", + "Requirement already satisfied: python-dateutil>=2.2 in c:\\users\\vigus\\appdata\\roaming\\python\\python313\\site-packages (from posthog<6.0.0,>=2.4.0->chromadb) (2.9.0.post0)\n", + "Requirement already satisfied: backoff>=1.10.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from posthog<6.0.0,>=2.4.0->chromadb) (2.2.1)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from requests>=2.26.0->tiktoken) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from requests>=2.26.0->tiktoken) (2.3.0)\n", + "Requirement already satisfied: pyproject_hooks in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from build>=1.0.3->chromadb) (1.2.0)\n", + "Requirement already satisfied: colorama in c:\\users\\vigus\\appdata\\roaming\\python\\python313\\site-packages (from build>=1.0.3->chromadb) (0.4.6)\n", + "Requirement already satisfied: attrs>=22.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from jsonschema>=4.19.0->chromadb) (24.3.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from jsonschema>=4.19.0->chromadb) (2023.7.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from jsonschema>=4.19.0->chromadb) (0.30.2)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from jsonschema>=4.19.0->chromadb) (0.22.3)\n", + "Requirement already satisfied: websocket-client!=0.40.0,!=0.41.*,!=0.42.*,>=0.32.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from kubernetes>=28.1.0->chromadb) (1.8.0)\n", + "Requirement already satisfied: requests-oauthlib in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from kubernetes>=28.1.0->chromadb) (2.0.0)\n", + "Requirement already satisfied: durationpy>=0.7 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from kubernetes>=28.1.0->chromadb) (0.10)\n", + "Requirement already satisfied: coloredlogs in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from onnxruntime>=1.14.1->chromadb) (15.0.1)\n", + "Requirement already satisfied: flatbuffers in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from onnxruntime>=1.14.1->chromadb) (25.12.19)\n", + "Requirement already satisfied: protobuf in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from onnxruntime>=1.14.1->chromadb) (5.29.3)\n", + "Requirement already satisfied: sympy in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from onnxruntime>=1.14.1->chromadb) (1.13.3)\n", + "Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from opentelemetry-api>=1.2.0->chromadb) (8.5.0)\n", + "Requirement already satisfied: zipp>=3.20 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api>=1.2.0->chromadb) (3.21.0)\n", + "Requirement already satisfied: googleapis-common-protos~=1.57 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb) (1.72.0)\n", + "Requirement already satisfied: opentelemetry-exporter-otlp-proto-common==1.39.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb) (1.39.1)\n", + "Requirement already satisfied: opentelemetry-proto==1.39.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb) (1.39.1)\n", + "Requirement already satisfied: opentelemetry-semantic-conventions==0.60b1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from opentelemetry-sdk>=1.2.0->chromadb) (0.60b1)\n", + "Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from rich>=10.11.0->chromadb) (2.2.0)\n", + "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\vigus\\appdata\\roaming\\python\\python313\\site-packages (from rich>=10.11.0->chromadb) (2.19.2)\n", + "Requirement already satisfied: mdurl~=0.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->chromadb) (0.1.0)\n", + "Requirement already satisfied: networkx>=2.5.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from torch>=1.11.0->sentence-transformers) (3.4.2)\n", + "Requirement already satisfied: jinja2 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from torch>=1.11.0->sentence-transformers) (3.1.6)\n", + "Requirement already satisfied: setuptools in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from torch>=1.11.0->sentence-transformers) (72.1.0)\n", + "Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from sympy->onnxruntime>=1.14.1->chromadb) (1.3.0)\n", + "Requirement already satisfied: click<9.0.0,>=7.1.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from typer>=0.9.0->chromadb) (8.1.8)\n", + "Requirement already satisfied: httptools>=0.6.3 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.7.1)\n", + "Requirement already satisfied: watchfiles>=0.13 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from uvicorn[standard]>=0.18.3->chromadb) (1.1.1)\n", + "Requirement already satisfied: websockets>=10.4 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from uvicorn[standard]>=0.18.3->chromadb) (16.0)\n", + "Requirement already satisfied: humanfriendly>=9.1 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from coloredlogs->onnxruntime>=1.14.1->chromadb) (10.0)\n", + "Requirement already satisfied: pyreadline3 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from humanfriendly>=9.1->coloredlogs->onnxruntime>=1.14.1->chromadb) (3.5.4)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from jinja2->torch>=1.11.0->sentence-transformers) (3.0.2)\n", + "Requirement already satisfied: oauthlib>=3.0.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from requests-oauthlib->kubernetes>=28.1.0->chromadb) (3.3.1)\n", + "Requirement already satisfied: joblib>=1.2.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from scikit-learn->sentence-transformers) (1.4.2)\n", + "Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\vigus\\anaconda3\\lib\\site-packages (from scikit-learn->sentence-transformers) (3.5.0)\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], "source": [ "%pip install langchain langchain_community pypdf\n", "%pip install termcolor langchain_openai langchain-huggingface sentence-transformers chromadb langchain_chroma tiktoken openai python-dotenv\n" @@ -69,15 +238,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "6heKZkQUxYZr" }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "c:\\Users\\vigus\\anaconda3\\Lib\\site-packages\\keras\\src\\export\\tf2onnx_lib.py:8: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.\n", + " if not hasattr(np, \"object\"):\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WARNING:tensorflow:From c:\\Users\\vigus\\anaconda3\\Lib\\site-packages\\tf_keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n", + "\n" + ] + } + ], "source": [ "import os\n", - "from langchain.document_loaders import PyPDFLoader\n", - "from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter\n", + "from langchain_classic.document_loaders import PyPDFLoader\n", + "from langchain_classic.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter\n", "import warnings\n", "warnings.filterwarnings('ignore')\n" ] @@ -96,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "cuREtJRixYZt" }, @@ -104,7 +290,7 @@ "source": [ "# File path for the document\n", "\n", - "file_path = \"LAB/ai-for-everyone.pdf\"" + "file_path = \"C:\\\\bootcamp\\\\lab-intro-rag\\\\ai-for-everyone.pdf\"" ] }, { @@ -122,12 +308,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "id": "_b5Z_45UxYZu", "outputId": "a600d69f-14fe-4492-f236-97261d6ff36c" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "297" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Load and split the document\n", "loader = PyPDFLoader(file_path)\n", @@ -168,9 +365,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1096" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "text_splitter = RecursiveCharacterTextSplitter(\n", " chunk_size=1000,\n", @@ -285,31 +493,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "L0xDxElwxYZw" }, "outputs": [], "source": [ - "from langchain.embeddings import OpenAIEmbeddings\n", + "from langchain_classic.embeddings import OpenAIEmbeddings\n", "from dotenv import load_dotenv" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "_WRIo3_0xYZx", "outputId": "78bfbbf3-9d25-4e31-bdbc-3e932e6bbfec" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "load_dotenv()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "MNZfTng5xYZz", "outputId": "db1a7c85-ef9f-447e-92cd-9d097e959847" @@ -343,23 +562,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "brKe6wUgxYZ0" }, "outputs": [], "source": [ - "from langchain.vectorstores import Chroma" + "from langchain_classic.vectorstores import Chroma" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "id": "VkjHR-RkxYZ0", "outputId": "bc11bda9-f283-457a-f584-5a06b95c4dd9" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ChromaDB created with document embeddings.\n" + ] + } + ], "source": [ "db = Chroma.from_documents(chunks, embeddings, persist_directory=\"./chroma_db_LAB\")\n", "print(\"ChromaDB created with document embeddings.\")" @@ -383,24 +610,71 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "XiLv-TfrxYZ1" }, "outputs": [], "source": [ - "user_question = \"\" # User question\n", + "user_question = \"What is AI?\" # User question\n", "retrieved_docs = db.similarity_search(user_question, k=10) # k is the number of documents to retrieve" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "id": "qgWsh50JxYZ1", "outputId": "c8640c5d-5955-471f-fdd2-37096f5f68c7" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Document 1:\n", + "For some years now, technical solutions utilising artificial intelligence are \n", + "widely seen as means to tackle many fundamental problems of mankind. From \n", + "fighting the climate crisis, tackling the problems of ageing societies, reducing \n", + "global poverty, stopping terror, detecting copyright infringements or curing \n", + "cancer to improving evidence-based politics, improving predictive police work, \n", + "local transportation, self-driving cars and even waste removal.\n", + "Definitions\n", + "The first step towards a meaningful discussion about AI would be to define \n", + "what exactly one means when talking about AI. Historically there have been \n", + "two major understandings of AI: strong AI or Artificial General Intelligence \n", + "(AGI) and weak AI or Artificial Narrow Intelligence (ANI). The goal of AGI is \n", + "the creation of an artificial human like intelligence, so an AI system with true \n", + "human-like intelligence including perception, agency, consciousness, inten -\n", + "Document 2:\n", + "applications), combined with the availabil-\n", + "ity of powerful and almost limitless computing capacity and advancements in \n", + "machine learning and deep learning is why we are currently in another period \n", + "of AI optimism and hype (Elish and boyd 2018). \n", + "Given the concepts and the brief discussion above, how can we agree on an \n", + "operational definition of AI? A basic definition would be to refer to AI as com-\n", + "puter programming that learns from and adapts to data. A more elaborate ver-\n", + "sion of this, as Elliott (2019: 4) puts it, defines AI as ‘any computational system \n", + "that can sense its relevant context and react intelligently to data’ in order to \n", + "perform highly complex tasks effectively and to achieve specific goals, thereby \n", + "mimicking intelligent human behaviours. The discussion about how to define \n", + "AI cannot be settled in one definition, let alone one book. It is an important\n", + "Document 3:\n", + " more debate than agreement about what AI \n", + "is and what it is not, and the only thing generally agreed is that there is no \n", + "widely accepted definition (Russell and Norvig 2016). The first definition comes \n", + "from that gathering of scientists in 1955: McCarthy et al. (1955/2006) then \n", + "defined AI as: ‘Making a machine behave in ways that would be called intelli-\n", + "gent if a human were so behaving’ . This only raises the challenge of how exactly \n", + "to define intelligence. Russell and Norvig (2016: 2) define different approaches to \n", + "AI to serve different goals. AI can refer to systems that: (1) think like humans; \n", + "(2) think rationally; (3) act like humans; and (4) act rationally. Each of the \n", + "approaches requires different disciplinary expertise, thus requiring an inter-, \n", + "or at least cross-disciplinary discussion. The human-centred approaches will \n", + "depart from social science studying human behaviour, while the rationalist\n" + ] + } + ], "source": [ "# Display top results\n", "for i, doc in enumerate(retrieved_docs[:3]): # Display top 3 results\n", @@ -418,7 +692,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "id": "2iB3lZqHxYZ2" }, @@ -434,12 +708,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "id": "2okzmuADxYZ2", "outputId": "0aa6cdca-188d-40e0-f5b4-8888d3549ea4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Context formatted for GPT model.\n" + ] + } + ], "source": [ "# Generate a formatted context from the retrieved documents\n", "formatted_context = _get_document_prompt(retrieved_docs)\n", @@ -464,22 +746,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "id": "tqxVh9s3xYZ3", "outputId": "97cca95d-4ab3-44d8-a76c-5713aad387d8" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Final prompt prepared for GPT model.\n", + "What is AI?\n", + "Use the following context to answer the question:\n", + "This is some example context.\n", + "Answer:\n" + ] + } + ], "source": [ - "prompt = f\"\"\"\n", + "formatted_context = \"This is some example context.\"\n", "\n", + "prompt = f\"\"\"What is AI?\n", + "Use the following context to answer the question:\n", + "{formatted_context}\n", + "Answer:\"\"\"\n", "\n", - "\"\"\"\n" + "print(\"Final prompt prepared for GPT model.\")\n", + "print(prompt)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "id": "0mjkQJ_ZxYZ3" }, @@ -497,7 +796,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "id": "ylypRWRlxYZ4" }, @@ -507,11 +806,11 @@ "client = openai.OpenAI()\n", "model_params = {\n", " 'model': 'gpt-4o',\n", - " 'temperature': , # Increase creativity\n", - " 'max_tokens': , # Allow for longer responses\n", - " 'top_p': , # Use nucleus sampling\n", - " 'frequency_penalty': , # Reduce repetition\n", - " 'presence_penalty': # Encourage new topics\n", + " 'temperature': 0.7, # Increase creativity\n", + " 'max_tokens': 1024, # Allow for longer responses\n", + " 'top_p': 0.9, # Use nucleus sampling\n", + " 'frequency_penalty': 0.5, # Reduce repetition\n", + " 'presence_penalty': 0.5 # Encourage new topics\n", "}" ] }, @@ -526,7 +825,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "id": "4eXZO4pIxYZ4" }, @@ -538,12 +837,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "id": "wLPAcchBxYZ5", "outputId": "976c7800-16ed-41fe-c4cf-58f60d3230d2" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "AI, or Artificial Intelligence, refers to the simulation of human intelligence processes by machines, particularly computer systems. These processes include learning (the acquisition of information and rules for using it), reasoning (using rules to reach approximate or definite conclusions), and self-correction. AI can be categorized into narrow AI, which is designed for a specific task, and general AI, which has the potential to perform any intellectual task that a human can do. Common applications of AI include speech recognition, image processing, natural language understanding, and autonomous vehicles.\n" + ] + } + ], "source": [ "answer = completion.choices[0].message.content\n", "print(answer)" @@ -595,7 +902,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "id": "nCXL9Cz1xYaV" }, @@ -615,7 +922,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "id": "9y3E0YWExYaV" }, @@ -636,12 +943,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": { "id": "i7SkWPpnxYaW", "outputId": "28e82563-edba-4b41-acad-ec27e5ba134f" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Snippet 1:\n", + "The Case of Artificial Intelligence\n", + "For some years now, technical solutions utilising artificial intelligence are \n", + "widely seen as means to tackle many fundamental problems of mankind. From \n", + "fighting t\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], "source": [ "query_keywords = [] # add your keywords\n", "for i, doc in enumerate(retrieved_docs[:1]):\n", @@ -680,6 +1000,243 @@ "source": [ "**Try loading one of your own PDF books and go through the steps again to explore how the pipeline works with your content**:\n" ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "file_path2 = \"C:\\\\bootcamp\\\\lab-intro-rag\\\\artificial_intelligence_with_python_tutorial.pdf\"" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "297" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Load and split the document\n", + "loader2 = PyPDFLoader(file_path2)\n", + "pages2 = loader2.load_and_split()\n", + "len(pages)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "654" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "text_splitter2 = RecursiveCharacterTextSplitter(\n", + " chunk_size=500,\n", + " chunk_overlap=100\n", + ")\n", + "chunks2 = text_splitter2.split_documents(pages2)\n", + "len(chunks2)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "user_question2 = \"what is the best way to use Python in machine learning?\" # User question\n", + "retrieved_docs2 = db.similarity_search(user_question2, k=10) # k is the number of documents to retrieve" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Document 1:\n", + "as machine learning. Machine learning is \n", + "often anthropomorphised, but it is at base the use of statistical methods, called \n", + "learning algorithms, to find patterns in large datasets. On the basis of these pat-\n", + "terns an algorithm called a ‘model’ is produced which may be used to analyse \n", + "new data (Alpaydin 2014, 2–3). A model thus represents ‘knowledge’ of the pat-\n", + "terns found by the learning algorithm and can be used to make useful analyses \n", + "or predictions. Much of the hype around machine learning derives from this \n", + "automated production of models from data, which Domingos (2015) calls the \n", + "‘inverse of programming’ (6–7). \n", + "Machine learning is being applied almost anywhere electronic data is accessi-\n", + "ble. Brynjolfsson and McAfee (2017) argue that machine learning is a general-\n", + "purpose technology comparable to the combustion engine. While this remains \n", + "to be seen, AI has found diverse applications from recommendation engines\n", + "Document 2:\n", + "Agrawal et al. 2018). Such systems can be \n", + "extremely powerful but are limited in the range of tasks they can perform.\n", + "Russell and Norvig (2016) see machine learning as a prerequisite for intel -\n", + "ligent machines. Machine learning is a paradigm that allows programs to auto-\n", + "matically improve their performance on a particular task by learning from vast \n", + "amounts of data (Alpaydin 2016). It seeks and uses statistical patterns and cor-\n", + "relation in enormous datasets. Unlike older types of AI (e.g. expert systems, \n", + "that are based on rules which are inputted by humans), machine learning algo-\n", + "rithms learn not from humans but from data. The availability of significant \n", + "amounts of real-world data (that we produce by using the internet, social media, \n", + "sensors or other Internet-of-Things applications), combined with the availabil-\n", + "ity of powerful and almost limitless computing capacity and advancements in\n", + "Document 3:\n", + "its from its associations with science and \n", + "statistics. Like them, it’s an approach that elevates quantitative analysis over \n", + "any other form of insight. But machine learning is all about prediction and not \n", + "about explanation. For machine learning, all that matters is generalisability; \n", + "does the pattern learned from training data perform well on test data, in which \n", + "case it can be let loose on the world.\n", + "When people talk about practical AI they mean machine learning as number \n", + "crunching, and not any of the symbolic attempts to seriously emulate human \n", + "reasoning that used to be called ‘strong AI’ . Even the term ‘learning’ has, at dif-\n", + "ferent times, meant a more profound attempt to understand the way we learn \n", + "as embodied beings with life experience (Marcus 2018). But these approaches \n", + "struggled to produce practical results, whereas the form of machine learning \n", + "that simply means improving with ‘experience’ (i.e., with data) has succeeded\n" + ] + } + ], + "source": [ + "for i, doc in enumerate(retrieved_docs2[:3]): # Display top 3 results\n", + " print(f\"Document {i+1}:\\n{doc.page_content[36:1000]}\") # Display content" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Final prompt prepared for GPT model.\n", + "What is python?\n", + "Use the following context to answer the question:\n", + "This is some example context.\n", + "Answer:\n" + ] + } + ], + "source": [ + "formatted_context2 = \"This is some example context.\"\n", + "\n", + "prompt2 = f\"\"\"What is python?\n", + "Use the following context to answer the question:\n", + "{formatted_context2}\n", + "Answer:\"\"\"\n", + "\n", + "print(\"Final prompt prepared for GPT model.\")\n", + "print(prompt2)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "# Set up GPT client and parameters\n", + "client = openai.OpenAI()\n", + "model_params = {\n", + " 'model': 'gpt-4o',\n", + " 'temperature': 0.5, # Increase creativity\n", + " 'max_tokens': 1024, # Allow for longer responses\n", + " 'top_p': 0.9, # Use nucleus sampling\n", + " 'frequency_penalty': 0.5, # Reduce repetition\n", + " 'presence_penalty': 0.5 # Encourage new topics\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "messages2 = [{'role': 'user', 'content': prompt2}]\n", + "completion2 = client.chat.completions.create(messages=messages2, **model_params, timeout=120)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python is a high-level, interpreted programming language known for its readability and simplicity. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Python is widely used for web development, data analysis, artificial intelligence, scientific computing, and more due to its extensive standard library and active community.\n" + ] + } + ], + "source": [ + "answer2 = completion2.choices[0].message.content\n", + "print(answer2)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [], + "source": [ + "def highlight_keywords2(text2, keywords2):\n", + " for keyword in keywords2:\n", + " text2 = text2.replace(keyword, colored(keyword, 'red', attrs=['bold']))\n", + " return text2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Snippet 1:\n", + "by a different approach to \u001b[1m\u001b[31mAI\u001b[0m known as \u001b[1m\u001b[31mmachine learning\u001b[0m. Machine learning is \n", + "often anthropomorphised, but it is at base the use of statistical methods, called \n", + "learning algorithms, to find patterns i\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], + "source": [ + "query_keywords2 = [\"machine learning\", \"AI\", \"data science\", \"neural networks\", \"python\"] # add your keywords\n", + "for i, doc2 in enumerate(retrieved_docs[:1]):\n", + " snippet2 = doc2.page_content[:200]\n", + " highlighted2 = highlight_keywords2(snippet2, query_keywords2)\n", + " print(f\"Snippet {i+1}:\\n{highlighted2}\\n{'-'*80}\")" + ] } ], "metadata": { @@ -687,7 +1244,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "llm", + "display_name": "base", "language": "python", "name": "python3" }, @@ -701,7 +1258,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.10" + "version": "3.13.5" } }, "nbformat": 4,