diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..963a057 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.env diff --git a/lab-chains-in-langchain.ipynb b/lab-chains-in-langchain.ipynb index 290f3bb..3db3c8d 100644 --- a/lab-chains-in-langchain.ipynb +++ b/lab-chains-in-langchain.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "541eb2f1", "metadata": {}, "outputs": [], @@ -29,7 +29,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "b7ed03ed-1322-49e3-b2a2-33e94fb592ef", "metadata": { "tags": [] @@ -47,19 +47,39 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "id": "b84e441b", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting pandas\n", + " Downloading pandas-3.0.5-cp313-cp313-macosx_11_0_arm64.whl.metadata (79 kB)\n", + "Requirement already satisfied: numpy>=1.26.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from pandas) (1.26.4)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from pandas) (2.9.0.post0)\n", + "Requirement already satisfied: six>=1.5 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n", + "Downloading pandas-3.0.5-cp313-cp313-macosx_11_0_arm64.whl (9.9 MB)\n", + "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m9.9/9.9 MB\u001b[0m \u001b[31m12.7 MB/s\u001b[0m \u001b[33m0:00:00\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hInstalling collected packages: pandas\n", + "Successfully installed pandas-3.0.5\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;49m25.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m26.1.2\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;49mpip install --upgrade pip\u001b[0m\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], "source": [ - "#!pip install pandas" + "%pip install pandas" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 5, "id": "974acf8e-8f88-42de-88f8-40a82cb58e8b", "metadata": { "tags": [] @@ -67,12 +87,12 @@ "outputs": [], "source": [ "import pandas as pd\n", - "df = pd.read_csv('./lab/data/Data.csv')" + "df = pd.read_csv('./data/Data.csv')" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 6, "id": "b7a09c35", "metadata": { "tags": [] @@ -142,7 +162,7 @@ "4 Milk Frother Handheld\\n  I loved this product. But they only seem to l..." ] }, - "execution_count": 15, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -161,17 +181,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "427e1119", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: langchain_community in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (0.2.19)\n", + "Requirement already satisfied: PyYAML>=5.3 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (6.0.3)\n", + "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (2.0.51)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (3.14.3)\n", + "Requirement already satisfied: dataclasses-json<0.7,>=0.5.7 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (0.6.7)\n", + "Requirement already satisfied: langchain<0.3.0,>=0.2.17 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (0.2.17)\n", + "Requirement already satisfied: langchain-core<0.3.0,>=0.2.43 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (0.2.43)\n", + "Requirement already satisfied: langsmith<0.2.0,>=0.1.112 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (0.1.147)\n", + "Requirement already satisfied: numpy<2.0.0,>=1.26.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (1.26.4)\n", + "Requirement already satisfied: requests<3,>=2 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (2.34.2)\n", + "Requirement already satisfied: tenacity!=8.4.0,<9.0.0,>=8.1.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain_community) (8.5.0)\n", + "Requirement already satisfied: aiohappyeyeballs>=2.5.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (2.7.1)\n", + "Requirement already satisfied: aiosignal>=1.4.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.4.0)\n", + "Requirement already satisfied: attrs>=17.3.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (26.1.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/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 /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (6.7.1)\n", + "Requirement already satisfied: propcache>=0.2.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (0.5.2)\n", + "Requirement already satisfied: yarl<2.0,>=1.17.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.24.5)\n", + "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain_community) (3.26.2)\n", + "Requirement already satisfied: typing-inspect<1,>=0.4.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain_community) (0.9.0)\n", + "Requirement already satisfied: langchain-text-splitters<0.3.0,>=0.2.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain<0.3.0,>=0.2.17->langchain_community) (0.2.4)\n", + "Requirement already satisfied: pydantic<3,>=1 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain<0.3.0,>=0.2.17->langchain_community) (2.13.4)\n", + "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain-core<0.3.0,>=0.2.43->langchain_community) (1.33)\n", + "Requirement already satisfied: packaging<25,>=23.2 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain-core<0.3.0,>=0.2.43->langchain_community) (24.2)\n", + "Requirement already satisfied: typing-extensions>=4.7 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langchain-core<0.3.0,>=0.2.43->langchain_community) (4.16.0)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.43->langchain_community) (3.1.1)\n", + "Requirement already satisfied: httpx<1,>=0.23.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langsmith<0.2.0,>=0.1.112->langchain_community) (0.28.1)\n", + "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langsmith<0.2.0,>=0.1.112->langchain_community) (3.11.9)\n", + "Requirement already satisfied: requests-toolbelt<2.0.0,>=1.0.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from langsmith<0.2.0,>=0.1.112->langchain_community) (1.0.0)\n", + "Requirement already satisfied: anyio in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.112->langchain_community) (4.14.2)\n", + "Requirement already satisfied: certifi in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.112->langchain_community) (2026.7.22)\n", + "Requirement already satisfied: httpcore==1.* in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.112->langchain_community) (1.0.9)\n", + "Requirement already satisfied: idna in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.112->langchain_community) (3.18)\n", + "Requirement already satisfied: h11>=0.16 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.112->langchain_community) (0.16.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from pydantic<3,>=1->langchain<0.3.0,>=0.2.17->langchain_community) (0.8.0)\n", + "Requirement already satisfied: pydantic-core==2.46.4 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from pydantic<3,>=1->langchain<0.3.0,>=0.2.17->langchain_community) (2.46.4)\n", + "Requirement already satisfied: typing-inspection>=0.4.2 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from pydantic<3,>=1->langchain<0.3.0,>=0.2.17->langchain_community) (0.4.2)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from requests<3,>=2->langchain_community) (3.4.9)\n", + "Requirement already satisfied: urllib3<3,>=1.26 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from requests<3,>=2->langchain_community) (2.7.0)\n", + "Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/dahliaelbanhawy/Desktop/IronHack/week_7/.venv/langchain-v0.2.x/lib/python3.13/site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.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;49m25.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m26.1.2\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;49mpip install --upgrade pip\u001b[0m\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], "source": [ - "!pip install langchain_community" + "%pip install langchain_community" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 7, "id": "e92dff22", "metadata": { "tags": [] @@ -185,33 +256,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "943237a7", "metadata": {}, "outputs": [], "source": [ "#Replace None by your own value and justify\n", - "llm = ChatOpenAI(temperature=None)\n" + "#0.7 gives a good balance of creativity and consistency\n", + "llm = ChatOpenAI(temperature=0.7)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "cdcdb42d", "metadata": {}, "outputs": [], "source": [ - "prompt = ChatPromptTemplate.from_template( #Write a query that would take a variable to describe any product\n", - " \n", + "prompt = ChatPromptTemplate.from_template(\n", + " \"Write a compelling product description for a {product}. Include its key features and benefits.\"\n", ")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "d7abc20b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/88/scxzcgb55s1_sms0q1v2bkl80000gn/T/ipykernel_59488/546483037.py:1: LangChainDeprecationWarning: The class `LLMChain` was deprecated in LangChain 0.1.17 and will be removed in 1.0. Use RunnableSequence, e.g., `prompt | llm` instead.\n", + " chain = LLMChain(llm=llm, prompt=prompt)\n" + ] + } + ], "source": [ "\n", "chain = LLMChain(llm=llm, prompt=prompt)" @@ -219,13 +300,132 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "ad44d1fb", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/88/scxzcgb55s1_sms0q1v2bkl80000gn/T/ipykernel_59488/2886539801.py:2: LangChainDeprecationWarning: The method `Chain.run` was deprecated in langchain 0.1.0 and will be removed in 1.0. Use invoke instead.\n", + " result = chain.run(product)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Introducing the ultimate hydration companion - the Smart Water Bottle. Stay on top of your hydration goals with this innovative bottle that tracks your water intake throughout the day.\n", + "\n", + "Key Features:\n", + "- Built-in hydration tracker: With its smart technology, this water bottle keeps track of how much water you've consumed and sends reminders when it's time to take another sip.\n", + "- Customizable goals: Set your own daily hydration goals and watch as the Smart Water Bottle helps you reach them with ease.\n", + "- Leak-proof design: Made from durable, BPA-free materials, this water bottle is designed to withstand daily wear and tear. Plus, its leak-proof lid ensures that your water stays where it belongs - in the bottle.\n", + "- Easy to use: Simply fill up the bottle, sync it with your smartphone, and let the Smart Water Bottle do the rest. Its user-friendly interface makes staying hydrated a breeze.\n", + "\n", + "Benefits:\n", + "- Improved hydration: By keeping track of your water intake, this smart water bottle helps you stay properly hydrated throughout the day. Say goodbye to dehydration headaches and fatigue.\n", + "- Healthier habits: With regular reminders and customizable goals, the Smart Water Bottle encourages you to develop healthy hydration habits that will benefit your overall well-being.\n", + "- Eco-friendly: Reusable and sustainable, this water bottle is a great alternative to single-use plastic bottles. Help reduce plastic waste and do your part for the environment.\n", + "\n", + "Don't let dehydration get in the way of your day. Stay hydrated and healthy with the Smart Water Bottle - your new favorite hydration companion.\n" + ] + } + ], + "source": [ + "product = \"smart water bottle that tracks hydration\"\n", + "result = chain.run(product)\n", + "print(result)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "213938ee", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "==================================================\n", + "Product: wireless noise-canceling headphones\n", + "==================================================\n", + "Introducing our cutting-edge wireless noise-canceling headphones, the ultimate solution for immersive, uninterrupted listening experiences. \n", + "\n", + "Featuring advanced noise-canceling technology, these headphones block out background noise, allowing you to focus solely on your music, podcasts, or calls without any distractions. Say goodbye to loud environments and hello to crystal-clear sound quality.\n", + "\n", + "Key features include Bluetooth connectivity for seamless pairing with your devices, a long-lasting battery life for hours of uninterrupted use, and an adjustable headband for a comfortable fit. The built-in microphone also allows for hands-free calling, making it convenient for on-the-go communication.\n", + "\n", + "With these headphones, you can enjoy your favorite music in its purest form, without any external interference. Whether you're commuting, working out, or simply relaxing at home, these wireless noise-canceling headphones will elevate your listening experience to new heights.\n", + "\n", + "Invest in your auditory pleasure and upgrade to our wireless noise-canceling headphones today. Say goodbye to distractions and hello to unparalleled sound quality.\n", + "\n", + "==================================================\n", + "Product: portable solar-powered charger\n", + "==================================================\n", + "Introducing the ultimate solution for powering up on the go - the portable solar-powered charger! This innovative device harnesses the power of the sun to keep your devices charged and ready for action wherever you are.\n", + "\n", + "Key Features:\n", + "- Built-in solar panels for eco-friendly charging\n", + "- Dual USB ports for charging multiple devices simultaneously\n", + "- Lightweight and compact design for easy portability\n", + "- Durable construction for long-lasting use\n", + "- LED indicator lights to show charging status\n", + "- Overcharge and short circuit protection for peace of mind\n", + "\n", + "Benefits:\n", + "- Never run out of battery again with unlimited solar power\n", + "- Charge your devices anytime, anywhere, without needing an outlet\n", + "- Reduce your carbon footprint by using renewable energy\n", + "- Stay connected and powered up during outdoor adventures, camping trips, or emergencies\n", + "- Save money on disposable batteries and traditional chargers\n", + "- Enjoy the convenience of a reliable and efficient charging solution on the move\n", + "\n", + "Don't let a dead battery hold you back - invest in a portable solar-powered charger today and stay powered up wherever life takes you!\n", + "\n", + "==================================================\n", + "Product: ergonomic standing desk\n", + "==================================================\n", + "Introducing the ultimate solution for a healthier work environment - the ergonomic standing desk. Say goodbye to the aches and pains that come from sitting at a traditional desk all day long, and say hello to improved posture, increased productivity, and a happier, healthier you.\n", + "\n", + "Key features of our ergonomic standing desk include:\n", + "\n", + "1. Adjustable height settings: Easily transition from sitting to standing with the touch of a button, allowing you to customize the desk to the perfect height for your comfort.\n", + "\n", + "2. Spacious work surface: With plenty of room for your computer, keyboard, mouse, and other essentials, this desk provides ample space to spread out and work efficiently.\n", + "\n", + "3. Sturdy construction: Made from high-quality materials, this desk is built to last and can support all of your work essentials without wobbling or shaking.\n", + "\n", + "4. Cable management system: Keep your workspace clutter-free and organized with built-in cable management, ensuring that your cords stay neat and out of the way.\n", + "\n", + "Benefits of using an ergonomic standing desk include:\n", + "\n", + "1. Improved posture: By alternating between sitting and standing throughout the day, you can alleviate strain on your back, neck, and shoulders, leading to better posture and decreased discomfort.\n", + "\n", + "2. Increased energy and focus: Standing while working can boost circulation and energy levels, helping you stay focused and alert throughout the day.\n", + "\n", + "3. Healthier lifestyle: Studies have shown that prolonged sitting can have negative effects on our overall health, including increased risk of obesity, heart disease, and other health conditions. By incorporating more standing into your daily routine, you can combat these risks and lead a healthier lifestyle.\n", + "\n", + "Invest in your health and well-being with our ergonomic standing desk. Experience the benefits of a more comfortable and productive workday, and take the first step towards a healthier you.\n" + ] + } + ], "source": [ - "product = #Select a product type to be describe\n", - "chain.run(product)" + "products = [\n", + " \"wireless noise-canceling headphones\",\n", + " \"portable solar-powered charger\",\n", + " \"ergonomic standing desk\"\n", + "]\n", + "\n", + "for product in products:\n", + " print(f\"\\n{'='*50}\")\n", + " print(f\"Product: {product}\")\n", + " print(f\"{'='*50}\")\n", + " result = chain.run(product)\n", + " print(result)" ] }, { @@ -238,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "febee243", "metadata": {}, "outputs": [], @@ -248,7 +448,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "2f31aa8a", "metadata": {}, "outputs": [], @@ -257,7 +457,7 @@ "\n", "# prompt template 1\n", "first_prompt = ChatPromptTemplate.from_template(\n", - " #Repeat the initial query or create a new query that would feed into the second prompt\n", + " \"Generate a creative, catchy name for a product that is a {product_type}. Just give me the name, nothing else.\"\n", ")\n", "\n", "# Chain 1\n", @@ -266,7 +466,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "3f5d5b76", "metadata": {}, "outputs": [], @@ -274,7 +474,7 @@ "\n", "# prompt template 2\n", "second_prompt = ChatPromptTemplate.from_template(\n", - " #Write the second prompt query that takes an input variable whose input will come from the previous prompt\"\n", + " \"Write a memorable 5-word slogan for a product called '{product_name}'. Just give me the slogan, nothing else.\"\n", ")\n", "# chain 2\n", "chain_two = LLMChain(llm=llm, prompt=second_prompt)" @@ -282,7 +482,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "6c1eb2c4", "metadata": {}, "outputs": [], @@ -294,12 +494,108 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "78458efe", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[36;1m\u001b[1;3mAudiobudz\u001b[0m\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33;1m\u001b[1;3m\"Immerse yourself in sound quality.\"\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "\n", + "==================================================\n", + "Product: smart watch\n", + "==================================================\n", + "\u001b[36;1m\u001b[1;3mTimeSync Smartwatch\u001b[0m\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33;1m\u001b[1;3m\"Stay in sync with time.\"\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "Complete Output: \"Stay in sync with time.\"\n", + "\n", + "\n", + "==================================================\n", + "Product: coffee maker\n", + "==================================================\n", + "\u001b[36;1m\u001b[1;3mBrewMistress\u001b[0m\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33;1m\u001b[1;3m\"BrewMistress: Master of Crafted Flavor\"\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "Complete Output: \"BrewMistress: Master of Crafted Flavor\"\n", + "\n", + "\n", + "==================================================\n", + "Product: yoga mat\n", + "==================================================\n", + "\u001b[36;1m\u001b[1;3mZenMat\u001b[0m\n", + "\u001b[33;1m\u001b[1;3m\"Find your inner peace here.\"\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "Complete Output: \"Find your inner peace here.\"\n", + "\n" + ] + } + ], "source": [ - "overall_simple_chain.run(product)" + "overall_simple_chain.run(product)\n", + "products = [\"smart watch\", \"coffee maker\", \"yoga mat\"]\n", + "\n", + "for product in products:\n", + " print(f\"\\n{'='*50}\")\n", + " print(f\"Product: {product}\")\n", + " print(f\"{'='*50}\")\n", + " result = overall_simple_chain.run(product)\n", + " print(f\"Complete Output: {result}\")\n", + " print()" ] }, { @@ -320,7 +616,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "4c129ef6", "metadata": {}, "outputs": [], @@ -330,7 +626,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "016187ac", "metadata": {}, "outputs": [], @@ -339,50 +635,56 @@ "\n", "\n", "first_prompt = ChatPromptTemplate.from_template(\n", - " #This prompt should translate a review\n", + " \"Translate this review to English if it's not already in English:\\n\\n{review}\\n\\nTranslation:\"\n", ")\n", "\n", - "chain_one = LLMChain(llm=llm, prompt=first_prompt, \n", - " output_key=None #Give a name to your output\n", - " )\n" + "chain_one = LLMChain(\n", + " llm=llm, \n", + " prompt=first_prompt, \n", + " output_key=\"english_review\"\n", + ")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "0fb0730e", "metadata": {}, "outputs": [], "source": [ "second_prompt = ChatPromptTemplate.from_template(\n", - " #Write a promplt to summarize a review\n", + " \"Summarize this review in 2-3 sentences:\\n\\n{english_review}\\n\\nSummary:\"\n", ")\n", "\n", - "chain_two = LLMChain(llm=llm, prompt=second_prompt, \n", - " output_key=None #give a name to this output\n", - " )\n" + "chain_two = LLMChain(\n", + " llm=llm, \n", + " prompt=second_prompt, \n", + " output_key=\"summary\"\n", + ")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "6accf92d", "metadata": {}, "outputs": [], "source": [ "# prompt template 3: translate to english or other language\n", "third_prompt = ChatPromptTemplate.from_template(\n", - " None\n", + " \"What language is this review written in? Just state the language name.\\n\\n{review}\\n\\nLanguage:\"\n", ")\n", - "# chain 3: input= Review and output= language\n", - "chain_three = LLMChain(llm=llm, prompt=third_prompt,\n", - " output_key=None\n", - " )\n" + "\n", + "chain_three = LLMChain(\n", + " llm=llm, \n", + " prompt=third_prompt,\n", + " output_key=\"original_language\"\n", + ")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "c7a46121", "metadata": {}, "outputs": [], @@ -390,16 +692,22 @@ "\n", "# prompt template 4: follow up message that take as inputs the two previous prompts' variables\n", "fourth_prompt = ChatPromptTemplate.from_template(\n", - " None\n", + " \"Based on this review summary: '{summary}',\\n\"\n", + " \"and the fact it was originally written in {original_language},\\n\"\n", + " \"write a helpful response to the customer in {original_language}.\\n\\n\"\n", + " \"Response:\"\n", ")\n", - "chain_four = LLMChain(llm=llm, prompt=fourth_prompt,\n", - " output_key=None\n", - " )\n" + "\n", + "chain_four = LLMChain(\n", + " llm=llm, \n", + " prompt=fourth_prompt,\n", + " output_key=\"followup_message\"\n", + ")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "89603117", "metadata": {}, "outputs": [], @@ -408,8 +716,8 @@ "# and output= English_Review,summary, followup_message\n", "overall_chain = SequentialChain(\n", " chains=[chain_one, chain_two, chain_three, chain_four],\n", - " input_variables=None,\n", - " output_variables=[None, None, None],\n", + " input_variables=[\"review\"],\n", + " output_variables=[\"english_review\", \"summary\", \"original_language\", \"followup_message\"],\n", " verbose=True\n", ")" ] @@ -419,10 +727,140 @@ "execution_count": null, "id": "51b04f45", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original Review:\n", + "Je trouve le goût médiocre. La mousse ne tient pas, c'est bizarre. J'achète les mêmes dans le commerce et le goût est bien meilleur...\n", + "Vieux lot ou contrefaçon !?\n", + "\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n" + ] + } + ], "source": [ - "review = df.Review[5]\n", - "overall_chain(review)" + "review_idx = min(5, len(df) - 1)\n", + "review = df[\"Review\"].iloc[review_idx]\n", + "print(f\"Original Review:\\n{review}\\n\")\n", + "result = overall_chain.invoke({\"review\": review})" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "90941c07", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "============================================================\n", + "PROCESSING REVIEW #0\n", + "============================================================\n", + "Original: I ordered a king size set. My only criticism would be that I wish seller would offer the king size s...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "\n", + "📝 Summary: The review mentioned ordering a king size set and wishing the seller offered it with 4 pillowcases instead of just 2. Despite this, customer service was helpful in sending additional matching pillowcases. Overall, the reviewer was satisfied with the quality and cooling properties of the sheets for the price.\n", + "🌐 Original Language: English\n", + "💬 Follow-up: Dear valued customer,\n", + "\n", + "Thank you for your feedback on your recent purchase of our king-size sheet set. We are pleased to hear that you are satisfied w...\n", + "\n", + "\n", + "============================================================\n", + "PROCESSING REVIEW #1\n", + "============================================================\n", + "Original: I loved the waterproof sac, although the opening was made of a hard plastic. I don’t know if that wo...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "\n", + "📝 Summary: The reviewer enjoyed the waterproof sack but had concerns about the durability of the hard plastic opening. Additionally, they had difficulty using their phone while inside the pouch.\n", + "🌐 Original Language: English\n", + "💬 Follow-up: Thank you for your feedback on the waterproof sack. We appreciate your positive comments about its waterproof capabilities. We apologize for any conce...\n", + "\n", + "\n", + "============================================================\n", + "PROCESSING REVIEW #2\n", + "============================================================\n", + "Original: This mattress had a small hole in the top of it (took forever to find where it was), and the patches...\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "\n", + "📝 Summary: The reviewer had a negative experience with this mattress as it arrived with a small hole that was difficult to patch and the company did not provide adequate customer service or quality assurance. The flat mattress ruined the reviewer's friend's stay and the inconvenience of having to ship it back for a refund added to their frustration.\n", + "🌐 Original Language: English\n", + "💬 Follow-up: We are sorry to hear about your negative experience with our mattress. We sincerely apologize for the inconvenience caused by the small hole in the ma...\n", + "\n" + ] + } + ], + "source": [ + "# Test with multiple reviews\n", + "review_indices = [0, 1, 2] # Choose valid indices within the dataset\n", + "\n", + "for idx in review_indices:\n", + " if idx >= len(df):\n", + " print(f\"Skipping index {idx}: dataset has only {len(df)} rows.\")\n", + " continue\n", + "\n", + " print(f\"\\n{'='*60}\")\n", + " print(f\"PROCESSING REVIEW #{idx}\")\n", + " print(f\"{'='*60}\")\n", + " \n", + " review = df[\"Review\"].iloc[idx]\n", + " print(f\"Original: {review[:100]}...\")\n", + " \n", + " result = overall_chain.invoke({\"review\": review})\n", + " \n", + " print(f\"\\n📝 Summary: {result['summary']}\")\n", + " print(f\"🌐 Original Language: {result['original_language']}\")\n", + " print(f\"💬 Follow-up: {result['followup_message'][:150]}...\")\n", + " print()" ] }, { @@ -443,7 +881,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "id": "ade83f4f", "metadata": {}, "outputs": [], @@ -509,7 +947,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "id": "5f590e9f", "metadata": {}, "outputs": [], @@ -545,7 +983,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "id": "31b06fc8", "metadata": {}, "outputs": [], @@ -557,7 +995,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "id": "f3f50bcc", "metadata": {}, "outputs": [], @@ -567,7 +1005,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "id": "8eefec24", "metadata": {}, "outputs": [], @@ -586,7 +1024,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "9f98018a", "metadata": {}, "outputs": [], @@ -597,7 +1035,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "id": "11b2e2ba", "metadata": {}, "outputs": [], @@ -635,8 +1073,8 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "1387109d", + "execution_count": 45, + "id": "8b9e732b", "metadata": {}, "outputs": [], "source": [ @@ -654,10 +1092,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "id": "2fb7d560", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/88/scxzcgb55s1_sms0q1v2bkl80000gn/T/ipykernel_59488/3038952769.py:1: LangChainDeprecationWarning: Use RunnableLambda to select from multiple prompt templates. See example in API reference: https://api.python.langchain.com/en/latest/chains/langchain.chains.router.multi_prompt.MultiPromptChain.html\n", + " chain = MultiPromptChain(router_chain=router_chain,\n" + ] + } + ], "source": [ "chain = MultiPromptChain(router_chain=router_chain, \n", " destination_chains=destination_chains, \n", @@ -667,34 +1114,246 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "id": "d86b2131", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "physics: {'input': 'What is black body radiation?'}\n", + "\u001b[1m> Finished chain.\u001b[0m\n" + ] + }, + { + "data": { + "text/plain": [ + "\"Black body radiation refers to the electromagnetic radiation emitted by a perfect black body, which is an idealized physical body that absorbs all incident electromagnetic radiation and emits radiation at all frequencies. The radiation emitted by a black body is characterized by a continuous spectrum of wavelengths and intensities that depend only on the body's temperature. This phenomenon is described by Planck's law, which states that the intensity of radiation emitted by a black body is proportional to the frequency of the radiation and the temperature of the body. Black body radiation plays a key role in understanding the behavior of objects at high temperatures and in the development of quantum mechanics.\"" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "chain.run(\"What is black body radiation?\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "id": "3b717379", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "math: {'input': 'what is 2 + 2'}\n", + "\u001b[1m> Finished chain.\u001b[0m\n" + ] + }, + { + "data": { + "text/plain": [ + "'The answer to 2 + 2 is 4.'" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "chain.run(\"what is 2 + 2\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "id": "29e5be01", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "biology: {'input': 'Why does every cell in our body contain DNA?'}\n", + "\u001b[1m> Finished chain.\u001b[0m\n" + ] + }, + { + "data": { + "text/plain": [ + "\"Every cell in our body contains DNA because DNA is the genetic material that carries the instructions for the development, functioning, and reproduction of all living organisms. DNA contains the information needed to build and maintain an organism, including the proteins that make up our cells and tissues. \\n\\nHaving DNA in every cell ensures that each cell has the necessary genetic information to carry out its specific functions and to replicate itself accurately during cell division. This ensures that the genetic information is passed on to the next generation of cells, maintaining the integrity and continuity of the organism's genetic code.\\n\\nAdditionally, DNA serves as a storage system for genetic information, allowing for the transmission of traits from one generation to the next through the process of inheritance. This is essential for the survival and evolution of species, as it allows for genetic variation and adaptation to changing environments over time. \\n\\nIn summary, every cell in our body contains DNA because it is essential for the proper functioning, development, and reproduction of living organisms.\"" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "chain.run(\"Why does every cell in our body contain DNA?\")" ] }, + { + "cell_type": "code", + "execution_count": 51, + "id": "47150481", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "==================================================\n", + "Q: What is black body radiation?\n", + "==================================================\n", + "physics: {'input': 'What is black body radiation?'}" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "A: Black body radiation refers to the electromagnetic radiation emitted by a perfect black body, which is an idealized physical body that absorbs all incident electromagnetic radiation and emits radiation at all frequencies. The radiation emitted by a black body depends only on its temperature and follows a specific distribution known as Planck's law. This type of radiation is important in understanding concepts such as thermal radiation and the behavior of objects at different temperatures.\n", + "\n", + "==================================================\n", + "Q: what is 2 + 2\n", + "==================================================\n", + "math: {'input': 'what is 2 + 2'}" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "A: The answer to 2 + 2 is 4.\n", + "\n", + "==================================================\n", + "Q: Why does every cell in our body contain DNA?\n", + "==================================================\n", + "biology: {'input': 'Why does every cell in our body contain DNA?'}" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "A: Every cell in our body contains DNA because DNA is the genetic material that carries the instructions for the development, functioning, and reproduction of all living organisms. DNA contains the information needed to build and maintain an organism, including the proteins that make up our cells and tissues. \n", + "\n", + "Having DNA in every cell ensures that each cell has the necessary genetic information to carry out its specific functions and to replicate itself accurately during cell division. This ensures that the genetic information is passed on to the next generation of cells. \n", + "\n", + "Additionally, DNA is constantly being used by cells to carry out processes such as protein synthesis, cell division, and repair. Having DNA in every cell allows for the coordination of these processes and ensures that the organism functions properly as a whole. \n", + "\n", + "In summary, every cell in our body contains DNA because it is essential for the proper functioning and development of all living organisms.\n", + "\n", + "==================================================\n", + "Q: What is the time complexity of binary search?\n", + "==================================================\n", + "computer science: {'input': 'What is the time complexity of binary search?'}" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Error in StdOutCallbackHandler.on_chain_start callback: AttributeError(\"'NoneType' object has no attribute 'get'\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "A: The time complexity of binary search is O(log n), where n is the number of elements in the sorted array. This is because binary search divides the array in half with each comparison, reducing the search space by half each time. This results in a logarithmic time complexity, making binary search very efficient for searching in sorted arrays.\n", + "\n", + "==================================================\n", + "Q: Who was the first emperor of Rome?\n", + "==================================================\n", + "History: {'input': 'Who was the first emperor of Rome?'}\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "A: The first emperor of Rome was Augustus, also known as Caesar Augustus. He ruled from 27 BC until his death in AD 14. Augustus was the adopted son of Julius Caesar and played a crucial role in the transition from the Roman Republic to the Roman Empire.\n" + ] + } + ], + "source": [ + "test_questions = [\n", + "\"What is black body radiation?\",\n", + "\"what is 2 + 2\",\n", + "\"Why does every cell in our body contain DNA?\",\n", + "\"What is the time complexity of binary search?\",\n", + "\"Who was the first emperor of Rome?\"\n", + "]\n", + "\n", + "for question in test_questions:\n", + " print(f\"\\n{'='*50}\")\n", + " print(f\"Q: {question}\")\n", + " print(f\"{'='*50}\")\n", + " result = chain.run(question)\n", + " print(f\"A: {result}\") " + ] + }, { "cell_type": "markdown", "id": "09e0c60b-7ae0-453e-9467-142d8dafee6e", @@ -706,9 +1365,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python (LangChain 0.2.x)", "language": "python", - "name": "python3" + "name": "langchain-v0.2.x" }, "language_info": { "codemirror_mode": { @@ -720,7 +1379,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.13.9" } }, "nbformat": 4,