{ "cells": [ { "cell_type": "markdown", "id": "d312255a", "metadata": {}, "source": [ " Project Structure\n", "\n", " tools.py – Provides auxiliary tools for the agent.\n", " retriever.py – Implements retrieval functions to support knowledge access.\n", " app.py – Integrates all components into a fully functional agent, which we’ll finalize in the last part of this unit." ] }, { "cell_type": "markdown", "id": "fbbeaeb4", "metadata": {}, "source": [ "### Building the Guestbook Tool" ] }, { "cell_type": "markdown", "id": "5cd54389", "metadata": {}, "source": [ "Step 1: Load and Prepare the Dataset" ] }, { "cell_type": "code", "execution_count": 7, "id": "a36bf5b5", "metadata": {}, "outputs": [], "source": [ "from llama_index.core.schema import Document\n", "import pandas as pd\n", "#from huggingface_hub import hf_hub_download" ] }, { "cell_type": "code", "execution_count": 8, "id": "62d4fbf9", "metadata": {}, "outputs": [], "source": [ "# Load the dataset\n", "#guest_dataset = datasets.load_dataset(\"agents-course/unit3-invitees\", split=\"train\")\n", "guest_dataset = pd.read_parquet(\"/home/cairo/code/alfred-agent-rag/data/train-00000-of-00001.parquet\")\n", "\n", "# Convert dataset entries into Document objects\n", "docs = [\n", " Document(\n", " text=\"\\n\".join([\n", " f\"Name: {guest_dataset['name'][i]}\",\n", " f\"Relation: {guest_dataset['relation'][i]}\",\n", " f\"Description: {guest_dataset['description'][i]}\",\n", " f\"Email: {guest_dataset['email'][i]}\"\n", " ]),\n", " metadata={\"name\": guest_dataset['name'][i]}\n", " )\n", " for i in range(len(guest_dataset))\n", "]" ] }, { "cell_type": "code", "execution_count": 9, "id": "5e94a1f5", "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "name", "rawType": "object", "type": "string" }, { "name": "relation", "rawType": "object", "type": "string" }, { "name": "description", "rawType": "object", "type": "string" }, { "name": "email", "rawType": "object", "type": "string" } ], "conversionMethod": "pd.DataFrame", "ref": "5b022186-8682-4d89-87c4-204710defe6d", "rows": [ [ "0", "Ada Lovelace", "best friend", "Lady Ada Lovelace is my best friend. She is an esteemed mathematician and friend. She is renowned for her pioneering work in mathematics and computing, often celebrated as the first computer programmer due to her work on Charles Babbage's Analytical Engine.", "ada.lovelace@example.com" ], [ "1", "Dr. Nikola Tesla", "old friend from university days", "Dr. Nikola Tesla is an old friend from your university days. He's recently patented a new wireless energy transmission system and would be delighted to discuss it with you. Just remember he's passionate about pigeons, so that might make for good small talk.", "nikola.tesla@gmail.com" ], [ "2", "Marie Curie", "no relation", "Marie Curie was a groundbreaking physicist and chemist, famous for her research on radioactivity.", "marie.curie@example.com" ] ], "shape": { "columns": 4, "rows": 3 } }, "text/html": [ "
\n", " | name | \n", "relation | \n", "description | \n", "|
---|---|---|---|---|
0 | \n", "Ada Lovelace | \n", "best friend | \n", "Lady Ada Lovelace is my best friend. She is an... | \n", "ada.lovelace@example.com | \n", "
1 | \n", "Dr. Nikola Tesla | \n", "old friend from university days | \n", "Dr. Nikola Tesla is an old friend from your un... | \n", "nikola.tesla@gmail.com | \n", "
2 | \n", "Marie Curie | \n", "no relation | \n", "Marie Curie was a groundbreaking physicist and... | \n", "marie.curie@example.com | \n", "