Spaces:
Sleeping
Sleeping
daddyofadoggy
commited on
Commit
Β·
3897298
1
Parent(s):
4671af8
agent project
Browse files- Agent_test.ipynb +486 -0
- agent.py +2 -2
- explore_metadata.ipynb +593 -0
- supabase_docs.csv +0 -0
- supabase_docs_22.csv +0 -0
Agent_test.ipynb
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "e146b50e-5aec-4901-abf5-98a9521644ec",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"\"\"\"LangGraph Agent\"\"\"\n",
|
| 11 |
+
"import os\n",
|
| 12 |
+
"from dotenv import load_dotenv\n",
|
| 13 |
+
"from langgraph.graph import START, StateGraph, MessagesState\n",
|
| 14 |
+
"from langgraph.prebuilt import tools_condition\n",
|
| 15 |
+
"from langgraph.prebuilt import ToolNode\n",
|
| 16 |
+
"from langchain_google_genai import ChatGoogleGenerativeAI\n",
|
| 17 |
+
"from langchain_groq import ChatGroq\n",
|
| 18 |
+
"from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint, HuggingFaceEmbeddings\n",
|
| 19 |
+
"from langchain_community.tools.tavily_search import TavilySearchResults\n",
|
| 20 |
+
"from langchain_community.document_loaders import WikipediaLoader\n",
|
| 21 |
+
"from langchain_community.document_loaders import ArxivLoader\n",
|
| 22 |
+
"from langchain_community.vectorstores import SupabaseVectorStore\n",
|
| 23 |
+
"from langchain_core.messages import SystemMessage, HumanMessage\n",
|
| 24 |
+
"from langchain_core.tools import tool\n",
|
| 25 |
+
"from langchain.tools.retriever import create_retriever_tool\n",
|
| 26 |
+
"from supabase.client import Client, create_client"
|
| 27 |
+
]
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"cell_type": "code",
|
| 31 |
+
"execution_count": 2,
|
| 32 |
+
"id": "2c83828b-2c24-4b6a-9083-6caae5afded9",
|
| 33 |
+
"metadata": {},
|
| 34 |
+
"outputs": [
|
| 35 |
+
{
|
| 36 |
+
"data": {
|
| 37 |
+
"text/plain": [
|
| 38 |
+
"True"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
"execution_count": 2,
|
| 42 |
+
"metadata": {},
|
| 43 |
+
"output_type": "execute_result"
|
| 44 |
+
}
|
| 45 |
+
],
|
| 46 |
+
"source": [
|
| 47 |
+
"load_dotenv()"
|
| 48 |
+
]
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"cell_type": "code",
|
| 52 |
+
"execution_count": 3,
|
| 53 |
+
"id": "c3aa673a-c860-47c6-8f71-9ab7d163a219",
|
| 54 |
+
"metadata": {},
|
| 55 |
+
"outputs": [],
|
| 56 |
+
"source": [
|
| 57 |
+
"@tool\n",
|
| 58 |
+
"def multiply(a: int, b: int) -> int:\n",
|
| 59 |
+
" \"\"\"Multiply two numbers.\n",
|
| 60 |
+
"\n",
|
| 61 |
+
" Args:\n",
|
| 62 |
+
" a: first int\n",
|
| 63 |
+
" b: second int\n",
|
| 64 |
+
" \"\"\"\n",
|
| 65 |
+
" return a * b\n",
|
| 66 |
+
"\n",
|
| 67 |
+
"@tool\n",
|
| 68 |
+
"def add(a: int, b: int) -> int:\n",
|
| 69 |
+
" \"\"\"Add two numbers.\n",
|
| 70 |
+
" \n",
|
| 71 |
+
" Args:\n",
|
| 72 |
+
" a: first int\n",
|
| 73 |
+
" b: second int\n",
|
| 74 |
+
" \"\"\"\n",
|
| 75 |
+
" return a + b\n",
|
| 76 |
+
"\n",
|
| 77 |
+
"@tool\n",
|
| 78 |
+
"def subtract(a: int, b: int) -> int:\n",
|
| 79 |
+
" \"\"\"Subtract two numbers.\n",
|
| 80 |
+
" \n",
|
| 81 |
+
" Args:\n",
|
| 82 |
+
" a: first int\n",
|
| 83 |
+
" b: second int\n",
|
| 84 |
+
" \"\"\"\n",
|
| 85 |
+
" return a - b\n",
|
| 86 |
+
"\n",
|
| 87 |
+
"@tool\n",
|
| 88 |
+
"def divide(a: int, b: int) -> int:\n",
|
| 89 |
+
" \"\"\"Divide two numbers.\n",
|
| 90 |
+
" \n",
|
| 91 |
+
" Args:\n",
|
| 92 |
+
" a: first int\n",
|
| 93 |
+
" b: second int\n",
|
| 94 |
+
" \"\"\"\n",
|
| 95 |
+
" if b == 0:\n",
|
| 96 |
+
" raise ValueError(\"Cannot divide by zero.\")\n",
|
| 97 |
+
" return a / b\n",
|
| 98 |
+
"\n",
|
| 99 |
+
"@tool\n",
|
| 100 |
+
"def modulus(a: int, b: int) -> int:\n",
|
| 101 |
+
" \"\"\"Get the modulus of two numbers.\n",
|
| 102 |
+
" \n",
|
| 103 |
+
" Args:\n",
|
| 104 |
+
" a: first int\n",
|
| 105 |
+
" b: second int\n",
|
| 106 |
+
" \"\"\"\n",
|
| 107 |
+
" return a % b\n",
|
| 108 |
+
"\n",
|
| 109 |
+
"@tool\n",
|
| 110 |
+
"def wiki_search(query: str) -> str:\n",
|
| 111 |
+
" \"\"\"Search Wikipedia for a query and return maximum 2 results.\n",
|
| 112 |
+
" \n",
|
| 113 |
+
" Args:\n",
|
| 114 |
+
" query: The search query.\"\"\"\n",
|
| 115 |
+
" search_docs = WikipediaLoader(query=query, load_max_docs=2).load()\n",
|
| 116 |
+
" formatted_search_docs = \"\\n\\n---\\n\\n\".join(\n",
|
| 117 |
+
" [\n",
|
| 118 |
+
" f'<Document source=\"{doc.metadata[\"source\"]}\" page=\"{doc.metadata.get(\"page\", \"\")}\"/>\\n{doc.page_content}\\n</Document>'\n",
|
| 119 |
+
" for doc in search_docs\n",
|
| 120 |
+
" ])\n",
|
| 121 |
+
" return {\"wiki_results\": formatted_search_docs}\n",
|
| 122 |
+
"\n",
|
| 123 |
+
"@tool\n",
|
| 124 |
+
"def web_search(query: str) -> str:\n",
|
| 125 |
+
" \"\"\"Search Tavily for a query and return maximum 3 results.\n",
|
| 126 |
+
" \n",
|
| 127 |
+
" Args:\n",
|
| 128 |
+
" query: The search query.\"\"\"\n",
|
| 129 |
+
" search_docs = TavilySearchResults(max_results=3).invoke(query=query)\n",
|
| 130 |
+
" formatted_search_docs = \"\\n\\n---\\n\\n\".join(\n",
|
| 131 |
+
" [\n",
|
| 132 |
+
" f'<Document source=\"{doc.metadata[\"source\"]}\" page=\"{doc.metadata.get(\"page\", \"\")}\"/>\\n{doc.page_content}\\n</Document>'\n",
|
| 133 |
+
" for doc in search_docs\n",
|
| 134 |
+
" ])\n",
|
| 135 |
+
" return {\"web_results\": formatted_search_docs}\n",
|
| 136 |
+
"\n",
|
| 137 |
+
"@tool\n",
|
| 138 |
+
"def arvix_search(query: str) -> str:\n",
|
| 139 |
+
" \"\"\"Search Arxiv for a query and return maximum 3 result.\n",
|
| 140 |
+
" \n",
|
| 141 |
+
" Args:\n",
|
| 142 |
+
" query: The search query.\"\"\"\n",
|
| 143 |
+
" search_docs = ArxivLoader(query=query, load_max_docs=3).load()\n",
|
| 144 |
+
" formatted_search_docs = \"\\n\\n---\\n\\n\".join(\n",
|
| 145 |
+
" [\n",
|
| 146 |
+
" f'<Document source=\"{doc.metadata[\"source\"]}\" page=\"{doc.metadata.get(\"page\", \"\")}\"/>\\n{doc.page_content[:1000]}\\n</Document>'\n",
|
| 147 |
+
" for doc in search_docs\n",
|
| 148 |
+
" ])\n",
|
| 149 |
+
" return {\"arvix_results\": formatted_search_docs}\n"
|
| 150 |
+
]
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"cell_type": "code",
|
| 154 |
+
"execution_count": 4,
|
| 155 |
+
"id": "34c29028-656a-4c22-853a-bb707cc8354c",
|
| 156 |
+
"metadata": {},
|
| 157 |
+
"outputs": [],
|
| 158 |
+
"source": [
|
| 159 |
+
"# load the system prompt from the file\n",
|
| 160 |
+
"with open(\"system_prompt.txt\", \"r\", encoding=\"utf-8\") as f:\n",
|
| 161 |
+
" system_prompt = f.read()"
|
| 162 |
+
]
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"cell_type": "code",
|
| 166 |
+
"execution_count": 5,
|
| 167 |
+
"id": "f5b1c874-f2bd-49f3-aeee-498618530a5b",
|
| 168 |
+
"metadata": {},
|
| 169 |
+
"outputs": [],
|
| 170 |
+
"source": [
|
| 171 |
+
"# System message\n",
|
| 172 |
+
"sys_msg = SystemMessage(content=system_prompt)"
|
| 173 |
+
]
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"cell_type": "code",
|
| 177 |
+
"execution_count": 6,
|
| 178 |
+
"id": "11d9e25e-628e-440a-bd75-830d6f3563d9",
|
| 179 |
+
"metadata": {},
|
| 180 |
+
"outputs": [
|
| 181 |
+
{
|
| 182 |
+
"data": {
|
| 183 |
+
"text/plain": [
|
| 184 |
+
"SystemMessage(content='You are a helpful assistant tasked with answering questions using a set of tools. \\nNow, I will ask you a question. Report your thoughts, and finish your answer with the following template: \\nFINAL ANSWER: [YOUR FINAL ANSWER]. \\nYOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don\\'t use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don\\'t use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\\nYour answer should only start with \"FINAL ANSWER: \", then follows with the answer. \\n', additional_kwargs={}, response_metadata={})"
|
| 185 |
+
]
|
| 186 |
+
},
|
| 187 |
+
"execution_count": 6,
|
| 188 |
+
"metadata": {},
|
| 189 |
+
"output_type": "execute_result"
|
| 190 |
+
}
|
| 191 |
+
],
|
| 192 |
+
"source": [
|
| 193 |
+
"sys_msg"
|
| 194 |
+
]
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"cell_type": "code",
|
| 198 |
+
"execution_count": null,
|
| 199 |
+
"id": "4fb614f8-340a-49b6-9b62-2f37a9c5ed2a",
|
| 200 |
+
"metadata": {},
|
| 201 |
+
"outputs": [],
|
| 202 |
+
"source": [
|
| 203 |
+
"!pip install sentence-transformers"
|
| 204 |
+
]
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
"cell_type": "code",
|
| 208 |
+
"execution_count": 7,
|
| 209 |
+
"id": "467085b4-c410-4a4c-9f7e-11523794dd48",
|
| 210 |
+
"metadata": {},
|
| 211 |
+
"outputs": [
|
| 212 |
+
{
|
| 213 |
+
"name": "stderr",
|
| 214 |
+
"output_type": "stream",
|
| 215 |
+
"text": [
|
| 216 |
+
"/Users/ron/Documents/github/agentcoursefinal/hf-agent/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
| 217 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 218 |
+
]
|
| 219 |
+
}
|
| 220 |
+
],
|
| 221 |
+
"source": [
|
| 222 |
+
"# build a retriever\n",
|
| 223 |
+
"embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\") # dim=768"
|
| 224 |
+
]
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"cell_type": "code",
|
| 228 |
+
"execution_count": 8,
|
| 229 |
+
"id": "a71a7556-2594-4219-999d-1ff0f21f6b06",
|
| 230 |
+
"metadata": {},
|
| 231 |
+
"outputs": [],
|
| 232 |
+
"source": [
|
| 233 |
+
"supabase: Client = create_client(\n",
|
| 234 |
+
" os.environ.get(\"SUPABASE_URL\"), \n",
|
| 235 |
+
" os.environ.get(\"SUPABASE_SERVICE_KEY\"))"
|
| 236 |
+
]
|
| 237 |
+
},
|
| 238 |
+
{
|
| 239 |
+
"cell_type": "code",
|
| 240 |
+
"execution_count": 9,
|
| 241 |
+
"id": "4c2d5009-13b4-4389-94ce-1c0b9b6fa5b7",
|
| 242 |
+
"metadata": {},
|
| 243 |
+
"outputs": [],
|
| 244 |
+
"source": [
|
| 245 |
+
"vector_store = SupabaseVectorStore(\n",
|
| 246 |
+
" client=supabase,\n",
|
| 247 |
+
" embedding= embeddings,\n",
|
| 248 |
+
" table_name=\"documents\",\n",
|
| 249 |
+
" query_name=\"match_documents_langchain_2\",\n",
|
| 250 |
+
")"
|
| 251 |
+
]
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"cell_type": "code",
|
| 255 |
+
"execution_count": 10,
|
| 256 |
+
"id": "729bfc4c-bc07-4d92-b9a1-e9a9f6e1937d",
|
| 257 |
+
"metadata": {},
|
| 258 |
+
"outputs": [],
|
| 259 |
+
"source": [
|
| 260 |
+
"retriever=vector_store.as_retriever()"
|
| 261 |
+
]
|
| 262 |
+
},
|
| 263 |
+
{
|
| 264 |
+
"cell_type": "code",
|
| 265 |
+
"execution_count": 11,
|
| 266 |
+
"id": "bced1bb3-8cfa-41c7-baf1-8edfaf6b8415",
|
| 267 |
+
"metadata": {},
|
| 268 |
+
"outputs": [],
|
| 269 |
+
"source": [
|
| 270 |
+
"create_retriever_tool = create_retriever_tool(\n",
|
| 271 |
+
" retriever=vector_store.as_retriever(),\n",
|
| 272 |
+
" name=\"Question Search\",\n",
|
| 273 |
+
" description=\"A tool to retrieve similar questions from a vector store.\",\n",
|
| 274 |
+
")"
|
| 275 |
+
]
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"cell_type": "code",
|
| 279 |
+
"execution_count": 12,
|
| 280 |
+
"id": "3d71d24b-4d54-4cab-abb5-22f35b17e665",
|
| 281 |
+
"metadata": {},
|
| 282 |
+
"outputs": [],
|
| 283 |
+
"source": [
|
| 284 |
+
"tools = [\n",
|
| 285 |
+
" multiply,\n",
|
| 286 |
+
" add,\n",
|
| 287 |
+
" subtract,\n",
|
| 288 |
+
" divide,\n",
|
| 289 |
+
" modulus,\n",
|
| 290 |
+
" wiki_search,\n",
|
| 291 |
+
" web_search,\n",
|
| 292 |
+
" arvix_search,\n",
|
| 293 |
+
"]"
|
| 294 |
+
]
|
| 295 |
+
},
|
| 296 |
+
{
|
| 297 |
+
"cell_type": "code",
|
| 298 |
+
"execution_count": 13,
|
| 299 |
+
"id": "bf212992-0a20-47b1-8bc0-43c28b5e66b7",
|
| 300 |
+
"metadata": {},
|
| 301 |
+
"outputs": [],
|
| 302 |
+
"source": [
|
| 303 |
+
"# Build graph function\n",
|
| 304 |
+
"# Build graph function\n",
|
| 305 |
+
"def build_graph(provider: str = \"huggingface\"):\n",
|
| 306 |
+
" \"\"\"Build the graph\"\"\"\n",
|
| 307 |
+
" # Load environment variables from .env file\n",
|
| 308 |
+
" if provider == \"google\":\n",
|
| 309 |
+
" # Google Gemini\n",
|
| 310 |
+
" llm = ChatGoogleGenerativeAI(model=\"gemini-2.0-flash\", temperature=0)\n",
|
| 311 |
+
" elif provider == \"groq\":\n",
|
| 312 |
+
" # Groq https://console.groq.com/docs/models\n",
|
| 313 |
+
" llm = ChatGroq(model=\"qwen-qwq-32b\", temperature=0) # optional : qwen-qwq-32b gemma2-9b-it\n",
|
| 314 |
+
" elif provider == \"huggingface\":\n",
|
| 315 |
+
" llm = ChatHuggingFace(\n",
|
| 316 |
+
" llm=HuggingFaceEndpoint(\n",
|
| 317 |
+
" repo_id = \"Qwen/Qwen2.5-Coder-32B-Instruct\"\n",
|
| 318 |
+
" ),\n",
|
| 319 |
+
" )\n",
|
| 320 |
+
" else:\n",
|
| 321 |
+
" raise ValueError(\"Invalid provider. Choose 'google', 'groq' or 'huggingface'.\")\n",
|
| 322 |
+
" # Bind tools to LLM\n",
|
| 323 |
+
" llm_with_tools = llm.bind_tools(tools)\n",
|
| 324 |
+
"\n",
|
| 325 |
+
" # Node\n",
|
| 326 |
+
" def assistant(state: MessagesState):\n",
|
| 327 |
+
" \"\"\"Assistant node\"\"\"\n",
|
| 328 |
+
" return {\"messages\": [llm_with_tools.invoke(state[\"messages\"])]}\n",
|
| 329 |
+
" \n",
|
| 330 |
+
" def retriever(state: MessagesState):\n",
|
| 331 |
+
" \"\"\"Retriever node\"\"\"\n",
|
| 332 |
+
" similar_question = vector_store.similarity_search(state[\"messages\"][0].content)\n",
|
| 333 |
+
" example_msg = HumanMessage(\n",
|
| 334 |
+
" content=f\"Here I provide a similar question and answer for reference: \\n\\n{similar_question[0].page_content}\",\n",
|
| 335 |
+
" )\n",
|
| 336 |
+
" return {\"messages\": [sys_msg] + state[\"messages\"] + [example_msg]}\n",
|
| 337 |
+
"\n",
|
| 338 |
+
" builder = StateGraph(MessagesState)\n",
|
| 339 |
+
" builder.add_node(\"retriever\", retriever)\n",
|
| 340 |
+
" builder.add_node(\"assistant\", assistant)\n",
|
| 341 |
+
" builder.add_node(\"tools\", ToolNode(tools))\n",
|
| 342 |
+
" builder.add_edge(START, \"retriever\")\n",
|
| 343 |
+
" builder.add_edge(\"retriever\", \"assistant\")\n",
|
| 344 |
+
" builder.add_conditional_edges(\n",
|
| 345 |
+
" \"assistant\",\n",
|
| 346 |
+
" tools_condition,\n",
|
| 347 |
+
" )\n",
|
| 348 |
+
" builder.add_edge(\"tools\", \"assistant\")\n",
|
| 349 |
+
"\n",
|
| 350 |
+
" # Compile graph\n",
|
| 351 |
+
" return builder.compile()"
|
| 352 |
+
]
|
| 353 |
+
},
|
| 354 |
+
{
|
| 355 |
+
"cell_type": "code",
|
| 356 |
+
"execution_count": 14,
|
| 357 |
+
"id": "e9081e66-7f52-479c-9b58-e0515a56fc48",
|
| 358 |
+
"metadata": {},
|
| 359 |
+
"outputs": [],
|
| 360 |
+
"source": [
|
| 361 |
+
"question = \"When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?\"\n",
|
| 362 |
+
"# Build the graph\n",
|
| 363 |
+
"graph = build_graph(provider=\"huggingface\")"
|
| 364 |
+
]
|
| 365 |
+
},
|
| 366 |
+
{
|
| 367 |
+
"cell_type": "code",
|
| 368 |
+
"execution_count": 15,
|
| 369 |
+
"id": "b236ffc8-c446-4e48-95ab-693a13f29fdc",
|
| 370 |
+
"metadata": {},
|
| 371 |
+
"outputs": [
|
| 372 |
+
{
|
| 373 |
+
"data": {
|
| 374 |
+
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANgAAAFcCAIAAAAlFOfAAAAAAXNSR0IArs4c6QAAIABJREFUeJzt3XtcU/X/B/DP2X0MtjFgAx0IyE0EBEEpNBXxV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ChxZ20Qab9nn6GY+olH0dWu/8oTvVb/6E514kcohcR4dhA5PNq0Ze75aQ8N+q527bWZSq4pySif/aVXO5ZFcNGuc7ZsDm3Cgu555x42ybrI7aItyaoVNQXVb63ypNLQ4+oI096LB3wXxrzvexoUsvKcapyuuFifskFdmlnBYammLUOHyQTr2HX90bNcC27JL6ZUcN3sWQ4ss0fT8DMajbJqpapBpVerh4537u5jk5+ii+nwDSa+YQ6+YQ45V2V30xseZlYJ3B0wCoXOpNKYVCqdAtHLg1rAMIpOrdOp9Vq1Tq/S1lcq3f05EdEOPUOERJeGPPacdzoFRnIDI7k6jaE4R1FboW2UahsbmnSNQKeFMYp2DjRMb3Dk0+wdqUJ3O89e5k/RIwR6oVvuaAyKb6iDb2jnlYOQlc3f6UQqLA6FSrfhQ3uuE72tm2xQEG0Jk02tr7bVM2hGo/FRvpLvYv7aLwqiLRG6M7VNtvrdQmmNxjukzbs8URBtSc8Q+waJ5mGeTT4O5WJyVcRwx7bmwvW+ZuSZDAZjyq9lXsHcnn0cKBTbGC8q5brU3RWD3nDu3rPNU7YoiDbpfHJ19iVZt55sA9w7antH+sO8RldPVsQwRzcvSxcOUBBtmKRMrW6C+04UzCgQMdvzCCEURAQK6GAFgQIKIgIFFEQECiiICBRQEBEooCAiUPg/tctkIqLIzcsAAAAASUVORK5CYII=",
|
| 375 |
+
"text/plain": [
|
| 376 |
+
"<langgraph.graph.state.CompiledStateGraph object at 0x168c09fd0>"
|
| 377 |
+
]
|
| 378 |
+
},
|
| 379 |
+
"execution_count": 15,
|
| 380 |
+
"metadata": {},
|
| 381 |
+
"output_type": "execute_result"
|
| 382 |
+
}
|
| 383 |
+
],
|
| 384 |
+
"source": [
|
| 385 |
+
"graph"
|
| 386 |
+
]
|
| 387 |
+
},
|
| 388 |
+
{
|
| 389 |
+
"cell_type": "code",
|
| 390 |
+
"execution_count": 16,
|
| 391 |
+
"id": "b732a90d-171c-4567-8510-66e188d2c7f8",
|
| 392 |
+
"metadata": {},
|
| 393 |
+
"outputs": [],
|
| 394 |
+
"source": [
|
| 395 |
+
"messages = [HumanMessage(content=question)]\n",
|
| 396 |
+
"messages = graph.invoke({\"messages\": messages})"
|
| 397 |
+
]
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"cell_type": "code",
|
| 401 |
+
"execution_count": 17,
|
| 402 |
+
"id": "e2b8eebb-b7b9-438b-8b6f-152c0b531213",
|
| 403 |
+
"metadata": {},
|
| 404 |
+
"outputs": [
|
| 405 |
+
{
|
| 406 |
+
"name": "stdout",
|
| 407 |
+
"output_type": "stream",
|
| 408 |
+
"text": [
|
| 409 |
+
"================================\u001b[1m Human Message \u001b[0m=================================\n",
|
| 410 |
+
"\n",
|
| 411 |
+
"When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?\n",
|
| 412 |
+
"================================\u001b[1m System Message \u001b[0m================================\n",
|
| 413 |
+
"\n",
|
| 414 |
+
"You are a helpful assistant tasked with answering questions using a set of tools. \n",
|
| 415 |
+
"Now, I will ask you a question. Report your thoughts, and finish your answer with the following template: \n",
|
| 416 |
+
"FINAL ANSWER: [YOUR FINAL ANSWER]. \n",
|
| 417 |
+
"YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\n",
|
| 418 |
+
"Your answer should only start with \"FINAL ANSWER: \", then follows with the answer. \n",
|
| 419 |
+
"\n",
|
| 420 |
+
"================================\u001b[1m Human Message \u001b[0m=================================\n",
|
| 421 |
+
"\n",
|
| 422 |
+
"Here I provide a similar question and answer for reference: \n",
|
| 423 |
+
"\n",
|
| 424 |
+
"Question : When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect? Answer using the format DD/MM/YYYY.\n",
|
| 425 |
+
"\n",
|
| 426 |
+
"Final answer : 19/02/2009\n",
|
| 427 |
+
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
| 428 |
+
"\n",
|
| 429 |
+
"To find the exact date when a picture of St. Thomas Aquinas was first added to the Wikipedia page on the Principle of double effect, I would need to check the page's history. However, since I don't have real-time access to Wikipedia's edit history, I'll use the provided reference answer as a basis for the format.\n",
|
| 430 |
+
"\n",
|
| 431 |
+
"FINAL ANSWER: 19/02/2009\n"
|
| 432 |
+
]
|
| 433 |
+
}
|
| 434 |
+
],
|
| 435 |
+
"source": [
|
| 436 |
+
"for m in messages[\"messages\"]:\n",
|
| 437 |
+
" m.pretty_print()"
|
| 438 |
+
]
|
| 439 |
+
},
|
| 440 |
+
{
|
| 441 |
+
"cell_type": "code",
|
| 442 |
+
"execution_count": null,
|
| 443 |
+
"id": "584a2e97-ab67-4bc2-b3a1-094cb0e19820",
|
| 444 |
+
"metadata": {},
|
| 445 |
+
"outputs": [],
|
| 446 |
+
"source": []
|
| 447 |
+
},
|
| 448 |
+
{
|
| 449 |
+
"cell_type": "code",
|
| 450 |
+
"execution_count": null,
|
| 451 |
+
"id": "189183c4-1e12-4f8f-805d-ca7a42b274b6",
|
| 452 |
+
"metadata": {},
|
| 453 |
+
"outputs": [],
|
| 454 |
+
"source": []
|
| 455 |
+
},
|
| 456 |
+
{
|
| 457 |
+
"cell_type": "code",
|
| 458 |
+
"execution_count": null,
|
| 459 |
+
"id": "c1d56af7-a5e5-4311-b8d7-afed7a7463b1",
|
| 460 |
+
"metadata": {},
|
| 461 |
+
"outputs": [],
|
| 462 |
+
"source": []
|
| 463 |
+
}
|
| 464 |
+
],
|
| 465 |
+
"metadata": {
|
| 466 |
+
"kernelspec": {
|
| 467 |
+
"display_name": "hf-agent",
|
| 468 |
+
"language": "python",
|
| 469 |
+
"name": "hf-agent"
|
| 470 |
+
},
|
| 471 |
+
"language_info": {
|
| 472 |
+
"codemirror_mode": {
|
| 473 |
+
"name": "ipython",
|
| 474 |
+
"version": 3
|
| 475 |
+
},
|
| 476 |
+
"file_extension": ".py",
|
| 477 |
+
"mimetype": "text/x-python",
|
| 478 |
+
"name": "python",
|
| 479 |
+
"nbconvert_exporter": "python",
|
| 480 |
+
"pygments_lexer": "ipython3",
|
| 481 |
+
"version": "3.13.5"
|
| 482 |
+
}
|
| 483 |
+
},
|
| 484 |
+
"nbformat": 4,
|
| 485 |
+
"nbformat_minor": 5
|
| 486 |
+
}
|
agent.py
CHANGED
|
@@ -130,7 +130,7 @@ vector_store = SupabaseVectorStore(
|
|
| 130 |
client=supabase,
|
| 131 |
embedding= embeddings,
|
| 132 |
table_name="documents",
|
| 133 |
-
query_name="
|
| 134 |
)
|
| 135 |
create_retriever_tool = create_retriever_tool(
|
| 136 |
retriever=vector_store.as_retriever(),
|
|
@@ -204,7 +204,7 @@ def build_graph(provider: str = "huggingface"):
|
|
| 204 |
if __name__ == "__main__":
|
| 205 |
question = "When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?"
|
| 206 |
# Build the graph
|
| 207 |
-
graph = build_graph(provider="
|
| 208 |
# Run the graph
|
| 209 |
messages = [HumanMessage(content=question)]
|
| 210 |
messages = graph.invoke({"messages": messages})
|
|
|
|
| 130 |
client=supabase,
|
| 131 |
embedding= embeddings,
|
| 132 |
table_name="documents",
|
| 133 |
+
query_name="match_documents_langchain_2",
|
| 134 |
)
|
| 135 |
create_retriever_tool = create_retriever_tool(
|
| 136 |
retriever=vector_store.as_retriever(),
|
|
|
|
| 204 |
if __name__ == "__main__":
|
| 205 |
question = "When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?"
|
| 206 |
# Build the graph
|
| 207 |
+
graph = build_graph(provider="huggingface")
|
| 208 |
# Run the graph
|
| 209 |
messages = [HumanMessage(content=question)]
|
| 210 |
messages = graph.invoke({"messages": messages})
|
explore_metadata.ipynb
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "a600d7fc",
|
| 7 |
+
"metadata": {
|
| 8 |
+
"id": "a600d7fc"
|
| 9 |
+
},
|
| 10 |
+
"outputs": [],
|
| 11 |
+
"source": [
|
| 12 |
+
"import json\n",
|
| 13 |
+
"with open('metadata.jsonl', 'r') as f:\n",
|
| 14 |
+
" json_list = list(f)\n",
|
| 15 |
+
"\n",
|
| 16 |
+
"json_QA = []\n",
|
| 17 |
+
"for json_str in json_list:\n",
|
| 18 |
+
" json_data = json.loads(json_str)\n",
|
| 19 |
+
" json_QA.append(json_data)"
|
| 20 |
+
]
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"cell_type": "code",
|
| 24 |
+
"execution_count": 2,
|
| 25 |
+
"id": "a2e6091a-9630-4f57-a980-3f7cad2126f4",
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"outputs": [
|
| 28 |
+
{
|
| 29 |
+
"data": {
|
| 30 |
+
"text/plain": [
|
| 31 |
+
"165"
|
| 32 |
+
]
|
| 33 |
+
},
|
| 34 |
+
"execution_count": 2,
|
| 35 |
+
"metadata": {},
|
| 36 |
+
"output_type": "execute_result"
|
| 37 |
+
}
|
| 38 |
+
],
|
| 39 |
+
"source": [
|
| 40 |
+
"len(json_QA)"
|
| 41 |
+
]
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"cell_type": "code",
|
| 45 |
+
"execution_count": 3,
|
| 46 |
+
"id": "aca0d8ad-d4f6-4749-a979-4b7e38843c64",
|
| 47 |
+
"metadata": {},
|
| 48 |
+
"outputs": [
|
| 49 |
+
{
|
| 50 |
+
"data": {
|
| 51 |
+
"text/plain": [
|
| 52 |
+
"{'task_id': 'c61d22de-5f6c-4958-a7f6-5e9707bd3466',\n",
|
| 53 |
+
" 'Question': 'A paper about AI regulation that was originally submitted to arXiv.org in June 2022 shows a figure with three axes, where each axis has a label word at both ends. Which of these words is used to describe a type of society in a Physics and Society article submitted to arXiv.org on August 11, 2016?',\n",
|
| 54 |
+
" 'Level': 2,\n",
|
| 55 |
+
" 'Final answer': 'egalitarian',\n",
|
| 56 |
+
" 'file_name': '',\n",
|
| 57 |
+
" 'Annotator Metadata': {'Steps': '1. Go to arxiv.org and navigate to the Advanced Search page.\\n2. Enter \"AI regulation\" in the search box and select \"All fields\" from the dropdown.\\n3. Enter 2022-06-01 and 2022-07-01 into the date inputs, select \"Submission date (original)\", and submit the search.\\n4. Go through the search results to find the article that has a figure with three axes and labels on each end of the axes, titled \"Fairness in Agreement With European Values: An Interdisciplinary Perspective on AI Regulation\".\\n5. Note the six words used as labels: deontological, egalitarian, localized, standardized, utilitarian, and consequential.\\n6. Go back to arxiv.org\\n7. Find \"Physics and Society\" and go to the page for the \"Physics and Society\" category.\\n8. Note that the tag for this category is \"physics.soc-ph\".\\n9. Go to the Advanced Search page.\\n10. Enter \"physics.soc-ph\" in the search box and select \"All fields\" from the dropdown.\\n11. Enter 2016-08-11 and 2016-08-12 into the date inputs, select \"Submission date (original)\", and submit the search.\\n12. Search for instances of the six words in the results to find the paper titled \"Phase transition from egalitarian to hierarchical societies driven by competition between cognitive and social constraints\", indicating that \"egalitarian\" is the correct answer.',\n",
|
| 58 |
+
" 'Number of steps': '12',\n",
|
| 59 |
+
" 'How long did this take?': '8 minutes',\n",
|
| 60 |
+
" 'Tools': '1. Web browser\\n2. Image recognition tools (to identify and parse a figure with three axes)',\n",
|
| 61 |
+
" 'Number of tools': '2'}}"
|
| 62 |
+
]
|
| 63 |
+
},
|
| 64 |
+
"execution_count": 3,
|
| 65 |
+
"metadata": {},
|
| 66 |
+
"output_type": "execute_result"
|
| 67 |
+
}
|
| 68 |
+
],
|
| 69 |
+
"source": [
|
| 70 |
+
"json_QA[0]"
|
| 71 |
+
]
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"cell_type": "code",
|
| 75 |
+
"execution_count": 4,
|
| 76 |
+
"id": "fa5d8eb8",
|
| 77 |
+
"metadata": {
|
| 78 |
+
"id": "fa5d8eb8",
|
| 79 |
+
"outputId": "562cd6eb-7436-4563-cbbb-de2a38ae447e"
|
| 80 |
+
},
|
| 81 |
+
"outputs": [
|
| 82 |
+
{
|
| 83 |
+
"name": "stdout",
|
| 84 |
+
"output_type": "stream",
|
| 85 |
+
"text": [
|
| 86 |
+
"==================================================\n",
|
| 87 |
+
"Task ID: 65afbc8a-89ca-4ad5-8d62-355bb401f61d\n",
|
| 88 |
+
"Question: You are given this Excel file as a map. You start on the START cell and move toward the END cell. You are allowed to move two cells per turn, and you may move up, down, left, or right. You may not move fewer than two cells, and you may not move backward. You must avoid moving onto any blue cells. On the eleventh turn, what is the 6-digit hex code (without prefix) of the color of the cell where you land after moving?\n",
|
| 89 |
+
"Level: 1\n",
|
| 90 |
+
"Final Answer: F478A7\n",
|
| 91 |
+
"Annotator Metadata: \n",
|
| 92 |
+
" βββ Steps: \n",
|
| 93 |
+
" β βββ 1. Opened Map.xlsx.\n",
|
| 94 |
+
" β βββ 2. Counted 11 turns of 2 spaces each (22 spaces) along the path of non-blue cells.\n",
|
| 95 |
+
" β βββ 3. Opened cell formatting for the cell.\n",
|
| 96 |
+
" β βββ 4. Clicked the \"Fill\" tab.\n",
|
| 97 |
+
" β βββ 5. Clicked \"More Colors...\"\n",
|
| 98 |
+
" β βββ 6. Noted the hex code of the color.\n",
|
| 99 |
+
" βββ Number of steps: 6\n",
|
| 100 |
+
" βββ How long did this take?: 5 minutes\n",
|
| 101 |
+
" βββ Tools:\n",
|
| 102 |
+
" β βββ 1. Access to Excel files\n",
|
| 103 |
+
" β βββ 2. Color recognition\n",
|
| 104 |
+
" β βββ 3. Calculator (or ability to count)\n",
|
| 105 |
+
" βββ Number of tools: 3\n",
|
| 106 |
+
"==================================================\n"
|
| 107 |
+
]
|
| 108 |
+
}
|
| 109 |
+
],
|
| 110 |
+
"source": [
|
| 111 |
+
"import random\n",
|
| 112 |
+
"random_samples = random.sample(json_QA, 1)\n",
|
| 113 |
+
"for sample in random_samples:\n",
|
| 114 |
+
" print(\"=\" * 50)\n",
|
| 115 |
+
" print(f\"Task ID: {sample['task_id']}\")\n",
|
| 116 |
+
" print(f\"Question: {sample['Question']}\")\n",
|
| 117 |
+
" print(f\"Level: {sample['Level']}\")\n",
|
| 118 |
+
" print(f\"Final Answer: {sample['Final answer']}\")\n",
|
| 119 |
+
" print(f\"Annotator Metadata: \")\n",
|
| 120 |
+
" print(f\" βββ Steps: \")\n",
|
| 121 |
+
" for step in sample['Annotator Metadata']['Steps'].split('\\n'):\n",
|
| 122 |
+
" print(f\" β βββ {step}\")\n",
|
| 123 |
+
" print(f\" βββ Number of steps: {sample['Annotator Metadata']['Number of steps']}\")\n",
|
| 124 |
+
" print(f\" βββ How long did this take?: {sample['Annotator Metadata']['How long did this take?']}\")\n",
|
| 125 |
+
" print(f\" βββ Tools:\")\n",
|
| 126 |
+
" for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
|
| 127 |
+
" print(f\" β βββ {tool}\")\n",
|
| 128 |
+
" print(f\" βββ Number of tools: {sample['Annotator Metadata']['Number of tools']}\")\n",
|
| 129 |
+
"print(\"=\" * 50)"
|
| 130 |
+
]
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"cell_type": "code",
|
| 134 |
+
"execution_count": 5,
|
| 135 |
+
"id": "05076516",
|
| 136 |
+
"metadata": {
|
| 137 |
+
"id": "05076516"
|
| 138 |
+
},
|
| 139 |
+
"outputs": [
|
| 140 |
+
{
|
| 141 |
+
"name": "stderr",
|
| 142 |
+
"output_type": "stream",
|
| 143 |
+
"text": [
|
| 144 |
+
"/Users/ron/Documents/github/agentcoursefinal/hf-agent/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
| 145 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 146 |
+
]
|
| 147 |
+
}
|
| 148 |
+
],
|
| 149 |
+
"source": [
|
| 150 |
+
"import os\n",
|
| 151 |
+
"from dotenv import load_dotenv\n",
|
| 152 |
+
"from langchain_huggingface import HuggingFaceEmbeddings\n",
|
| 153 |
+
"from langchain_community.vectorstores import SupabaseVectorStore\n",
|
| 154 |
+
"from supabase.client import Client, create_client\n",
|
| 155 |
+
"\n",
|
| 156 |
+
"\n",
|
| 157 |
+
"load_dotenv()\n",
|
| 158 |
+
"embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\") # dim=768\n",
|
| 159 |
+
"\n",
|
| 160 |
+
"supabase_url = os.environ.get(\"SUPABASE_URL\")\n",
|
| 161 |
+
"supabase_key = os.environ.get(\"SUPABASE_SERVICE_KEY\")\n",
|
| 162 |
+
"supabase: Client = create_client(supabase_url, supabase_key)"
|
| 163 |
+
]
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"cell_type": "code",
|
| 167 |
+
"execution_count": 9,
|
| 168 |
+
"id": "aa1402e3",
|
| 169 |
+
"metadata": {
|
| 170 |
+
"id": "aa1402e3"
|
| 171 |
+
},
|
| 172 |
+
"outputs": [],
|
| 173 |
+
"source": [
|
| 174 |
+
"from langchain.schema import Document\n",
|
| 175 |
+
"docs = []\n",
|
| 176 |
+
"cnt = 0\n",
|
| 177 |
+
"for sample in json_QA:\n",
|
| 178 |
+
" content = f\"Question : {sample['Question']}\\n\\nFinal answer : {sample['Final answer']}\"\n",
|
| 179 |
+
" doc = {\n",
|
| 180 |
+
" \"id\" : cnt,\n",
|
| 181 |
+
" \"content\" : content,\n",
|
| 182 |
+
" \"metadata\" : {\n",
|
| 183 |
+
" \"source\" : sample['task_id']\n",
|
| 184 |
+
" },\n",
|
| 185 |
+
" \"embedding\" : embeddings.embed_query(content),\n",
|
| 186 |
+
" }\n",
|
| 187 |
+
" docs.append(doc)\n",
|
| 188 |
+
" cnt += 1\n",
|
| 189 |
+
"\n",
|
| 190 |
+
"# upload the documents to the vector database\n",
|
| 191 |
+
"try:\n",
|
| 192 |
+
" response = (\n",
|
| 193 |
+
" supabase.table(\"documents\")\n",
|
| 194 |
+
" .insert(docs)\n",
|
| 195 |
+
" .execute()\n",
|
| 196 |
+
" )\n",
|
| 197 |
+
"except Exception as exception:\n",
|
| 198 |
+
" print(\"Error inserting data into Supabase:\", exception)\n",
|
| 199 |
+
"\n",
|
| 200 |
+
"# # Save the documents (a list of dict) into a csv file, and manually upload it to Supabase\n",
|
| 201 |
+
"# import pandas as pd\n",
|
| 202 |
+
"# df = pd.DataFrame(docs)\n",
|
| 203 |
+
"# df.to_csv('supabase_docs.csv',index=False)"
|
| 204 |
+
]
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
"cell_type": "code",
|
| 208 |
+
"execution_count": 10,
|
| 209 |
+
"id": "b2a197a4-c0a7-40ac-a773-c3a6239d696e",
|
| 210 |
+
"metadata": {},
|
| 211 |
+
"outputs": [],
|
| 212 |
+
"source": [
|
| 213 |
+
"import pandas as pd\n",
|
| 214 |
+
"df = pd.DataFrame(docs)\n",
|
| 215 |
+
"df.to_csv('supabase_docs_22.csv',index=False)"
|
| 216 |
+
]
|
| 217 |
+
},
|
| 218 |
+
{
|
| 219 |
+
"cell_type": "code",
|
| 220 |
+
"execution_count": 11,
|
| 221 |
+
"id": "dd698b87-fbc7-4d30-b78d-a52b289b7812",
|
| 222 |
+
"metadata": {},
|
| 223 |
+
"outputs": [
|
| 224 |
+
{
|
| 225 |
+
"data": {
|
| 226 |
+
"text/plain": [
|
| 227 |
+
"(165, 4)"
|
| 228 |
+
]
|
| 229 |
+
},
|
| 230 |
+
"execution_count": 11,
|
| 231 |
+
"metadata": {},
|
| 232 |
+
"output_type": "execute_result"
|
| 233 |
+
}
|
| 234 |
+
],
|
| 235 |
+
"source": [
|
| 236 |
+
"df.shape"
|
| 237 |
+
]
|
| 238 |
+
},
|
| 239 |
+
{
|
| 240 |
+
"cell_type": "code",
|
| 241 |
+
"execution_count": 32,
|
| 242 |
+
"id": "9aa7eb5e",
|
| 243 |
+
"metadata": {
|
| 244 |
+
"id": "9aa7eb5e"
|
| 245 |
+
},
|
| 246 |
+
"outputs": [],
|
| 247 |
+
"source": [
|
| 248 |
+
"# add items to vector database\n",
|
| 249 |
+
"vector_store = SupabaseVectorStore(\n",
|
| 250 |
+
" client=supabase,\n",
|
| 251 |
+
" embedding= embeddings,\n",
|
| 252 |
+
" table_name=\"documents\",\n",
|
| 253 |
+
" query_name=\"match_documents_langchain_2\",\n",
|
| 254 |
+
")\n",
|
| 255 |
+
"retriever = vector_store.as_retriever()"
|
| 256 |
+
]
|
| 257 |
+
},
|
| 258 |
+
{
|
| 259 |
+
"cell_type": "code",
|
| 260 |
+
"execution_count": 33,
|
| 261 |
+
"id": "9eecafd1",
|
| 262 |
+
"metadata": {
|
| 263 |
+
"id": "9eecafd1"
|
| 264 |
+
},
|
| 265 |
+
"outputs": [],
|
| 266 |
+
"source": [
|
| 267 |
+
"query = \"On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?\"\n",
|
| 268 |
+
"# matched_docs = vector_store.similarity_search(query, k=2)\n",
|
| 269 |
+
"docs = retriever.invoke(query)"
|
| 270 |
+
]
|
| 271 |
+
},
|
| 272 |
+
{
|
| 273 |
+
"cell_type": "code",
|
| 274 |
+
"execution_count": 34,
|
| 275 |
+
"id": "658e0400-a611-4ce0-abd3-d0e3c3976d1b",
|
| 276 |
+
"metadata": {},
|
| 277 |
+
"outputs": [
|
| 278 |
+
{
|
| 279 |
+
"data": {
|
| 280 |
+
"text/plain": [
|
| 281 |
+
"1"
|
| 282 |
+
]
|
| 283 |
+
},
|
| 284 |
+
"execution_count": 34,
|
| 285 |
+
"metadata": {},
|
| 286 |
+
"output_type": "execute_result"
|
| 287 |
+
}
|
| 288 |
+
],
|
| 289 |
+
"source": [
|
| 290 |
+
"len(docs)"
|
| 291 |
+
]
|
| 292 |
+
},
|
| 293 |
+
{
|
| 294 |
+
"cell_type": "code",
|
| 295 |
+
"execution_count": 35,
|
| 296 |
+
"id": "ff917840",
|
| 297 |
+
"metadata": {
|
| 298 |
+
"id": "ff917840",
|
| 299 |
+
"outputId": "b802cc5b-3d17-405c-d6ed-0c51cfd77285"
|
| 300 |
+
},
|
| 301 |
+
"outputs": [
|
| 302 |
+
{
|
| 303 |
+
"data": {
|
| 304 |
+
"text/plain": [
|
| 305 |
+
"Document(metadata={'source': '840bfca7-4f7b-481a-8794-c560c340185d'}, page_content='Question : On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?\\n\\nFinal answer : 80GSFC21M0002')"
|
| 306 |
+
]
|
| 307 |
+
},
|
| 308 |
+
"execution_count": 35,
|
| 309 |
+
"metadata": {},
|
| 310 |
+
"output_type": "execute_result"
|
| 311 |
+
}
|
| 312 |
+
],
|
| 313 |
+
"source": [
|
| 314 |
+
"docs[0]"
|
| 315 |
+
]
|
| 316 |
+
},
|
| 317 |
+
{
|
| 318 |
+
"cell_type": "code",
|
| 319 |
+
"execution_count": 36,
|
| 320 |
+
"id": "5004471b-5124-4a18-bb0f-4860a370977c",
|
| 321 |
+
"metadata": {},
|
| 322 |
+
"outputs": [],
|
| 323 |
+
"source": [
|
| 324 |
+
"matched_docs = vector_store.similarity_search(query, k=4)"
|
| 325 |
+
]
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"cell_type": "code",
|
| 329 |
+
"execution_count": 37,
|
| 330 |
+
"id": "27faef37-95c5-4cf4-a359-e1c53557d631",
|
| 331 |
+
"metadata": {},
|
| 332 |
+
"outputs": [
|
| 333 |
+
{
|
| 334 |
+
"data": {
|
| 335 |
+
"text/plain": [
|
| 336 |
+
"1"
|
| 337 |
+
]
|
| 338 |
+
},
|
| 339 |
+
"execution_count": 37,
|
| 340 |
+
"metadata": {},
|
| 341 |
+
"output_type": "execute_result"
|
| 342 |
+
}
|
| 343 |
+
],
|
| 344 |
+
"source": [
|
| 345 |
+
"len(matched_docs)"
|
| 346 |
+
]
|
| 347 |
+
},
|
| 348 |
+
{
|
| 349 |
+
"cell_type": "code",
|
| 350 |
+
"execution_count": 38,
|
| 351 |
+
"id": "18c100a4-bde8-4084-a4d2-fd45f8414671",
|
| 352 |
+
"metadata": {},
|
| 353 |
+
"outputs": [],
|
| 354 |
+
"source": [
|
| 355 |
+
"query = \"When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?\""
|
| 356 |
+
]
|
| 357 |
+
},
|
| 358 |
+
{
|
| 359 |
+
"cell_type": "code",
|
| 360 |
+
"execution_count": 39,
|
| 361 |
+
"id": "67cfcf76-a890-4e37-a2fd-562153b21a35",
|
| 362 |
+
"metadata": {},
|
| 363 |
+
"outputs": [],
|
| 364 |
+
"source": [
|
| 365 |
+
"docs = retriever.invoke(query)"
|
| 366 |
+
]
|
| 367 |
+
},
|
| 368 |
+
{
|
| 369 |
+
"cell_type": "code",
|
| 370 |
+
"execution_count": 40,
|
| 371 |
+
"id": "209eb26e-5956-41f0-a599-38706831ed47",
|
| 372 |
+
"metadata": {},
|
| 373 |
+
"outputs": [
|
| 374 |
+
{
|
| 375 |
+
"data": {
|
| 376 |
+
"text/plain": [
|
| 377 |
+
"[Document(metadata={'source': 'd5141ca5-e7a0-469f-bf3e-e773507c86e2'}, page_content='Question : When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect? Answer using the format DD/MM/YYYY.\\n\\nFinal answer : 19/02/2009')]"
|
| 378 |
+
]
|
| 379 |
+
},
|
| 380 |
+
"execution_count": 40,
|
| 381 |
+
"metadata": {},
|
| 382 |
+
"output_type": "execute_result"
|
| 383 |
+
}
|
| 384 |
+
],
|
| 385 |
+
"source": [
|
| 386 |
+
"docs"
|
| 387 |
+
]
|
| 388 |
+
},
|
| 389 |
+
{
|
| 390 |
+
"cell_type": "code",
|
| 391 |
+
"execution_count": 30,
|
| 392 |
+
"id": "21770f59-c6ca-4df6-b29e-3d7442e758d9",
|
| 393 |
+
"metadata": {},
|
| 394 |
+
"outputs": [],
|
| 395 |
+
"source": [
|
| 396 |
+
"matched_docs = vector_store.similarity_search(query, k=4)"
|
| 397 |
+
]
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"cell_type": "code",
|
| 401 |
+
"execution_count": 31,
|
| 402 |
+
"id": "565af38a-ccdc-4dcd-b6d6-035da1c51b12",
|
| 403 |
+
"metadata": {},
|
| 404 |
+
"outputs": [
|
| 405 |
+
{
|
| 406 |
+
"data": {
|
| 407 |
+
"text/plain": [
|
| 408 |
+
"[]"
|
| 409 |
+
]
|
| 410 |
+
},
|
| 411 |
+
"execution_count": 31,
|
| 412 |
+
"metadata": {},
|
| 413 |
+
"output_type": "execute_result"
|
| 414 |
+
}
|
| 415 |
+
],
|
| 416 |
+
"source": [
|
| 417 |
+
"matched_docs"
|
| 418 |
+
]
|
| 419 |
+
},
|
| 420 |
+
{
|
| 421 |
+
"cell_type": "code",
|
| 422 |
+
"execution_count": 21,
|
| 423 |
+
"id": "01c8f337",
|
| 424 |
+
"metadata": {
|
| 425 |
+
"id": "01c8f337",
|
| 426 |
+
"outputId": "b2b05251-1ab1-4019-f272-129294f28708"
|
| 427 |
+
},
|
| 428 |
+
"outputs": [
|
| 429 |
+
{
|
| 430 |
+
"name": "stdout",
|
| 431 |
+
"output_type": "stream",
|
| 432 |
+
"text": [
|
| 433 |
+
"List of tools used in all samples:\n",
|
| 434 |
+
"Total number of tools used: 83\n",
|
| 435 |
+
" βββ web browser: 107\n",
|
| 436 |
+
" βββ image recognition tools (to identify and parse a figure with three axes): 1\n",
|
| 437 |
+
" βββ search engine: 101\n",
|
| 438 |
+
" βββ calculator: 34\n",
|
| 439 |
+
" βββ unlambda compiler (optional): 1\n",
|
| 440 |
+
" βββ a web browser.: 2\n",
|
| 441 |
+
" βββ a search engine.: 2\n",
|
| 442 |
+
" βββ a calculator.: 1\n",
|
| 443 |
+
" βββ microsoft excel: 5\n",
|
| 444 |
+
" βββ google search: 1\n",
|
| 445 |
+
" βββ ne: 9\n",
|
| 446 |
+
" βββ pdf access: 7\n",
|
| 447 |
+
" βββ file handling: 2\n",
|
| 448 |
+
" βββ python: 3\n",
|
| 449 |
+
" βββ image recognition tools: 12\n",
|
| 450 |
+
" βββ jsonld file access: 1\n",
|
| 451 |
+
" βββ video parsing: 1\n",
|
| 452 |
+
" βοΏ½οΏ½β python compiler: 1\n",
|
| 453 |
+
" βββ video recognition tools: 3\n",
|
| 454 |
+
" βββ pdf viewer: 7\n",
|
| 455 |
+
" βββ microsoft excel / google sheets: 3\n",
|
| 456 |
+
" βββ word document access: 1\n",
|
| 457 |
+
" βββ tool to extract text from images: 1\n",
|
| 458 |
+
" βββ a word reversal tool / script: 1\n",
|
| 459 |
+
" βββ counter: 1\n",
|
| 460 |
+
" βββ excel: 3\n",
|
| 461 |
+
" βββ image recognition: 5\n",
|
| 462 |
+
" βββ color recognition: 3\n",
|
| 463 |
+
" βββ excel file access: 3\n",
|
| 464 |
+
" βββ xml file access: 1\n",
|
| 465 |
+
" βββ access to the internet archive, web.archive.org: 1\n",
|
| 466 |
+
" βββ text processing/diff tool: 1\n",
|
| 467 |
+
" βββ gif parsing tools: 1\n",
|
| 468 |
+
" βββ a web browser: 7\n",
|
| 469 |
+
" βββ a search engine: 7\n",
|
| 470 |
+
" βββ a speech-to-text tool: 2\n",
|
| 471 |
+
" βββ code/data analysis tools: 1\n",
|
| 472 |
+
" βββ audio capability: 2\n",
|
| 473 |
+
" βββ pdf reader: 1\n",
|
| 474 |
+
" βββ markdown: 1\n",
|
| 475 |
+
" βββ a calculator: 5\n",
|
| 476 |
+
" βββ access to wikipedia: 3\n",
|
| 477 |
+
" βββ image recognition/ocr: 3\n",
|
| 478 |
+
" βββ google translate access: 1\n",
|
| 479 |
+
" βββ ocr: 4\n",
|
| 480 |
+
" βββ bass note data: 1\n",
|
| 481 |
+
" βββ text editor: 1\n",
|
| 482 |
+
" βββ xlsx file access: 1\n",
|
| 483 |
+
" βββ powerpoint viewer: 1\n",
|
| 484 |
+
" βββ csv file access: 1\n",
|
| 485 |
+
" βββ calculator (or use excel): 1\n",
|
| 486 |
+
" βββ computer algebra system: 1\n",
|
| 487 |
+
" βββ video processing software: 1\n",
|
| 488 |
+
" βββ audio processing software: 1\n",
|
| 489 |
+
" βββ computer vision: 1\n",
|
| 490 |
+
" βββ google maps: 1\n",
|
| 491 |
+
" βββ access to excel files: 1\n",
|
| 492 |
+
" βββ calculator (or ability to count): 1\n",
|
| 493 |
+
" βββ a file interface: 3\n",
|
| 494 |
+
" βββ a python ide: 1\n",
|
| 495 |
+
" βββ spreadsheet editor: 1\n",
|
| 496 |
+
" βββ tools required: 1\n",
|
| 497 |
+
" βββ b browser: 1\n",
|
| 498 |
+
" βββ image recognition and processing tools: 1\n",
|
| 499 |
+
" βββ computer vision or ocr: 1\n",
|
| 500 |
+
" βββ c++ compiler: 1\n",
|
| 501 |
+
" βββ access to google maps: 1\n",
|
| 502 |
+
" βββ youtube player: 1\n",
|
| 503 |
+
" βββ natural language processor: 1\n",
|
| 504 |
+
" βββ graph interaction tools: 1\n",
|
| 505 |
+
" βββ bablyonian cuniform -> arabic legend: 1\n",
|
| 506 |
+
" βββ access to youtube: 1\n",
|
| 507 |
+
" βββ image search tools: 1\n",
|
| 508 |
+
" βββ calculator or counting function: 1\n",
|
| 509 |
+
" βββ a speech-to-text audio processing tool: 1\n",
|
| 510 |
+
" βββ access to academic journal websites: 1\n",
|
| 511 |
+
" βββ pdf reader/extracter: 1\n",
|
| 512 |
+
" βββ rubik's cube model: 1\n",
|
| 513 |
+
" βββ wikipedia: 1\n",
|
| 514 |
+
" βββ video capability: 1\n",
|
| 515 |
+
" βββ image processing tools: 1\n",
|
| 516 |
+
" βββ age recognition software: 1\n",
|
| 517 |
+
" βββ youtube: 1\n"
|
| 518 |
+
]
|
| 519 |
+
}
|
| 520 |
+
],
|
| 521 |
+
"source": [
|
| 522 |
+
"# list of the tools used in all the samples\n",
|
| 523 |
+
"from collections import Counter, OrderedDict\n",
|
| 524 |
+
"\n",
|
| 525 |
+
"tools = []\n",
|
| 526 |
+
"for sample in json_QA:\n",
|
| 527 |
+
" for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
|
| 528 |
+
" tool = tool[2:].strip().lower()\n",
|
| 529 |
+
" if tool.startswith(\"(\"):\n",
|
| 530 |
+
" tool = tool[11:].strip()\n",
|
| 531 |
+
" tools.append(tool)\n",
|
| 532 |
+
"tools_counter = OrderedDict(Counter(tools))\n",
|
| 533 |
+
"print(\"List of tools used in all samples:\")\n",
|
| 534 |
+
"print(\"Total number of tools used:\", len(tools_counter))\n",
|
| 535 |
+
"for tool, count in tools_counter.items():\n",
|
| 536 |
+
" print(f\" βββ {tool}: {count}\")"
|
| 537 |
+
]
|
| 538 |
+
},
|
| 539 |
+
{
|
| 540 |
+
"cell_type": "code",
|
| 541 |
+
"execution_count": 22,
|
| 542 |
+
"id": "b056a03f-6183-4f8d-97b6-63168f745e51",
|
| 543 |
+
"metadata": {},
|
| 544 |
+
"outputs": [
|
| 545 |
+
{
|
| 546 |
+
"data": {
|
| 547 |
+
"text/plain": [
|
| 548 |
+
"83"
|
| 549 |
+
]
|
| 550 |
+
},
|
| 551 |
+
"execution_count": 22,
|
| 552 |
+
"metadata": {},
|
| 553 |
+
"output_type": "execute_result"
|
| 554 |
+
}
|
| 555 |
+
],
|
| 556 |
+
"source": [
|
| 557 |
+
"len(tools_counter)"
|
| 558 |
+
]
|
| 559 |
+
},
|
| 560 |
+
{
|
| 561 |
+
"cell_type": "code",
|
| 562 |
+
"execution_count": null,
|
| 563 |
+
"id": "1bfa81e5-c097-4b0f-be7f-760ef1355928",
|
| 564 |
+
"metadata": {},
|
| 565 |
+
"outputs": [],
|
| 566 |
+
"source": []
|
| 567 |
+
}
|
| 568 |
+
],
|
| 569 |
+
"metadata": {
|
| 570 |
+
"colab": {
|
| 571 |
+
"provenance": []
|
| 572 |
+
},
|
| 573 |
+
"kernelspec": {
|
| 574 |
+
"display_name": "hf-agent",
|
| 575 |
+
"language": "python",
|
| 576 |
+
"name": "hf-agent"
|
| 577 |
+
},
|
| 578 |
+
"language_info": {
|
| 579 |
+
"codemirror_mode": {
|
| 580 |
+
"name": "ipython",
|
| 581 |
+
"version": 3
|
| 582 |
+
},
|
| 583 |
+
"file_extension": ".py",
|
| 584 |
+
"mimetype": "text/x-python",
|
| 585 |
+
"name": "python",
|
| 586 |
+
"nbconvert_exporter": "python",
|
| 587 |
+
"pygments_lexer": "ipython3",
|
| 588 |
+
"version": "3.13.5"
|
| 589 |
+
}
|
| 590 |
+
},
|
| 591 |
+
"nbformat": 4,
|
| 592 |
+
"nbformat_minor": 5
|
| 593 |
+
}
|
supabase_docs.csv
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
supabase_docs_22.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|