diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..f6b2e49 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b97c73c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +**/chroma_db_LAB/ \ No newline at end of file diff --git a/your-code/.DS_Store b/your-code/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/your-code/.DS_Store differ diff --git a/your-code/main.ipynb b/your-code/main.ipynb index e3a225a..8e29127 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -61,10 +61,184 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: langchain in /opt/homebrew/lib/python3.11/site-packages (1.2.10)\n", + "Requirement already satisfied: langchain_community in /opt/homebrew/lib/python3.11/site-packages (0.4.1)\n", + "Requirement already satisfied: pypdf in /opt/homebrew/lib/python3.11/site-packages (6.7.3)\n", + "Requirement already satisfied: langchain-core<2.0.0,>=1.2.10 in /opt/homebrew/lib/python3.11/site-packages (from langchain) (1.2.16)\n", + "Requirement already satisfied: langgraph<1.1.0,>=1.0.8 in /opt/homebrew/lib/python3.11/site-packages (from langchain) (1.0.9)\n", + "Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in /opt/homebrew/lib/python3.11/site-packages (from langchain) (2.12.5)\n", + "Requirement already satisfied: jsonpatch<2.0.0,>=1.33.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.10->langchain) (1.33)\n", + "Requirement already satisfied: langsmith<1.0.0,>=0.3.45 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.10->langchain) (0.7.7)\n", + "Requirement already satisfied: packaging>=23.2.0 in /Users/isishassan/Library/Python/3.11/lib/python/site-packages (from langchain-core<2.0.0,>=1.2.10->langchain) (26.0)\n", + "Requirement already satisfied: pyyaml<7.0.0,>=5.3.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.10->langchain) (6.0.3)\n", + "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.10->langchain) (9.1.4)\n", + "Requirement already satisfied: typing-extensions<5.0.0,>=4.7.0 in /Users/isishassan/Library/Python/3.11/lib/python/site-packages (from langchain-core<2.0.0,>=1.2.10->langchain) (4.15.0)\n", + "Requirement already satisfied: uuid-utils<1.0,>=0.12.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.10->langchain) (0.14.1)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /opt/homebrew/lib/python3.11/site-packages (from jsonpatch<2.0.0,>=1.33.0->langchain-core<2.0.0,>=1.2.10->langchain) (3.0.0)\n", + "Requirement already satisfied: langgraph-checkpoint<5.0.0,>=2.1.0 in /opt/homebrew/lib/python3.11/site-packages (from langgraph<1.1.0,>=1.0.8->langchain) (4.0.0)\n", + "Requirement already satisfied: langgraph-prebuilt<1.1.0,>=1.0.8 in /opt/homebrew/lib/python3.11/site-packages (from langgraph<1.1.0,>=1.0.8->langchain) (1.0.8)\n", + "Requirement already satisfied: langgraph-sdk<0.4.0,>=0.3.0 in /opt/homebrew/lib/python3.11/site-packages (from langgraph<1.1.0,>=1.0.8->langchain) (0.3.9)\n", + "Requirement already satisfied: xxhash>=3.5.0 in /opt/homebrew/lib/python3.11/site-packages (from langgraph<1.1.0,>=1.0.8->langchain) (3.6.0)\n", + "Requirement already satisfied: ormsgpack>=1.12.0 in /opt/homebrew/lib/python3.11/site-packages (from langgraph-checkpoint<5.0.0,>=2.1.0->langgraph<1.1.0,>=1.0.8->langchain) (1.12.2)\n", + "Requirement already satisfied: httpx>=0.25.2 in /opt/homebrew/lib/python3.11/site-packages (from langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.8->langchain) (0.28.1)\n", + "Requirement already satisfied: orjson>=3.11.5 in /opt/homebrew/lib/python3.11/site-packages (from langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.8->langchain) (3.11.7)\n", + "Requirement already satisfied: requests-toolbelt>=1.0.0 in /opt/homebrew/lib/python3.11/site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.10->langchain) (1.0.0)\n", + "Requirement already satisfied: requests>=2.0.0 in /opt/homebrew/lib/python3.11/site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.10->langchain) (2.32.5)\n", + "Requirement already satisfied: zstandard>=0.23.0 in /opt/homebrew/lib/python3.11/site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.10->langchain) (0.25.0)\n", + "Requirement already satisfied: anyio in /opt/homebrew/lib/python3.11/site-packages (from httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.8->langchain) (4.12.1)\n", + "Requirement already satisfied: certifi in /opt/homebrew/lib/python3.11/site-packages (from httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.8->langchain) (2026.2.25)\n", + "Requirement already satisfied: httpcore==1.* in /opt/homebrew/lib/python3.11/site-packages (from httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.8->langchain) (1.0.9)\n", + "Requirement already satisfied: idna in /opt/homebrew/lib/python3.11/site-packages (from httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.8->langchain) (3.11)\n", + "Requirement already satisfied: h11>=0.16 in /opt/homebrew/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.25.2->langgraph-sdk<0.4.0,>=0.3.0->langgraph<1.1.0,>=1.0.8->langchain) (0.16.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /opt/homebrew/lib/python3.11/site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.41.5 in /opt/homebrew/lib/python3.11/site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (2.41.5)\n", + "Requirement already satisfied: typing-inspection>=0.4.2 in /opt/homebrew/lib/python3.11/site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (0.4.2)\n", + "Requirement already satisfied: langchain-classic<2.0.0,>=1.0.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain_community) (1.0.1)\n", + "Requirement already satisfied: SQLAlchemy<3.0.0,>=1.4.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain_community) (2.0.47)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /opt/homebrew/lib/python3.11/site-packages (from langchain_community) (3.13.3)\n", + "Requirement already satisfied: dataclasses-json<0.7.0,>=0.6.7 in /opt/homebrew/lib/python3.11/site-packages (from langchain_community) (0.6.7)\n", + "Requirement already satisfied: pydantic-settings<3.0.0,>=2.10.1 in /opt/homebrew/lib/python3.11/site-packages (from langchain_community) (2.13.1)\n", + "Requirement already satisfied: httpx-sse<1.0.0,>=0.4.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain_community) (0.4.3)\n", + "Requirement already satisfied: numpy>=1.26.2 in /opt/homebrew/lib/python3.11/site-packages (from langchain_community) (2.4.2)\n", + "Requirement already satisfied: aiohappyeyeballs>=2.5.0 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (2.6.1)\n", + "Requirement already satisfied: aiosignal>=1.4.0 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.4.0)\n", + "Requirement already satisfied: attrs>=17.3.0 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (25.4.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.8.0)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (6.7.1)\n", + "Requirement already satisfied: propcache>=0.2.0 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (0.4.1)\n", + "Requirement already satisfied: yarl<2.0,>=1.17.0 in /opt/homebrew/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.22.0)\n", + "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /opt/homebrew/lib/python3.11/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 /opt/homebrew/lib/python3.11/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 /opt/homebrew/lib/python3.11/site-packages (from langchain-classic<2.0.0,>=1.0.0->langchain_community) (1.1.1)\n", + "Requirement already satisfied: python-dotenv>=0.21.0 in /opt/homebrew/lib/python3.11/site-packages (from pydantic-settings<3.0.0,>=2.10.1->langchain_community) (1.2.1)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /opt/homebrew/lib/python3.11/site-packages (from requests>=2.0.0->langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.10->langchain) (3.4.4)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/homebrew/lib/python3.11/site-packages (from requests>=2.0.0->langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.10->langchain) (2.6.3)\n", + "Requirement already satisfied: mypy-extensions>=0.3.0 in /opt/homebrew/lib/python3.11/site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7.0,>=0.6.7->langchain_community) (1.1.0)\n", + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m26.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m26.0.1\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49m/opt/homebrew/opt/python@3.11/bin/python3.11 -m pip install --upgrade pip\u001b[0m\n", + "Note: you may need to restart the kernel to use updated packages.\n", + "Requirement already satisfied: termcolor in /opt/homebrew/lib/python3.11/site-packages (3.3.0)\n", + "Requirement already satisfied: langchain_openai in /opt/homebrew/lib/python3.11/site-packages (1.1.10)\n", + "Requirement already satisfied: langchain-huggingface in /opt/homebrew/lib/python3.11/site-packages (1.2.0)\n", + "Requirement already satisfied: sentence-transformers in /opt/homebrew/lib/python3.11/site-packages (5.2.3)\n", + "Requirement already satisfied: chromadb in /opt/homebrew/lib/python3.11/site-packages (1.5.1)\n", + "Requirement already satisfied: langchain_chroma in /opt/homebrew/lib/python3.11/site-packages (1.1.0)\n", + "Requirement already satisfied: tiktoken in /opt/homebrew/lib/python3.11/site-packages (0.12.0)\n", + "Requirement already satisfied: openai in /opt/homebrew/lib/python3.11/site-packages (2.24.0)\n", + "Requirement already satisfied: python-dotenv in /opt/homebrew/lib/python3.11/site-packages (1.2.1)\n", + "Requirement already satisfied: langchain-core<2.0.0,>=1.2.13 in /opt/homebrew/lib/python3.11/site-packages (from langchain_openai) (1.2.16)\n", + "Requirement already satisfied: regex>=2022.1.18 in /opt/homebrew/lib/python3.11/site-packages (from tiktoken) (2026.2.19)\n", + "Requirement already satisfied: requests>=2.26.0 in /opt/homebrew/lib/python3.11/site-packages (from tiktoken) (2.32.5)\n", + "Requirement already satisfied: anyio<5,>=3.5.0 in /opt/homebrew/lib/python3.11/site-packages (from openai) (4.12.1)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /opt/homebrew/lib/python3.11/site-packages (from openai) (1.9.0)\n", + "Requirement already satisfied: httpx<1,>=0.23.0 in /opt/homebrew/lib/python3.11/site-packages (from openai) (0.28.1)\n", + "Requirement already satisfied: jiter<1,>=0.10.0 in /opt/homebrew/lib/python3.11/site-packages (from openai) (0.13.0)\n", + "Requirement already satisfied: pydantic<3,>=1.9.0 in /opt/homebrew/lib/python3.11/site-packages (from openai) (2.12.5)\n", + "Requirement already satisfied: sniffio in /opt/homebrew/lib/python3.11/site-packages (from openai) (1.3.1)\n", + "Requirement already satisfied: tqdm>4 in /opt/homebrew/lib/python3.11/site-packages (from openai) (4.67.3)\n", + "Requirement already satisfied: typing-extensions<5,>=4.11 in /Users/isishassan/Library/Python/3.11/lib/python/site-packages (from openai) (4.15.0)\n", + "Requirement already satisfied: idna>=2.8 in /opt/homebrew/lib/python3.11/site-packages (from anyio<5,>=3.5.0->openai) (3.11)\n", + "Requirement already satisfied: certifi in /opt/homebrew/lib/python3.11/site-packages (from httpx<1,>=0.23.0->openai) (2026.2.25)\n", + "Requirement already satisfied: httpcore==1.* in /opt/homebrew/lib/python3.11/site-packages (from httpx<1,>=0.23.0->openai) (1.0.9)\n", + "Requirement already satisfied: h11>=0.16 in /opt/homebrew/lib/python3.11/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 /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.13->langchain_openai) (1.33)\n", + "Requirement already satisfied: langsmith<1.0.0,>=0.3.45 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.13->langchain_openai) (0.7.7)\n", + "Requirement already satisfied: packaging>=23.2.0 in /Users/isishassan/Library/Python/3.11/lib/python/site-packages (from langchain-core<2.0.0,>=1.2.13->langchain_openai) (26.0)\n", + "Requirement already satisfied: pyyaml<7.0.0,>=5.3.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.13->langchain_openai) (6.0.3)\n", + "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.13->langchain_openai) (9.1.4)\n", + "Requirement already satisfied: uuid-utils<1.0,>=0.12.0 in /opt/homebrew/lib/python3.11/site-packages (from langchain-core<2.0.0,>=1.2.13->langchain_openai) (0.14.1)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /opt/homebrew/lib/python3.11/site-packages (from jsonpatch<2.0.0,>=1.33.0->langchain-core<2.0.0,>=1.2.13->langchain_openai) (3.0.0)\n", + "Requirement already satisfied: orjson>=3.9.14 in /opt/homebrew/lib/python3.11/site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.13->langchain_openai) (3.11.7)\n", + "Requirement already satisfied: requests-toolbelt>=1.0.0 in /opt/homebrew/lib/python3.11/site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.13->langchain_openai) (1.0.0)\n", + "Requirement already satisfied: xxhash>=3.0.0 in /opt/homebrew/lib/python3.11/site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.13->langchain_openai) (3.6.0)\n", + "Requirement already satisfied: zstandard>=0.23.0 in /opt/homebrew/lib/python3.11/site-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.13->langchain_openai) (0.25.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /opt/homebrew/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->openai) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.41.5 in /opt/homebrew/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->openai) (2.41.5)\n", + "Requirement already satisfied: typing-inspection>=0.4.2 in /opt/homebrew/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->openai) (0.4.2)\n", + "Requirement already satisfied: huggingface-hub<1.0.0,>=0.33.4 in /opt/homebrew/lib/python3.11/site-packages (from langchain-huggingface) (0.36.2)\n", + "Requirement already satisfied: tokenizers<1.0.0,>=0.19.1 in /opt/homebrew/lib/python3.11/site-packages (from langchain-huggingface) (0.22.2)\n", + "Requirement already satisfied: filelock in /opt/homebrew/lib/python3.11/site-packages (from huggingface-hub<1.0.0,>=0.33.4->langchain-huggingface) (3.24.3)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /opt/homebrew/lib/python3.11/site-packages (from huggingface-hub<1.0.0,>=0.33.4->langchain-huggingface) (2026.2.0)\n", + "Requirement already satisfied: hf-xet<2.0.0,>=1.1.3 in /opt/homebrew/lib/python3.11/site-packages (from huggingface-hub<1.0.0,>=0.33.4->langchain-huggingface) (1.3.1)\n", + "Requirement already satisfied: transformers<6.0.0,>=4.41.0 in /opt/homebrew/lib/python3.11/site-packages (from sentence-transformers) (4.57.6)\n", + "Requirement already satisfied: torch>=1.11.0 in /opt/homebrew/lib/python3.11/site-packages (from sentence-transformers) (2.10.0)\n", + "Requirement already satisfied: numpy in /opt/homebrew/lib/python3.11/site-packages (from sentence-transformers) (2.4.2)\n", + "Requirement already satisfied: scikit-learn in /opt/homebrew/lib/python3.11/site-packages (from sentence-transformers) (1.8.0)\n", + "Requirement already satisfied: scipy in /opt/homebrew/lib/python3.11/site-packages (from sentence-transformers) (1.17.1)\n", + "Requirement already satisfied: safetensors>=0.4.3 in /opt/homebrew/lib/python3.11/site-packages (from transformers<6.0.0,>=4.41.0->sentence-transformers) (0.7.0)\n", + "Requirement already satisfied: build>=1.0.3 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (1.4.0)\n", + "Requirement already satisfied: pybase64>=1.4.1 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (1.4.3)\n", + "Requirement already satisfied: uvicorn>=0.18.3 in /opt/homebrew/lib/python3.11/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.41.0)\n", + "Requirement already satisfied: posthog<6.0.0,>=2.4.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (5.4.0)\n", + "Requirement already satisfied: onnxruntime>=1.14.1 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (1.24.2)\n", + "Requirement already satisfied: opentelemetry-api>=1.2.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (1.39.1)\n", + "Requirement already satisfied: opentelemetry-exporter-otlp-proto-grpc>=1.2.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (1.39.1)\n", + "Requirement already satisfied: opentelemetry-sdk>=1.2.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (1.39.1)\n", + "Requirement already satisfied: pypika>=0.48.9 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (0.51.1)\n", + "Requirement already satisfied: overrides>=7.3.1 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (7.7.0)\n", + "Requirement already satisfied: importlib-resources in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (6.5.2)\n", + "Requirement already satisfied: grpcio>=1.58.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (1.78.0)\n", + "Requirement already satisfied: bcrypt>=4.0.1 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (5.0.0)\n", + "Requirement already satisfied: typer>=0.9.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (0.24.1)\n", + "Requirement already satisfied: kubernetes>=28.1.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (35.0.0)\n", + "Requirement already satisfied: mmh3>=4.0.1 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (5.2.0)\n", + "Requirement already satisfied: rich>=10.11.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (14.3.3)\n", + "Requirement already satisfied: jsonschema>=4.19.0 in /opt/homebrew/lib/python3.11/site-packages (from chromadb) (4.26.0)\n", + "Requirement already satisfied: six>=1.5 in /Users/isishassan/Library/Python/3.11/lib/python/site-packages (from posthog<6.0.0,>=2.4.0->chromadb) (1.17.0)\n", + "Requirement already satisfied: python-dateutil>=2.2 in /Users/isishassan/Library/Python/3.11/lib/python/site-packages (from posthog<6.0.0,>=2.4.0->chromadb) (2.9.0.post0)\n", + "Requirement already satisfied: backoff>=1.10.0 in /opt/homebrew/lib/python3.11/site-packages (from posthog<6.0.0,>=2.4.0->chromadb) (2.2.1)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /opt/homebrew/lib/python3.11/site-packages (from requests>=2.26.0->tiktoken) (3.4.4)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/homebrew/lib/python3.11/site-packages (from requests>=2.26.0->tiktoken) (2.6.3)\n", + "Requirement already satisfied: pyproject_hooks in /opt/homebrew/lib/python3.11/site-packages (from build>=1.0.3->chromadb) (1.2.0)\n", + "Requirement already satisfied: attrs>=22.2.0 in /opt/homebrew/lib/python3.11/site-packages (from jsonschema>=4.19.0->chromadb) (25.4.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /opt/homebrew/lib/python3.11/site-packages (from jsonschema>=4.19.0->chromadb) (2025.9.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /opt/homebrew/lib/python3.11/site-packages (from jsonschema>=4.19.0->chromadb) (0.37.0)\n", + "Requirement already satisfied: rpds-py>=0.25.0 in /opt/homebrew/lib/python3.11/site-packages (from jsonschema>=4.19.0->chromadb) (0.30.0)\n", + "Requirement already satisfied: websocket-client!=0.40.0,!=0.41.*,!=0.42.*,>=0.32.0 in /opt/homebrew/lib/python3.11/site-packages (from kubernetes>=28.1.0->chromadb) (1.9.0)\n", + "Requirement already satisfied: requests-oauthlib in /opt/homebrew/lib/python3.11/site-packages (from kubernetes>=28.1.0->chromadb) (2.0.0)\n", + "Requirement already satisfied: durationpy>=0.7 in /opt/homebrew/lib/python3.11/site-packages (from kubernetes>=28.1.0->chromadb) (0.10)\n", + "Requirement already satisfied: flatbuffers in /opt/homebrew/lib/python3.11/site-packages (from onnxruntime>=1.14.1->chromadb) (25.12.19)\n", + "Requirement already satisfied: protobuf in /opt/homebrew/lib/python3.11/site-packages (from onnxruntime>=1.14.1->chromadb) (6.33.5)\n", + "Requirement already satisfied: sympy in /opt/homebrew/lib/python3.11/site-packages (from onnxruntime>=1.14.1->chromadb) (1.14.0)\n", + "Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in /opt/homebrew/lib/python3.11/site-packages (from opentelemetry-api>=1.2.0->chromadb) (8.7.1)\n", + "Requirement already satisfied: zipp>=3.20 in /opt/homebrew/lib/python3.11/site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api>=1.2.0->chromadb) (3.23.0)\n", + "Requirement already satisfied: googleapis-common-protos~=1.57 in /opt/homebrew/lib/python3.11/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 /opt/homebrew/lib/python3.11/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 /opt/homebrew/lib/python3.11/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 /opt/homebrew/lib/python3.11/site-packages (from opentelemetry-sdk>=1.2.0->chromadb) (0.60b1)\n", + "Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/homebrew/lib/python3.11/site-packages (from rich>=10.11.0->chromadb) (4.0.0)\n", + "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/isishassan/Library/Python/3.11/lib/python/site-packages (from rich>=10.11.0->chromadb) (2.19.2)\n", + "Requirement already satisfied: mdurl~=0.1 in /opt/homebrew/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->chromadb) (0.1.2)\n", + "Requirement already satisfied: networkx>=2.5.1 in /opt/homebrew/lib/python3.11/site-packages (from torch>=1.11.0->sentence-transformers) (3.6.1)\n", + "Requirement already satisfied: jinja2 in /opt/homebrew/lib/python3.11/site-packages (from torch>=1.11.0->sentence-transformers) (3.1.6)\n", + "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /opt/homebrew/lib/python3.11/site-packages (from sympy->onnxruntime>=1.14.1->chromadb) (1.3.0)\n", + "Requirement already satisfied: click>=8.2.1 in /opt/homebrew/lib/python3.11/site-packages (from typer>=0.9.0->chromadb) (8.3.1)\n", + "Requirement already satisfied: shellingham>=1.3.0 in /opt/homebrew/lib/python3.11/site-packages (from typer>=0.9.0->chromadb) (1.5.4)\n", + "Requirement already satisfied: annotated-doc>=0.0.2 in /opt/homebrew/lib/python3.11/site-packages (from typer>=0.9.0->chromadb) (0.0.4)\n", + "Requirement already satisfied: httptools>=0.6.3 in /opt/homebrew/lib/python3.11/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.7.1)\n", + "Requirement already satisfied: uvloop>=0.15.1 in /opt/homebrew/lib/python3.11/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.22.1)\n", + "Requirement already satisfied: watchfiles>=0.20 in /opt/homebrew/lib/python3.11/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (1.1.1)\n", + "Requirement already satisfied: websockets>=10.4 in /opt/homebrew/lib/python3.11/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (16.0)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /opt/homebrew/lib/python3.11/site-packages (from jinja2->torch>=1.11.0->sentence-transformers) (3.0.3)\n", + "Requirement already satisfied: oauthlib>=3.0.0 in /opt/homebrew/lib/python3.11/site-packages (from requests-oauthlib->kubernetes>=28.1.0->chromadb) (3.3.1)\n", + "Requirement already satisfied: joblib>=1.3.0 in /opt/homebrew/lib/python3.11/site-packages (from scikit-learn->sentence-transformers) (1.5.3)\n", + "Requirement already satisfied: threadpoolctl>=3.2.0 in /opt/homebrew/lib/python3.11/site-packages (from scikit-learn->sentence-transformers) (3.6.0)\n", + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m26.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m26.0.1\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49m/opt/homebrew/opt/python@3.11/bin/python3.11 -m pip install --upgrade pip\u001b[0m\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" + "#%pip install langchain langchain_community pypdf\n", + "#%pip install termcolor langchain_openai langchain-huggingface sentence-transformers chromadb langchain_chroma tiktoken openai python-dotenv\n" ] }, { @@ -75,11 +249,30 @@ }, "outputs": [], "source": [ + "#this was provided in the lab, but has doesn't work\n", + "\"\"\"\n", "import os\n", "from langchain.document_loaders import PyPDFLoader\n", "from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter\n", "import warnings\n", - "warnings.filterwarnings('ignore')\n" + "warnings.filterwarnings('ignore')\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#this was provided in class this morning, will use instead\n", + "\n", + "from langchain_community.document_loaders import PyPDFLoader\n", + "from langchain_text_splitters import RecursiveCharacterTextSplitter\n", + "from langchain_openai import OpenAIEmbeddings, ChatOpenAI\n", + "from langchain_chroma import Chroma\n", + "import warnings\n", + "warnings.filterwarnings('ignore')" ] }, { @@ -96,7 +289,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "cuREtJRixYZt" }, @@ -122,15 +315,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "id": "_b5Z_45UxYZu", "outputId": "a600d69f-14fe-4492-f236-97261d6ff36c" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "297" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Load and split the document\n", - "loader = PyPDFLoader(file_path)\n", + "loader = PyPDFLoader(\"/Users/isishassan/Documents/Ironhack/Week7/Labs/Day5/lab-intro-rag/ai-for-everyone.pdf\")\n", "pages = loader.load_and_split()\n", "len(pages)" ] @@ -168,9 +372,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1096" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "text_splitter = RecursiveCharacterTextSplitter(\n", " chunk_size=1000,\n", @@ -285,31 +500,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "id": "L0xDxElwxYZw" }, "outputs": [], "source": [ - "from langchain.embeddings import OpenAIEmbeddings\n", + "#from langchain.embeddings import OpenAIEmbeddings\n", "from dotenv import load_dotenv" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "id": "_WRIo3_0xYZx", "outputId": "78bfbbf3-9d25-4e31-bdbc-3e932e6bbfec" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "load_dotenv()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "id": "MNZfTng5xYZz", "outputId": "db1a7c85-ef9f-447e-92cd-9d097e959847" @@ -317,7 +543,7 @@ "outputs": [], "source": [ "api_key = os.getenv(\"OPENAI_API_KEY\")\n", - "embeddings = OpenAIEmbeddings(model=\"text-embedding-3-large\")" + "embeddings = OpenAIEmbeddings(model=\"text-embedding-3-large\")\n" ] }, { @@ -347,19 +573,39 @@ "metadata": { "id": "brKe6wUgxYZ0" }, - "outputs": [], + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'langchain.vectorstores'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[23]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mlangchain\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mvectorstores\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Chroma\n", + "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'langchain.vectorstores'" + ] + } + ], "source": [ - "from langchain.vectorstores import Chroma" + "#from langchain.vectorstores import Chroma" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "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,28 +629,74 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "id": "XiLv-TfrxYZ1" }, "outputs": [], "source": [ - "user_question = \"\" # User question\n", - "retrieved_docs = db.similarity_search(user_question, k=10) # k is the number of documents to retrieve" + "user_question = \"What are ethical concerns with AI?\" # User question\n", + "retrieved_docs = db.similarity_search(user_question, k=5) # k is the number of documents to retrieve. IH: set to 5" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "id": "qgWsh50JxYZ1", "outputId": "c8640c5d-5955-471f-fdd2-37096f5f68c7" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Document 1:\n", + "ous and problematic uses of the technol -\n", + "ogy, which has prompted a global conversation on the normative principles \n", + "to which AI ought adhere, under the banner of ‘AI ethics’ . Governments, cor-\n", + "porations and NGOs throughout the world have generated their own sets of \n", + "AI ethics principles. Questions and critiques arise about the content of these \n", + "ethics principles, whether they are actually implemented, and their (legal) \n", + "enforceability (Wagner 2018). Broader issues emerge about the power and \n", + "privilege of the organisations, governments and individuals which are creat -\n", + "ing and implementing AI and accompanying ethical principles. For example, \n", + "Google has recently announced an ethics service (Simonite 2020), yet has been \n", + "mired in ethics controversies from violating privacy law (Finley 2019), work -\n", + "ing on controversial military projects (Crofts and van Rijswijk 2020) and dis -\n", + "Document 2:\n", + " we also see in the US, the mere fact of AI ethics principles hav-\n", + "ing the binding force of law is insufficient to establish their ‘goodness’ .\n", + "It is also insufficient to focus solely on social norms in the form of unen -\n", + "forceable ethical principles as these can indeed result in ethics washing. We \n", + "agree with Powles and Nissenbaum (2018) who see a focus on ‘solving’ issues \n", + "of fairness, accountability and transparency as foremost among these discus -\n", + "sions through code (and to some extent social norms) as problematic, and one \n", + "which obscures the broader structural problems which are at the root of bias \n", + "in machine learning. Again, Ihde’s critique of the ‘designer fallacy’ mentioned \n", + "above also applies here regarding the unintended consequences of attempting \n", + "to ‘design out’ bias and other problems in digital technologies. Furthermore, \n", + "broader existential questions about whether a particular system or technol -\n", + "Document 3:\n", + "loped. This concept is the result of an open \n", + "consultation and its ethics guidelines have been presented by the High-Level \n", + "Expert Group of AI . According to these guidelines, trustworthy AI should be: \n", + "(1) lawful (respecting all applicable laws and regulations); (2) ethical (respect \n", + "ethical principles and values); and (3) robust (both from a technical perspec -\n", + "tive while taking into account its social environment) (European Commission \n", + "2019). These aspects are vague ( how is something ethical or robust exactly?) \n", + "as well as self-evident (very few people would favour unlawful AI). The EU, \n", + "however, has made these guidelines more explicit by formulating specific aims: \n", + "human agency/oversight, technical robustness/safety, privacy/data governance, \n", + "transparency, diversity/non-discrimination/fairness, societal/environmental \n", + "well-being and accountability. This is helpful as the list of specific aims can be\n" + ] + } + ], "source": [ "# Display top results\n", "for i, doc in enumerate(retrieved_docs[:3]): # Display top 3 results\n", - " print(f\"Document {i+1}:\\n{doc.page_content[36:1000]}\") # Display content" + " print(f\"Document {i+1}:\\n{doc.page_content[36:1000]}\") # Display content #why 36:1000" ] }, { @@ -419,6 +711,13 @@ { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 29, "metadata": { "id": "2iB3lZqHxYZ2" }, @@ -434,12 +733,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "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,7 +771,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": { "id": "tqxVh9s3xYZ3", "outputId": "97cca95d-4ab3-44d8-a76c-5713aad387d8" @@ -472,14 +779,50 @@ "outputs": [], "source": [ "prompt = f\"\"\"\n", + "## SYSTEM ROLE\n", + "You are a knowledgeable and factual chatbot designed to assist with general and technical questions about **AI**.\n", + "Your answers must be based exclusively on provided content.\n", + "\n", + "## USER QUESTION\n", + "The user has asked:\n", + "\"{user_question}\"\n", + "\n", + "## CONTEXT\n", + "Here is the relevant content from the technical books:\n", + "'''\n", + "{formatted_context}\n", + "'''\n", "\n", + "## GUIDELINES\n", + "1. **Accuracy**:\n", + " - Only use the content in the `CONTEXT` section to answer.\n", + " - If the answer cannot be found, explicitly state: \"The provided context does not contain this information.\"\n", "\n", - "\"\"\"\n" + "2. **Transparency and Clarity**:\n", + " - Reference the book's name and page numbers when providing information.\n", + " - Do not speculate or provide opinions.\n", + " - Use simple, professional, and concise language.\n", + "\n", + "## TASK\n", + "1. Answer the user's question **directly** if possible.\n", + "2. Point the user to relevant parts of the documentation.\n", + "3. Provide the response in the following format:\n", + "\n", + "## RESPONSE FORMAT\n", + "'''\n", + "# [Brief Title of the Answer]\n", + "[Answer in simple, clear text.]\n", + "\n", + "**Source**:\n", + "• [Book Title], Page(s): [...]\n", + "'''\n", + "\n", + "\"\"\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": { "id": "0mjkQJ_ZxYZ3" }, @@ -497,7 +840,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": { "id": "ylypRWRlxYZ4" }, @@ -506,12 +849,12 @@ "# Set up GPT client and parameters\n", "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", + " 'model': 'gpt-4.1-nano',\n", + " 'temperature': 0.8, # Increase creativity\n", + " 'max_tokens': 500, # Allow for longer responses\n", + " 'top_p': 0.9, # Use nucleus sampling\n", + " 'frequency_penalty': 0.9, # Reduce repetition\n", + " 'presence_penalty': 0.9 # Encourage new topics\n", "}" ] }, @@ -526,7 +869,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": { "id": "4eXZO4pIxYZ4" }, @@ -538,12 +881,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": { "id": "wLPAcchBxYZ5", "outputId": "976c7800-16ed-41fe-c4cf-58f60d3230d2" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "# Ethical Concerns with AI\n", + "The main ethical concerns include the potential for dangerous and problematic uses of AI, issues related to privacy violations, bias and unfairness in machine learning systems, lack of effective enforcement of ethics principles, and broader structural problems such as power imbalances among organizations developing AI. There are also concerns about \"ethics washing,\" where principles are declared but not effectively implemented or enforceable. Additionally, questions arise about whether ethical guidelines sufficiently address issues like transparency, accountability, fairness, societal well-being, and respect for human agency.\n", + "\n", + "**Source**:\n", + "• [Content], Pages: 114-115\n" + ] + } + ], "source": [ "answer = completion.choices[0].message.content\n", "print(answer)" @@ -595,7 +950,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": { "id": "nCXL9Cz1xYaV" }, @@ -615,7 +970,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": { "id": "9y3E0YWExYaV" }, @@ -641,9 +996,21 @@ "id": "i7SkWPpnxYaW", "outputId": "28e82563-edba-4b41-acad-ec27e5ba134f" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Snippet 1:\n", + "poses, there is concern about dangerous and problematic uses of the technol -\n", + "ogy, which has prompted a global conversation on the normative principles \n", + "to which AI ought adhere, under the banner of ‘\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], "source": [ - "query_keywords = [] # add your keywords\n", + "query_keywords = [\"accountability\",\"bias\"] # add your keywords\n", "for i, doc in enumerate(retrieved_docs[:1]):\n", " snippet = doc.page_content[:200]\n", " highlighted = highlight_keywords(snippet, query_keywords)\n", @@ -687,7 +1054,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "llm", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -701,7 +1068,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.10" + "version": "3.11.14" } }, "nbformat": 4,