{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "AI Engineering Bootcamp Cohort 4 Midterm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Install our key components for RAG etc" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: langchain-core==0.2.27 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (0.2.27)\n", "Requirement already satisfied: langchain-community==0.2.10 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (0.2.10)\n", "Requirement already satisfied: PyYAML>=5.3 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core==0.2.27) (6.0.1)\n", "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core==0.2.27) (1.33)\n", "Requirement already satisfied: langsmith<0.2.0,>=0.1.75 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core==0.2.27) (0.1.122)\n", "Requirement already satisfied: packaging<25,>=23.2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core==0.2.27) (24.1)\n", "Requirement already satisfied: pydantic<3,>=1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core==0.2.27) (2.8.2)\n", "Requirement already satisfied: tenacity!=8.4.0,<9.0.0,>=8.1.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core==0.2.27) (8.5.0)\n", "Requirement already satisfied: typing-extensions>=4.7 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core==0.2.27) (4.11.0)\n", "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community==0.2.10) (2.0.32)\n", "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community==0.2.10) (3.10.3)\n", "Requirement already satisfied: dataclasses-json<0.7,>=0.5.7 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community==0.2.10) (0.5.14)\n", "Requirement already satisfied: langchain<0.3.0,>=0.2.9 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community==0.2.10) (0.2.12)\n", "Requirement already satisfied: numpy<2,>=1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community==0.2.10) (1.26.4)\n", "Requirement already satisfied: requests<3,>=2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community==0.2.10) (2.32.3)\n", "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.2.10) (2.3.5)\n", "Requirement already satisfied: aiosignal>=1.1.2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.2.10) (1.3.1)\n", "Requirement already satisfied: attrs>=17.3.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.2.10) (24.2.0)\n", "Requirement already satisfied: frozenlist>=1.1.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.2.10) (1.4.1)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.2.10) (6.0.5)\n", "Requirement already satisfied: yarl<2.0,>=1.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.2.10) (1.9.4)\n", "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain-community==0.2.10) (3.21.3)\n", "Requirement already satisfied: typing-inspect<1,>=0.4.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain-community==0.2.10) (0.9.0)\n", "Requirement already satisfied: jsonpointer>=1.9 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain-core==0.2.27) (3.0.0)\n", "Requirement already satisfied: langchain-text-splitters<0.3.0,>=0.2.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain<0.3.0,>=0.2.9->langchain-community==0.2.10) (0.2.2)\n", "Requirement already satisfied: httpx<1,>=0.23.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.75->langchain-core==0.2.27) (0.27.0)\n", "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.75->langchain-core==0.2.27) (3.10.7)\n", "Requirement already satisfied: annotated-types>=0.4.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from pydantic<3,>=1->langchain-core==0.2.27) (0.7.0)\n", "Requirement already satisfied: pydantic-core==2.20.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from pydantic<3,>=1->langchain-core==0.2.27) (2.20.1)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from requests<3,>=2->langchain-community==0.2.10) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from requests<3,>=2->langchain-community==0.2.10) (3.7)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from requests<3,>=2->langchain-community==0.2.10) (2.2.2)\n", "Requirement already satisfied: certifi>=2017.4.17 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from requests<3,>=2->langchain-community==0.2.10) (2024.8.30)\n", "Requirement already satisfied: greenlet!=0.4.17 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from SQLAlchemy<3,>=1.4->langchain-community==0.2.10) (3.0.3)\n", "Requirement already satisfied: anyio in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.75->langchain-core==0.2.27) (3.7.1)\n", "Requirement already satisfied: httpcore==1.* in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.75->langchain-core==0.2.27) (1.0.5)\n", "Requirement already satisfied: sniffio in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.75->langchain-core==0.2.27) (1.3.0)\n", "Requirement already satisfied: h11<0.15,>=0.13 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.75->langchain-core==0.2.27) (0.14.0)\n", "Requirement already satisfied: mypy-extensions>=0.3.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain-community==0.2.10) (1.0.0)\n", "Requirement already satisfied: langchain-experimental==0.0.64 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (0.0.64)\n", "Requirement already satisfied: langgraph-checkpoint==1.0.6 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (1.0.6)\n", "Requirement already satisfied: langgraph==0.2.16 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (0.2.16)\n", "Requirement already satisfied: langchain-qdrant==0.1.3 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (0.1.3)\n", "Requirement already satisfied: langchain-community<0.3.0,>=0.2.10 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-experimental==0.0.64) (0.2.10)\n", "Requirement already satisfied: langchain-core<0.3.0,>=0.2.27 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-experimental==0.0.64) (0.2.27)\n", "Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-qdrant==0.1.3) (2.8.2)\n", "Requirement already satisfied: qdrant-client<2.0.0,>=1.10.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-qdrant==0.1.3) (1.11.2)\n", "Requirement already satisfied: PyYAML>=5.3 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (6.0.1)\n", "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (2.0.32)\n", "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (3.10.3)\n", "Requirement already satisfied: dataclasses-json<0.7,>=0.5.7 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (0.5.14)\n", "Requirement already satisfied: langchain<0.3.0,>=0.2.9 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (0.2.12)\n", "Requirement already satisfied: langsmith<0.2.0,>=0.1.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (0.1.122)\n", "Requirement already satisfied: numpy<2,>=1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (1.26.4)\n", "Requirement already satisfied: requests<3,>=2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (2.32.3)\n", "Requirement already satisfied: tenacity!=8.4.0,<9.0.0,>=8.1.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (8.5.0)\n", "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3.0,>=0.2.27->langchain-experimental==0.0.64) (1.33)\n", "Requirement already satisfied: packaging<25,>=23.2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3.0,>=0.2.27->langchain-experimental==0.0.64) (24.1)\n", "Requirement already satisfied: typing-extensions>=4.7 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3.0,>=0.2.27->langchain-experimental==0.0.64) (4.11.0)\n", "Requirement already satisfied: annotated-types>=0.4.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from pydantic<3.0.0,>=2.7.4->langchain-qdrant==0.1.3) (0.7.0)\n", "Requirement already satisfied: pydantic-core==2.20.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from pydantic<3.0.0,>=2.7.4->langchain-qdrant==0.1.3) (2.20.1)\n", "Requirement already satisfied: grpcio>=1.41.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (1.66.1)\n", "Requirement already satisfied: grpcio-tools>=1.41.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (1.66.1)\n", "Requirement already satisfied: httpx>=0.20.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (0.27.0)\n", "Requirement already satisfied: portalocker<3.0.0,>=2.7.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (2.10.1)\n", "Requirement already satisfied: urllib3<3,>=1.26.14 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (2.2.2)\n", "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (2.3.5)\n", "Requirement already satisfied: aiosignal>=1.1.2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (1.3.1)\n", "Requirement already satisfied: attrs>=17.3.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (24.2.0)\n", "Requirement already satisfied: frozenlist>=1.1.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (1.4.1)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (6.0.5)\n", "Requirement already satisfied: yarl<2.0,>=1.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (1.9.4)\n", "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (3.21.3)\n", "Requirement already satisfied: typing-inspect<1,>=0.4.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (0.9.0)\n", "Requirement already satisfied: protobuf<6.0dev,>=5.26.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from grpcio-tools>=1.41.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (5.28.0)\n", "Requirement already satisfied: setuptools in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from grpcio-tools>=1.41.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (74.0.0)\n", "Requirement already satisfied: anyio in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (3.7.1)\n", "Requirement already satisfied: certifi in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (2024.8.30)\n", "Requirement already satisfied: httpcore==1.* in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (1.0.5)\n", "Requirement already satisfied: idna in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (3.7)\n", "Requirement already satisfied: sniffio in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (1.3.0)\n", "Requirement already satisfied: h11<0.15,>=0.13 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (0.14.0)\n", "Requirement already satisfied: h2<5,>=3 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (4.1.0)\n", "Requirement already satisfied: jsonpointer>=1.9 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.27->langchain-experimental==0.0.64) (3.0.0)\n", "Requirement already satisfied: langchain-text-splitters<0.3.0,>=0.2.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain<0.3.0,>=0.2.9->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (0.2.2)\n", "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.0->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (3.10.7)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from requests<3,>=2->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (3.3.2)\n", "Requirement already satisfied: greenlet!=0.4.17 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from SQLAlchemy<3,>=1.4->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (3.0.3)\n", "Requirement already satisfied: hyperframe<7,>=6.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (6.0.1)\n", "Requirement already satisfied: hpack<5,>=4.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client<2.0.0,>=1.10.1->langchain-qdrant==0.1.3) (4.0.0)\n", "Requirement already satisfied: mypy-extensions>=0.3.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain-community<0.3.0,>=0.2.10->langchain-experimental==0.0.64) (1.0.0)\n", "Requirement already satisfied: langchain-openai==0.1.9 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (0.1.9)\n", "Requirement already satisfied: langchain-core<0.3,>=0.2.2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-openai==0.1.9) (0.2.27)\n", "Requirement already satisfied: openai<2.0.0,>=1.26.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-openai==0.1.9) (1.44.0)\n", "Requirement already satisfied: tiktoken<1,>=0.7 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-openai==0.1.9) (0.7.0)\n", "Requirement already satisfied: PyYAML>=5.3 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (6.0.1)\n", "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (1.33)\n", "Requirement already satisfied: langsmith<0.2.0,>=0.1.75 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (0.1.122)\n", "Requirement already satisfied: packaging<25,>=23.2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (24.1)\n", "Requirement already satisfied: pydantic<3,>=1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (2.8.2)\n", "Requirement already satisfied: tenacity!=8.4.0,<9.0.0,>=8.1.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (8.5.0)\n", "Requirement already satisfied: typing-extensions>=4.7 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (4.11.0)\n", "Requirement already satisfied: anyio<5,>=3.5.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (3.7.1)\n", "Requirement already satisfied: distro<2,>=1.7.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (1.9.0)\n", "Requirement already satisfied: httpx<1,>=0.23.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (0.27.0)\n", "Requirement already satisfied: jiter<1,>=0.4.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (0.5.0)\n", "Requirement already satisfied: sniffio in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (1.3.0)\n", "Requirement already satisfied: tqdm>4 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (4.66.5)\n", "Requirement already satisfied: regex>=2022.1.18 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from tiktoken<1,>=0.7->langchain-openai==0.1.9) (2024.7.24)\n", "Requirement already satisfied: requests>=2.26.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from tiktoken<1,>=0.7->langchain-openai==0.1.9) (2.32.3)\n", "Requirement already satisfied: idna>=2.8 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from anyio<5,>=3.5.0->openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (3.7)\n", "Requirement already satisfied: certifi in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx<1,>=0.23.0->openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (2024.8.30)\n", "Requirement already satisfied: httpcore==1.* in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpx<1,>=0.23.0->openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (1.0.5)\n", "Requirement already satisfied: h11<0.15,>=0.13 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai<2.0.0,>=1.26.0->langchain-openai==0.1.9) (0.14.0)\n", "Requirement already satisfied: jsonpointer>=1.9 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (3.0.0)\n", "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.75->langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (3.10.7)\n", "Requirement already satisfied: annotated-types>=0.4.0 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from pydantic<3,>=1->langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (0.7.0)\n", "Requirement already satisfied: pydantic-core==2.20.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from pydantic<3,>=1->langchain-core<0.3,>=0.2.2->langchain-openai==0.1.9) (2.20.1)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from requests>=2.26.0->tiktoken<1,>=0.7->langchain-openai==0.1.9) (3.3.2)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages (from requests>=2.26.0->tiktoken<1,>=0.7->langchain-openai==0.1.9) (2.2.2)\n" ] } ], "source": [ "!pip install langchain-core==0.2.27 langchain-community==0.2.10\n", "!pip install langchain-experimental==0.0.64 langgraph-checkpoint==1.0.6 langgraph==0.2.16 langchain-qdrant==0.1.3\n", "!pip install langchain-openai==0.1.9" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Install our vector store - Qdrant" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "ename": "", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31mThe kernel failed to start as the Python Environment 'Python' is no longer available. Consider selecting another kernel or refreshing the list of Python Environments." ] } ], "source": [ "!pip install -qU qdrant-client" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Install supporting utilities" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "!pip install -qU tiktoken pymupdf\n", "from langchain_community.document_loaders import PyMuPDFLoader" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Environment Variables\n", "\n", "- get OpenAI API Key - will use some of the OpenAI models" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import os\n", "import getpass\n", "\n", "os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of pages in 1: 73\n", "Number of pages in 2: 64\n", "Title of Document 1: Blueprint for an AI Bill of Rights\n", "Title of Document 2: Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile\n", "Full metadata for Document 1: {'format': 'PDF 1.6', 'title': 'Blueprint for an AI Bill of Rights', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Adobe Illustrator 26.3 (Macintosh)', 'producer': 'iLovePDF', 'creationDate': \"D:20220920133035-04'00'\", 'modDate': \"D:20221003104118-04'00'\", 'trapped': '', 'encryption': None}\n", "Full metadata for Document 2: {'format': 'PDF 1.6', 'title': 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile', 'author': 'National Institute of Standards and Technology', 'subject': '', 'keywords': '', 'creator': 'Acrobat PDFMaker 24 for Word', 'producer': 'Adobe PDF Library 24.2.159', 'creationDate': \"D:20240805141702-04'00'\", 'modDate': \"D:20240805143048-04'00'\", 'trapped': '', 'encryption': None}\n", "Number of chunks for Document 1: 61\n", "Number of chunks for Document 2: 53\n" ] } ], "source": [ "\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of pages in 1: 73\n", "Number of pages in 2: 64\n", "Title of Document 1: Blueprint for an AI Bill of Rights\n", "Title of Document 2: Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile\n", "Full metadata for Document 1: {'format': 'PDF 1.6', 'title': 'Blueprint for an AI Bill of Rights', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Adobe Illustrator 26.3 (Macintosh)', 'producer': 'iLovePDF', 'creationDate': \"D:20220920133035-04'00'\", 'modDate': \"D:20221003104118-04'00'\", 'trapped': '', 'encryption': None}\n", "Full metadata for Document 2: {'format': 'PDF 1.6', 'title': 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile', 'author': 'National Institute of Standards and Technology', 'subject': '', 'keywords': '', 'creator': 'Acrobat PDFMaker 24 for Word', 'producer': 'Adobe PDF Library 24.2.159', 'creationDate': \"D:20240805141702-04'00'\", 'modDate': \"D:20240805143048-04'00'\", 'trapped': '', 'encryption': None}\n", "Number of chunks for Document 1: 61\n", "Number of chunks for Document 2: 53\n" ] } ], "source": [ "from utilities.rag_utilities import create_vector_store\n", "\n", "qdrant_retriever = create_vector_store()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Test it" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "You should be protected from abusive data practices via built-in \n", "protections and you should have agency over how data about \n", "you is used. You should be protected from violations of privacy through \n", "design choices that ensure such protections are included by default, including \n", "ensuring that data collection conforms to reasonable expectations and that \n", "only data strictly necessary for the specific context is collected. Designers, de­\n", "velopers, and deployers of automated systems should seek your permission \n", "and respect your decisions regarding collection, use, access, transfer, and de­\n", "letion of your data in appropriate ways and to the greatest extent possible; \n", "where not possible, alternative privacy by design safeguards should be used. \n", "Systems should not employ user experience and design decisions that obfus­\n", "cate user choice or burden users with defaults that are privacy invasive. Con­\n", "sent should only be used to justify collection of data in cases where it can be \n", "appropriately and meaningfully given. Any consent requests should be brief, \n", "be understandable in plain language, and give you agency over data collection \n", "and the specific context of use; current hard-to-understand no­\n", "tice-and-choice practices for broad uses of data should be changed. Enhanced \n", "protections and restrictions for data and inferences related to sensitive do­\n", "mains, including health, work, education, criminal justice, and finance, and \n", "for data pertaining to youth should put you first. In sensitive domains, your \n", "data and related inferences should only be used for necessary functions, and \n", "you should be protected by ethical review and use prohibitions. You and your \n", "communities should be free from unchecked surveillance; surveillance tech­\n", "nologies should be subject to heightened oversight that includes at least \n", "pre-deployment assessment of their potential harms and scope limits to pro­\n", "tect privacy and civil liberties. Continuous surveillance and monitoring \n", "should not be used in education, work, housing, or in other contexts where the \n", "use of such surveillance technologies is likely to limit rights, opportunities, or \n", "access. Whenever possible, you should have access to reporting that confirms \n", "your data decisions have been respected and provides an assessment of the \n", "potential impact of surveillance technologies on your rights, opportunities, or \n", "access. \n", "DATA PRIVACY\n", "30\n", "{'source': 'Blueprint for an AI Bill of Rights', 'document_id': 'doc1', '_id': 'c7bb1309f85f46c7b5d1c7511523cb10', '_collection_name': 'ffb2f8aece51430086938e04161466e4'}\n", "---\n", "You should be protected from abusive data practices via built-in \n", "protections and you should have agency over how data about \n", "you is used. You should be protected from violations of privacy through \n", "design choices that ensure such protections are included by default, including \n", "ensuring that data collection conforms to reasonable expectations and that \n", "only data strictly necessary for the specific context is collected. Designers, de­\n", "velopers, and deployers of automated systems should seek your permission \n", "and respect your decisions regarding collection, use, access, transfer, and de­\n", "letion of your data in appropriate ways and to the greatest extent possible; \n", "where not possible, alternative privacy by design safeguards should be used. \n", "Systems should not employ user experience and design decisions that obfus­\n", "cate user choice or burden users with defaults that are privacy invasive. Con­\n", "sent should only be used to justify collection of data in cases where it can be \n", "appropriately and meaningfully given. Any consent requests should be brief, \n", "be understandable in plain language, and give you agency over data collection \n", "and the specific context of use; current hard-to-understand no­\n", "tice-and-choice practices for broad uses of data should be changed. Enhanced \n", "protections and restrictions for data and inferences related to sensitive do­\n", "mains, including health, work, education, criminal justice, and finance, and \n", "for data pertaining to youth should put you first. In sensitive domains, your \n", "data and related inferences should only be used for necessary functions, and \n", "you should be protected by ethical review and use prohibitions. You and your \n", "communities should be free from unchecked surveillance; surveillance tech­\n", "nologies should be subject to heightened oversight that includes at least \n", "pre-deployment assessment of their potential harms and scope limits to pro­\n", "tect privacy and civil liberties. Continuous surveillance and monitoring \n", "should not be used in education, work, housing, or in other contexts where the \n", "use of such surveillance technologies is likely to limit rights, opportunities, or \n", "access. Whenever possible, you should have access to reporting that confirms \n", "your data decisions have been respected and provides an assessment of the \n", "potential impact of surveillance technologies on your rights, opportunities, or \n", "access. \n", "DATA PRIVACY\n", "30\n", "{'source': 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile', 'document_id': 'doc2', '_id': '3969630587ab4c199e299edfb92905b5', '_collection_name': 'ffb2f8aece51430086938e04161466e4'}\n", "---\n", "DATA PRIVACY \n", "WHAT SHOULD BE EXPECTED OF AUTOMATED SYSTEMS\n", "The expectations for automated systems are meant to serve as a blueprint for the development of additional \n", "technical standards and practices that are tailored for particular sectors and contexts. \n", "Traditional terms of service—the block of text that the public is accustomed to clicking through when using a web­\n", "site or digital app—are not an adequate mechanism for protecting privacy. The American public should be protect­\n", "ed via built-in privacy protections, data minimization, use and collection limitations, and transparency, in addition \n", "to being entitled to clear mechanisms to control access to and use of their data—including their metadata—in a \n", "proactive, informed, and ongoing way. Any automated system collecting, using, sharing, or storing personal data \n", "should meet these expectations. \n", "Protect privacy by design and by default \n", "Privacy by design and by default. Automated systems should be designed and built with privacy protect­\n", "ed by default. Privacy risks should be assessed throughout the development life cycle, including privacy risks \n", "from reidentification, and appropriate technical and policy mitigation measures should be implemented. This \n", "includes potential harms to those who are not users of the automated system, but who may be harmed by \n", "inferred data, purposeful privacy violations, or community surveillance or other community harms. Data \n", "collection should be minimized and clearly communicated to the people whose data is collected. Data should \n", "only be collected or used for the purposes of training or testing machine learning models if such collection and \n", "use is legal and consistent with the expectations of the people whose data is collected. User experience \n", "research should be conducted to confirm that people understand what data is being collected about them and \n", "how it will be used, and that this collection matches their expectations and desires. \n", "Data collection and use-case scope limits. Data collection should be limited in scope, with specific, \n", "narrow identified goals, to avoid \"mission creep.\" Anticipated data collection should be determined to be \n", "strictly necessary to the identified goals and should be minimized as much as possible. Data collected based on \n", "these identified goals and for a specific context should not be used in a different context without assessing for \n", "new privacy risks and implementing appropriate mitigation measures, which may include express consent. \n", "Clear timelines for data retention should be established, with data deleted as soon as possible in accordance \n", "with legal or policy-based limitations. Determined data retention timelines should be documented and justi­\n", "fied. \n", "Risk identification and mitigation. Entities that collect, use, share, or store sensitive data should \n", "attempt to proactively identify harms and seek to manage them so as to avoid, mitigate, and respond appropri­\n", "ately to identified risks. Appropriate responses include determining not to process data when the privacy risks \n", "outweigh the benefits or implementing measures to mitigate acceptable risks. Appropriate responses do not \n", "include sharing or transferring the privacy risks to users via notice or consent requests where users could not \n", "reasonably be expected to understand the risks without further support. \n", "Privacy-preserving security. Entities creating, using, or governing automated systems should follow \n", "privacy and security best practices designed to ensure data and metadata do not leak beyond the specific \n", "consented use case. Best practices could include using privacy-enhancing cryptography or other types of \n", "privacy-enhancing technologies or fine-grained permissions and access control mechanisms, along with \n", "conventional system security protocols. \n", "33\n", "{'source': 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile', 'document_id': 'doc2', '_id': '382b9ef10528494a85b60231a0d0981b', '_collection_name': 'ffb2f8aece51430086938e04161466e4'}\n", "---\n", "DATA PRIVACY \n", "WHAT SHOULD BE EXPECTED OF AUTOMATED SYSTEMS\n", "The expectations for automated systems are meant to serve as a blueprint for the development of additional \n", "technical standards and practices that are tailored for particular sectors and contexts. \n", "Traditional terms of service—the block of text that the public is accustomed to clicking through when using a web­\n", "site or digital app—are not an adequate mechanism for protecting privacy. The American public should be protect­\n", "ed via built-in privacy protections, data minimization, use and collection limitations, and transparency, in addition \n", "to being entitled to clear mechanisms to control access to and use of their data—including their metadata—in a \n", "proactive, informed, and ongoing way. Any automated system collecting, using, sharing, or storing personal data \n", "should meet these expectations. \n", "Protect privacy by design and by default \n", "Privacy by design and by default. Automated systems should be designed and built with privacy protect­\n", "ed by default. Privacy risks should be assessed throughout the development life cycle, including privacy risks \n", "from reidentification, and appropriate technical and policy mitigation measures should be implemented. This \n", "includes potential harms to those who are not users of the automated system, but who may be harmed by \n", "inferred data, purposeful privacy violations, or community surveillance or other community harms. Data \n", "collection should be minimized and clearly communicated to the people whose data is collected. Data should \n", "only be collected or used for the purposes of training or testing machine learning models if such collection and \n", "use is legal and consistent with the expectations of the people whose data is collected. User experience \n", "research should be conducted to confirm that people understand what data is being collected about them and \n", "how it will be used, and that this collection matches their expectations and desires. \n", "Data collection and use-case scope limits. Data collection should be limited in scope, with specific, \n", "narrow identified goals, to avoid \"mission creep.\" Anticipated data collection should be determined to be \n", "strictly necessary to the identified goals and should be minimized as much as possible. Data collected based on \n", "these identified goals and for a specific context should not be used in a different context without assessing for \n", "new privacy risks and implementing appropriate mitigation measures, which may include express consent. \n", "Clear timelines for data retention should be established, with data deleted as soon as possible in accordance \n", "with legal or policy-based limitations. Determined data retention timelines should be documented and justi­\n", "fied. \n", "Risk identification and mitigation. Entities that collect, use, share, or store sensitive data should \n", "attempt to proactively identify harms and seek to manage them so as to avoid, mitigate, and respond appropri­\n", "ately to identified risks. Appropriate responses include determining not to process data when the privacy risks \n", "outweigh the benefits or implementing measures to mitigate acceptable risks. Appropriate responses do not \n", "include sharing or transferring the privacy risks to users via notice or consent requests where users could not \n", "reasonably be expected to understand the risks without further support. \n", "Privacy-preserving security. Entities creating, using, or governing automated systems should follow \n", "privacy and security best practices designed to ensure data and metadata do not leak beyond the specific \n", "consented use case. Best practices could include using privacy-enhancing cryptography or other types of \n", "privacy-enhancing technologies or fine-grained permissions and access control mechanisms, along with \n", "conventional system security protocols. \n", "33\n", "{'source': 'Blueprint for an AI Bill of Rights', 'document_id': 'doc1', '_id': '316b7df2f22c4975ad8621ec0131c8ac', '_collection_name': 'ffb2f8aece51430086938e04161466e4'}\n", "---\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/rchrdgwr/anaconda3/envs/llmops-course/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 0.3.0. Use invoke instead.\n", " warn_deprecated(\n" ] } ], "source": [ "query = \"How should you be protected from abusive data practices \"\n", "results = qdrant_retriever.get_relevant_documents(query)\n", "\n", "for result in results:\n", " print(result.page_content)\n", " print(result.metadata)\n", " print(\"---\")\n", "\n" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ENDNOTES\n", "75. See., e.g., Sam Sabin. Digital surveillance in a post-Roe world. Politico. May 5, 2022. https://\n", "www.politico.com/newsletters/digital-future-daily/2022/05/05/digital-surveillance-in-a-post-roe­\n", "world-00030459; Federal Trade Commission. FTC Sues Kochava for Selling Data that Tracks People at\n", "Reproductive Health Clinics, Places of Worship, and Other Sensitive Locations. Aug. 29, 2022. https://\n", "www.ftc.gov/news-events/news/press-releases/2022/08/ftc-sues-kochava-selling-data-tracks-people­\n", "reproductive-health-clinics-places-worship-other\n", "76. Todd Feathers. This Private Equity Firm Is Amassing Companies That Collect Data on America’s\n", "Children. The Markup. Jan. 11, 2022.\n", "https://themarkup.org/machine-learning/2022/01/11/this-private-equity-firm-is-amassing-companies­\n", "that-collect-data-on-americas-children\n", "77. Reed Albergotti. Every employee who leaves Apple becomes an ‘associate’: In job databases used by\n", "employers to verify resume information, every former Apple employee’s title gets erased and replaced with\n", "a generic title. The Washington Post. Feb. 10, 2022.\n", "https://www.washingtonpost.com/technology/2022/02/10/apple-associate/\n", "78. National Institute of Standards and Technology. Privacy Framework Perspectives and Success\n", "Stories. Accessed May 2, 2022.\n", "https://www.nist.gov/privacy-framework/getting-started-0/perspectives-and-success-stories\n", "79. ACLU of New York. What You Need to Know About New York’s Temporary Ban on Facial\n", "Recognition in Schools. Accessed May 2, 2022.\n", "https://www.nyclu.org/en/publications/what-you-need-know-about-new-yorks-temporary-ban-facial­\n", "recognition-schools\n", "80. New York State Assembly. Amendment to Education Law. Enacted Dec. 22, 2020.\n", "https://nyassembly.gov/leg/?default_fld=&leg_video=&bn=S05140&term=2019&Summary=Y&Text=Y\n", "81. U.S Department of Labor. Labor-Management Reporting and Disclosure Act of 1959, As Amended.\n", "https://www.dol.gov/agencies/olms/laws/labor-management-reporting-and-disclosure-act (Section\n", "203). See also: U.S Department of Labor. Form LM-10. OLMS Fact Sheet, Accessed May 2, 2022. https://\n", "www.dol.gov/sites/dolgov/files/OLMS/regs/compliance/LM-10_factsheet.pdf\n", "82. See, e.g., Apple. Protecting the User’s Privacy. Accessed May 2, 2022.\n", "https://developer.apple.com/documentation/uikit/protecting_the_user_s_privacy; Google Developers.\n", "Design for Safety: Android is secure by default and private by design. Accessed May 3, 2022.\n", "https://developer.android.com/design-for-safety\n", "83. Karen Hao. The coming war on the hidden algorithms that trap people in poverty. MIT Tech Review.\n", "Dec. 4, 2020.\n", "https://www.technologyreview.com/2020/12/04/1013068/algorithms-create-a-poverty-trap-lawyers­\n", "fight-back/\n", "84. Anjana Samant, Aaron Horowitz, Kath Xu, and Sophie Beiers. Family Surveillance by Algorithm.\n", "ACLU. Accessed May 2, 2022.\n", "https://www.aclu.org/fact-sheet/family-surveillance-algorithm\n", "70\n", "{'source': 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile', 'document_id': 'doc2', '_id': '4301d9bb14f44d928a3e254b4da4aa18', '_collection_name': '527fdbdd8d4148b48f493df2f8334866'}\n", "---\n", "ENDNOTES\n", "75. See., e.g., Sam Sabin. Digital surveillance in a post-Roe world. Politico. May 5, 2022. https://\n", "www.politico.com/newsletters/digital-future-daily/2022/05/05/digital-surveillance-in-a-post-roe­\n", "world-00030459; Federal Trade Commission. FTC Sues Kochava for Selling Data that Tracks People at\n", "Reproductive Health Clinics, Places of Worship, and Other Sensitive Locations. Aug. 29, 2022. https://\n", "www.ftc.gov/news-events/news/press-releases/2022/08/ftc-sues-kochava-selling-data-tracks-people­\n", "reproductive-health-clinics-places-worship-other\n", "76. Todd Feathers. This Private Equity Firm Is Amassing Companies That Collect Data on America’s\n", "Children. The Markup. Jan. 11, 2022.\n", "https://themarkup.org/machine-learning/2022/01/11/this-private-equity-firm-is-amassing-companies­\n", "that-collect-data-on-americas-children\n", "77. Reed Albergotti. Every employee who leaves Apple becomes an ‘associate’: In job databases used by\n", "employers to verify resume information, every former Apple employee’s title gets erased and replaced with\n", "a generic title. The Washington Post. Feb. 10, 2022.\n", "https://www.washingtonpost.com/technology/2022/02/10/apple-associate/\n", "78. National Institute of Standards and Technology. Privacy Framework Perspectives and Success\n", "Stories. Accessed May 2, 2022.\n", "https://www.nist.gov/privacy-framework/getting-started-0/perspectives-and-success-stories\n", "79. ACLU of New York. What You Need to Know About New York’s Temporary Ban on Facial\n", "Recognition in Schools. Accessed May 2, 2022.\n", "https://www.nyclu.org/en/publications/what-you-need-know-about-new-yorks-temporary-ban-facial­\n", "recognition-schools\n", "80. New York State Assembly. Amendment to Education Law. Enacted Dec. 22, 2020.\n", "https://nyassembly.gov/leg/?default_fld=&leg_video=&bn=S05140&term=2019&Summary=Y&Text=Y\n", "81. U.S Department of Labor. Labor-Management Reporting and Disclosure Act of 1959, As Amended.\n", "https://www.dol.gov/agencies/olms/laws/labor-management-reporting-and-disclosure-act (Section\n", "203). See also: U.S Department of Labor. Form LM-10. OLMS Fact Sheet, Accessed May 2, 2022. https://\n", "www.dol.gov/sites/dolgov/files/OLMS/regs/compliance/LM-10_factsheet.pdf\n", "82. See, e.g., Apple. Protecting the User’s Privacy. Accessed May 2, 2022.\n", "https://developer.apple.com/documentation/uikit/protecting_the_user_s_privacy; Google Developers.\n", "Design for Safety: Android is secure by default and private by design. Accessed May 3, 2022.\n", "https://developer.android.com/design-for-safety\n", "83. Karen Hao. The coming war on the hidden algorithms that trap people in poverty. MIT Tech Review.\n", "Dec. 4, 2020.\n", "https://www.technologyreview.com/2020/12/04/1013068/algorithms-create-a-poverty-trap-lawyers­\n", "fight-back/\n", "84. Anjana Samant, Aaron Horowitz, Kath Xu, and Sophie Beiers. Family Surveillance by Algorithm.\n", "ACLU. Accessed May 2, 2022.\n", "https://www.aclu.org/fact-sheet/family-surveillance-algorithm\n", "70\n", "{'source': 'Blueprint for an AI Bill of Rights', 'document_id': 'doc1', '_id': '2442bc209b7842858b5a85e83131fd69', '_collection_name': '527fdbdd8d4148b48f493df2f8334866'}\n", "---\n", "ENDNOTES\n", "57. ISO Technical Management Board. ISO/IEC Guide 71:2014. Guide for addressing accessibility in\n", "standards. International Standards Organization. 2021. https://www.iso.org/standard/57385.html\n", "58. World Wide Web Consortium. Web Content Accessibility Guidelines (WCAG) 2.0. Dec. 11, 2008.\n", "https://www.w3.org/TR/WCAG20/\n", "59. Reva Schwartz, Apostol Vassilev, Kristen Greene, Lori Perine, and Andrew Bert. NIST Special\n", "Publication 1270: Towards a Standard for Identifying and Managing Bias in Artificial Intelligence. The\n", "National Institute of Standards and Technology. March, 2022. https://nvlpubs.nist.gov/nistpubs/\n", "SpecialPublications/NIST.SP.1270.pdf\n", "60. See, e.g., the 2014 Federal Trade Commission report “Data Brokers A Call for Transparency and\n", "Accountability”. https://www.ftc.gov/system/files/documents/reports/data-brokers-call-transparency­\n", "accountability-report-federal-trade-commission-may-2014/140527databrokerreport.pdf\n", "61. See, e.g., Nir Kshetri. School surveillance of students via laptops may do more harm than good. The\n", "Conversation. Jan. 21, 2022.\n", "https://theconversation.com/school-surveillance-of-students-via-laptops-may-do-more-harm-than­\n", "good-170983; Matt Scherer. Warning: Bossware May be Hazardous to Your Health. Center for Democracy\n", "& Technology Report.\n", "https://cdt.org/wp-content/uploads/2021/07/2021-07-29-Warning-Bossware-May-Be-Hazardous-To­\n", "Your-Health-Final.pdf; Human Impact Partners and WWRC. The Public Health Crisis Hidden in Amazon\n", "Warehouses. HIP and WWRC report. Jan. 2021.\n", "https://humanimpact.org/wp-content/uploads/2021/01/The-Public-Health-Crisis-Hidden-In-Amazon­\n", "Warehouses-HIP-WWRC-01-21.pdf; Drew Harwell. Contract lawyers face a growing invasion of\n", "surveillance programs that monitor their work. The Washington Post. Nov. 11, 2021. https://\n", "www.washingtonpost.com/technology/2021/11/11/lawyer-facial-recognition-monitoring/;\n", "Virginia Doellgast and Sean O'Brady. Making Call Center Jobs Better: The Relationship between\n", "Management Practices and Worker Stress. A Report for the CWA. June 2020. https://\n", "hdl.handle.net/1813/74307\n", "62. See, e.g., Federal Trade Commission. Data Brokers: A Call for Transparency and Accountability. May\n", "2014.\n", "https://www.ftc.gov/system/files/documents/reports/data-brokers-call-transparency-accountability­\n", "report-federal-trade-commission-may-2014/140527databrokerreport.pdf; Cathy O’Neil.\n", "Weapons of Math Destruction. Penguin Books. 2017.\n", "https://en.wikipedia.org/wiki/Weapons_of_Math_Destruction\n", "63. See, e.g., Rachel Levinson-Waldman, Harsha Pandurnga, and Faiza Patel. Social Media Surveillance by\n", "the U.S. Government. Brennan Center for Justice. Jan. 7, 2022.\n", "https://www.brennancenter.org/our-work/research-reports/social-media-surveillance-us-government;\n", "Shoshana Zuboff. The Age of Surveillance Capitalism: The Fight for a Human Future at the New Frontier of\n", "Power. Public Affairs. 2019.\n", "64. Angela Chen. Why the Future of Life Insurance May Depend on Your Online Presence. The Verge. Feb.\n", "7, 2019.\n", "https://www.theverge.com/2019/2/7/18211890/social-media-life-insurance-new-york-algorithms-big­\n", "data-discrimination-online-records\n", "68\n", "{'source': 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile', 'document_id': 'doc2', '_id': 'ce568df861214be999caf4c0dac9d07d', '_collection_name': '527fdbdd8d4148b48f493df2f8334866'}\n", "---\n", "ENDNOTES\n", "57. ISO Technical Management Board. ISO/IEC Guide 71:2014. Guide for addressing accessibility in\n", "standards. International Standards Organization. 2021. https://www.iso.org/standard/57385.html\n", "58. World Wide Web Consortium. Web Content Accessibility Guidelines (WCAG) 2.0. Dec. 11, 2008.\n", "https://www.w3.org/TR/WCAG20/\n", "59. Reva Schwartz, Apostol Vassilev, Kristen Greene, Lori Perine, and Andrew Bert. NIST Special\n", "Publication 1270: Towards a Standard for Identifying and Managing Bias in Artificial Intelligence. The\n", "National Institute of Standards and Technology. March, 2022. https://nvlpubs.nist.gov/nistpubs/\n", "SpecialPublications/NIST.SP.1270.pdf\n", "60. See, e.g., the 2014 Federal Trade Commission report “Data Brokers A Call for Transparency and\n", "Accountability”. https://www.ftc.gov/system/files/documents/reports/data-brokers-call-transparency­\n", "accountability-report-federal-trade-commission-may-2014/140527databrokerreport.pdf\n", "61. See, e.g., Nir Kshetri. School surveillance of students via laptops may do more harm than good. The\n", "Conversation. Jan. 21, 2022.\n", "https://theconversation.com/school-surveillance-of-students-via-laptops-may-do-more-harm-than­\n", "good-170983; Matt Scherer. Warning: Bossware May be Hazardous to Your Health. Center for Democracy\n", "& Technology Report.\n", "https://cdt.org/wp-content/uploads/2021/07/2021-07-29-Warning-Bossware-May-Be-Hazardous-To­\n", "Your-Health-Final.pdf; Human Impact Partners and WWRC. The Public Health Crisis Hidden in Amazon\n", "Warehouses. HIP and WWRC report. Jan. 2021.\n", "https://humanimpact.org/wp-content/uploads/2021/01/The-Public-Health-Crisis-Hidden-In-Amazon­\n", "Warehouses-HIP-WWRC-01-21.pdf; Drew Harwell. Contract lawyers face a growing invasion of\n", "surveillance programs that monitor their work. The Washington Post. Nov. 11, 2021. https://\n", "www.washingtonpost.com/technology/2021/11/11/lawyer-facial-recognition-monitoring/;\n", "Virginia Doellgast and Sean O'Brady. Making Call Center Jobs Better: The Relationship between\n", "Management Practices and Worker Stress. A Report for the CWA. June 2020. https://\n", "hdl.handle.net/1813/74307\n", "62. See, e.g., Federal Trade Commission. Data Brokers: A Call for Transparency and Accountability. May\n", "2014.\n", "https://www.ftc.gov/system/files/documents/reports/data-brokers-call-transparency-accountability­\n", "report-federal-trade-commission-may-2014/140527databrokerreport.pdf; Cathy O’Neil.\n", "Weapons of Math Destruction. Penguin Books. 2017.\n", "https://en.wikipedia.org/wiki/Weapons_of_Math_Destruction\n", "63. See, e.g., Rachel Levinson-Waldman, Harsha Pandurnga, and Faiza Patel. Social Media Surveillance by\n", "the U.S. Government. Brennan Center for Justice. Jan. 7, 2022.\n", "https://www.brennancenter.org/our-work/research-reports/social-media-surveillance-us-government;\n", "Shoshana Zuboff. The Age of Surveillance Capitalism: The Fight for a Human Future at the New Frontier of\n", "Power. Public Affairs. 2019.\n", "64. Angela Chen. Why the Future of Life Insurance May Depend on Your Online Presence. The Verge. Feb.\n", "7, 2019.\n", "https://www.theverge.com/2019/2/7/18211890/social-media-life-insurance-new-york-algorithms-big­\n", "data-discrimination-online-records\n", "68\n", "{'source': 'Blueprint for an AI Bill of Rights', 'document_id': 'doc1', '_id': '0dea504571ec413bbb96e84737f87a19', '_collection_name': '527fdbdd8d4148b48f493df2f8334866'}\n", "---\n" ] } ], "source": [ "query = \"tell me about Karen Hao\"\n", "results = qdrant_retriever.get_relevant_documents(query)\n", "\n", "for result in results:\n", " print(result.page_content)\n", " print(result.metadata)\n", " print(\"---\")" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "content=\"I don't have enough information, sorry.\" response_metadata={'token_usage': {'completion_tokens': 8, 'prompt_tokens': 112, 'total_tokens': 120, 'completion_tokens_details': {'reasoning_tokens': 0}}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_52a7f40b0b', 'finish_reason': 'stop', 'logprobs': None} id='run-511e9c6e-8c54-4ca3-8991-18bb3ba7c744-0' usage_metadata={'input_tokens': 112, 'output_tokens': 8, 'total_tokens': 120}\n" ] } ], "source": [ "from langchain_core.prompts import ChatPromptTemplate\n", "from langchain_openai import ChatOpenAI\n", "system_template = \"\"\"\n", " You are an expert at explaining technical documents to people.\n", " You are provided context below to answer the question.\n", " Only use the information provided below.\n", " If you cannot answer the question with the content below say 'I don't have enough information, sorry'\n", " The two documents are 'Blueprint for an AI Bill of Rights' and 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile'\n", "\"\"\"\n", "human_template = \"\"\" \n", "===\n", "question:\n", "{question}\n", "\n", "===\n", "context:\n", "{context}\n", "===\n", "\"\"\"\n", "chat_prompt = ChatPromptTemplate.from_messages([\n", " (\"system\", system_template),\n", " (\"human\", human_template)\n", "])\n", "# create the chain\n", "openai_chat_model = ChatOpenAI(model=\"gpt-4o\")\n", "chain = chat_prompt | openai_chat_model\n", "print(chain.invoke({\"question\": \"Can you give me a summary of the 2 documents\", \"context\":\"\"})) # displays \n" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'response': AIMessage(content='The AI Bill of Rights, officially known as the \"Blueprint for an AI Bill of Rights,\" is a set of five principles and associated practices designed to guide the design, use, and deployment of automated systems. Its primary goal is to protect the rights of the American public in the age of artificial intelligence (AI). Developed through extensive consultation with various stakeholders, including impacted communities, industry stakeholders, technology developers, and policymakers, these principles are intended to ensure that AI systems are aligned with democratic values and protect civil rights, civil liberties, and privacy. The Blueprint provides a national values statement and a toolkit that is sector-agnostic, meaning it can be applied across different sectors to inform policy decisions and the technological design process.', response_metadata={'token_usage': {'completion_tokens': 144, 'prompt_tokens': 1848, 'total_tokens': 1992, 'completion_tokens_details': {'reasoning_tokens': 0}}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_52a7f40b0b', 'finish_reason': 'stop', 'logprobs': None}, id='run-eb76dbb2-facd-471e-9752-580bd7f46fc4-0', usage_metadata={'input_tokens': 1848, 'output_tokens': 144, 'total_tokens': 1992}), 'context': [Document(metadata={'source': 'Blueprint for an AI Bill of Rights', 'document_id': 'doc1', '_id': '7bacb7e37ad04ed0881408b49dfa5bd2', '_collection_name': 'ffb2f8aece51430086938e04161466e4'}, page_content='other protected data. Such activities require alternative, compatible safeguards through existing policies that \\ngovern automated systems and AI, such as the Department of Defense (DOD) AI Ethical Principles and \\nResponsible AI Implementation Pathway and the Intelligence Community (IC) AI Ethics Principles and \\nFramework. The implementation of these policies to national security and defense activities can be informed by \\nthe Blueprint for an AI Bill of Rights where feasible. \\nThe Blueprint for an AI Bill of Rights is not intended to, and does not, create any legal right, benefit, or \\ndefense, substantive or procedural, enforceable at law or in equity by any party against the United States, its \\ndepartments, agencies, or entities, its officers, employees, or agents, or any other person, nor does it constitute a \\nwaiver of sovereign immunity. \\nCopyright Information \\nThis document is a work of the United States Government and is in the public domain (see 17 U.S.C. §105). \\n2'), Document(metadata={'source': 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile', 'document_id': 'doc2', '_id': '0b5b8214b946430284b040e7e1a8a027', '_collection_name': 'ffb2f8aece51430086938e04161466e4'}, page_content='other protected data. Such activities require alternative, compatible safeguards through existing policies that \\ngovern automated systems and AI, such as the Department of Defense (DOD) AI Ethical Principles and \\nResponsible AI Implementation Pathway and the Intelligence Community (IC) AI Ethics Principles and \\nFramework. The implementation of these policies to national security and defense activities can be informed by \\nthe Blueprint for an AI Bill of Rights where feasible. \\nThe Blueprint for an AI Bill of Rights is not intended to, and does not, create any legal right, benefit, or \\ndefense, substantive or procedural, enforceable at law or in equity by any party against the United States, its \\ndepartments, agencies, or entities, its officers, employees, or agents, or any other person, nor does it constitute a \\nwaiver of sovereign immunity. \\nCopyright Information \\nThis document is a work of the United States Government and is in the public domain (see 17 U.S.C. §105). \\n2'), Document(metadata={'source': 'Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile', 'document_id': 'doc2', '_id': '4d87b814e59541b2ae7ee2d3bd110f96', '_collection_name': 'ffb2f8aece51430086938e04161466e4'}, page_content='ABOUT THIS FRAMEWORK\\xad\\xad\\xad\\xad\\xad\\nThe Blueprint for an AI Bill of Rights is a set of five principles and associated practices to help guide the \\ndesign, use, and deployment of automated systems to protect the rights of the American public in the age of \\nartificial intel-ligence. Developed through extensive consultation with the American public, these principles are \\na blueprint for building and deploying automated systems that are aligned with democratic values and protect \\ncivil rights, civil liberties, and privacy. The Blueprint for an AI Bill of Rights includes this Foreword, the five \\nprinciples, notes on Applying the The Blueprint for an AI Bill of Rights, and a Technical Companion that gives \\nconcrete steps that can be taken by many kinds of organizations—from governments at all levels to companies of \\nall sizes—to uphold these values. Experts from across the private sector, governments, and international \\nconsortia have published principles and frameworks to guide the responsible use of automated systems; this \\nframework provides a national values statement and toolkit that is sector-agnostic to inform building these \\nprotections into policy, practice, or the technological design process. Where existing law or policy—such as \\nsector-specific privacy laws and oversight requirements—do not already provide guidance, the Blueprint for an \\nAI Bill of Rights should be used to inform policy decisions.\\nLISTENING TO THE AMERICAN PUBLIC\\nThe White House Office of Science and Technology Policy has led a year-long process to seek and distill input \\nfrom people across the country—from impacted communities and industry stakeholders to technology develop-\\ners and other experts across fields and sectors, as well as policymakers throughout the Federal government—on \\nthe issue of algorithmic and data-driven harms and potential remedies. Through panel discussions, public listen-\\ning sessions, meetings, a formal request for information, and input to a publicly accessible and widely-publicized \\nemail address, people throughout the United States, public servants across Federal agencies, and members of the \\ninternational community spoke up about both the promises and potential harms of these technologies, and \\nplayed a central role in shaping the Blueprint for an AI Bill of Rights. The core messages gleaned from these \\ndiscussions include that AI has transformative potential to improve Americans’ lives, and that preventing the \\nharms of these technologies is both necessary and achievable. The Appendix includes a full list of public engage-\\nments. \\n4'), Document(metadata={'source': 'Blueprint for an AI Bill of Rights', 'document_id': 'doc1', '_id': 'd1a69baaaf6244b28fc90ebf898a5d92', '_collection_name': 'ffb2f8aece51430086938e04161466e4'}, page_content='ABOUT THIS FRAMEWORK\\xad\\xad\\xad\\xad\\xad\\nThe Blueprint for an AI Bill of Rights is a set of five principles and associated practices to help guide the \\ndesign, use, and deployment of automated systems to protect the rights of the American public in the age of \\nartificial intel-ligence. Developed through extensive consultation with the American public, these principles are \\na blueprint for building and deploying automated systems that are aligned with democratic values and protect \\ncivil rights, civil liberties, and privacy. The Blueprint for an AI Bill of Rights includes this Foreword, the five \\nprinciples, notes on Applying the The Blueprint for an AI Bill of Rights, and a Technical Companion that gives \\nconcrete steps that can be taken by many kinds of organizations—from governments at all levels to companies of \\nall sizes—to uphold these values. Experts from across the private sector, governments, and international \\nconsortia have published principles and frameworks to guide the responsible use of automated systems; this \\nframework provides a national values statement and toolkit that is sector-agnostic to inform building these \\nprotections into policy, practice, or the technological design process. Where existing law or policy—such as \\nsector-specific privacy laws and oversight requirements—do not already provide guidance, the Blueprint for an \\nAI Bill of Rights should be used to inform policy decisions.\\nLISTENING TO THE AMERICAN PUBLIC\\nThe White House Office of Science and Technology Policy has led a year-long process to seek and distill input \\nfrom people across the country—from impacted communities and industry stakeholders to technology develop-\\ners and other experts across fields and sectors, as well as policymakers throughout the Federal government—on \\nthe issue of algorithmic and data-driven harms and potential remedies. Through panel discussions, public listen-\\ning sessions, meetings, a formal request for information, and input to a publicly accessible and widely-publicized \\nemail address, people throughout the United States, public servants across Federal agencies, and members of the \\ninternational community spoke up about both the promises and potential harms of these technologies, and \\nplayed a central role in shaping the Blueprint for an AI Bill of Rights. The core messages gleaned from these \\ndiscussions include that AI has transformative potential to improve Americans’ lives, and that preventing the \\nharms of these technologies is both necessary and achievable. The Appendix includes a full list of public engage-\\nments. \\n4')]}\n", "The AI Bill of Rights, officially known as the \"Blueprint for an AI Bill of Rights,\" is a set of five principles and associated practices designed to guide the design, use, and deployment of automated systems. Its primary goal is to protect the rights of the American public in the age of artificial intelligence (AI). Developed through extensive consultation with various stakeholders, including impacted communities, industry stakeholders, technology developers, and policymakers, these principles are intended to ensure that AI systems are aligned with democratic values and protect civil rights, civil liberties, and privacy. The Blueprint provides a national values statement and a toolkit that is sector-agnostic, meaning it can be applied across different sectors to inform policy decisions and the technological design process.\n", "Number of found context: 4\n" ] } ], "source": [ "from operator import itemgetter\n", "from langchain.schema.output_parser import StrOutputParser\n", "from langchain.schema.runnable import RunnablePassthrough\n", "retrieval_augmented_qa_chain = (\n", " {\"context\": itemgetter(\"question\") | qdrant_retriever, \"question\": itemgetter(\"question\")}\n", " | RunnablePassthrough.assign(context=itemgetter(\"context\"))\n", "\n", "\n", " | {\"response\": chat_prompt | openai_chat_model, \"context\": itemgetter(\"context\")}\n", ")\n", "response = retrieval_augmented_qa_chain.invoke({\"question\" : \"What is the AI Bill of Rights \"})\n", "print(response)\n", "print(response[\"response\"].content)\n", "print(f\"Number of found context: {len(response['context'])}\")" ] } ], "metadata": { "kernelspec": { "display_name": "llmops-course", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 2 }