Update retriever.py
Browse files- retriever.py +41 -21
retriever.py
CHANGED
|
@@ -6,6 +6,21 @@ from langchain_community.retrievers import BM25Retriever
|
|
| 6 |
import datasets
|
| 7 |
from langchain.docstore.document import Document
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
###########################
|
| 11 |
# Retriever - changed to LangGraph version
|
|
@@ -27,29 +42,34 @@ guest_info_tool = Tool(
|
|
| 27 |
)
|
| 28 |
###########################
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
# Load the dataset
|
| 35 |
-
guest_dataset = datasets.load_dataset("agents-course/unit3-invitees", split="train")
|
| 36 |
-
|
| 37 |
-
# Convert dataset entries into Document objects
|
| 38 |
-
docs = [
|
| 39 |
-
Document(
|
| 40 |
-
page_content="\n".join([
|
| 41 |
-
f"Name: {guest['name']}",
|
| 42 |
-
f"Relation: {guest['relation']}",
|
| 43 |
-
f"Description: {guest['description']}",
|
| 44 |
-
f"Email: {guest['email']}"
|
| 45 |
-
]),
|
| 46 |
-
metadata={"name": guest["name"]}
|
| 47 |
-
)
|
| 48 |
-
for guest in guest_dataset
|
| 49 |
-
]
|
| 50 |
-
|
| 51 |
-
# Return the tool
|
| 52 |
-
return GuestInfoRetrieverTool(docs)
|
| 53 |
|
| 54 |
|
| 55 |
|
|
|
|
| 6 |
import datasets
|
| 7 |
from langchain.docstore.document import Document
|
| 8 |
|
| 9 |
+
# Load dataset and create documents
|
| 10 |
+
guest_dataset = datasets.load_dataset("agents-course/unit3-invitees", split="train")
|
| 11 |
+
|
| 12 |
+
docs = [
|
| 13 |
+
Document(
|
| 14 |
+
page_content="\n".join([
|
| 15 |
+
f"Name: {guest['name']}",
|
| 16 |
+
f"Relation: {guest['relation']}",
|
| 17 |
+
f"Description: {guest['description']}",
|
| 18 |
+
f"Email: {guest['email']}"
|
| 19 |
+
]),
|
| 20 |
+
metadata={"name": guest["name"]}
|
| 21 |
+
)
|
| 22 |
+
for guest in guest_dataset
|
| 23 |
+
]
|
| 24 |
|
| 25 |
###########################
|
| 26 |
# Retriever - changed to LangGraph version
|
|
|
|
| 42 |
)
|
| 43 |
###########################
|
| 44 |
|
| 45 |
+
# # (Optional) Remove or update this function if unused
|
| 46 |
+
# def load_guest_dataset():
|
| 47 |
+
# # This function is no longer needed as docs are created above
|
| 48 |
+
# pass
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# # no change from smolagents to LangGraph
|
| 53 |
+
# def load_guest_dataset():
|
| 54 |
+
# # Load the dataset
|
| 55 |
+
# guest_dataset = datasets.load_dataset("agents-course/unit3-invitees", split="train")
|
| 56 |
|
| 57 |
+
# # Convert dataset entries into Document objects
|
| 58 |
+
# docs = [
|
| 59 |
+
# Document(
|
| 60 |
+
# page_content="\n".join([
|
| 61 |
+
# f"Name: {guest['name']}",
|
| 62 |
+
# f"Relation: {guest['relation']}",
|
| 63 |
+
# f"Description: {guest['description']}",
|
| 64 |
+
# f"Email: {guest['email']}"
|
| 65 |
+
# ]),
|
| 66 |
+
# metadata={"name": guest["name"]}
|
| 67 |
+
# )
|
| 68 |
+
# for guest in guest_dataset
|
| 69 |
+
# ]
|
| 70 |
|
| 71 |
+
# # Return the tool
|
| 72 |
+
# return GuestInfoRetrieverTool(docs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
|