CoolFace
Apppublic

eiingeeel/gaia-benchmark-agent

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
test.ipynb148 linesDownload Raw Back to root
1{2 "cells": [3  {4   "cell_type": "code",5   "execution_count": null,6   "id": "09ef97ef",7   "metadata": {},8   "outputs": [],9   "source": [10    "%run app.py"11   ]12  },13  {14   "cell_type": "code",15   "execution_count": null,16   "id": "c234de78",17   "metadata": {},18   "outputs": [],19   "source": [20    "import json\n",21    "from langchain_core.documents import Document\n",22    "from langchain_chroma import Chroma\n",23    "from langchain_core.documents import Document\n",24    "from src.services.azure_ai_fountry import embeddings\n",25    "\n",26    "# Config\n",27    "jsonl_path = \"src/core/db/metadata.jsonl\"\n",28    "persist_directory = \"./chroma_langchain_db\"\n",29    "\n",30    "\n",31    "# Initialize Chroma DB\n",32    "vector_store = Chroma(\n",33    "    collection_name=\"documents\",\n",34    "    embedding_function=embeddings,\n",35    "    persist_directory=persist_directory,\n",36    ")\n",37    "\n",38    "# Read the metadata.jsonl file\n",39    "documents = []\n",40    "with open(jsonl_path, \"r\", encoding=\"utf-8\") as f:\n",41    "    for line in f:\n",42    "        try:\n",43    "            data = json.loads(line)\n",44    "            content = data.get(\"content\") or data.get(\"text\") or str(data)\n",45    "\n",46    "            # Store the entire line as a string in metadata\n",47    "            metadata = {\n",48    "                \"raw_json\": line.strip()  # store the raw JSON as string\n",49    "            }\n",50    "\n",51    "            doc = Document(page_content=content, metadata=metadata)\n",52    "            documents.append(doc)\n",53    "        except json.JSONDecodeError as e:\n",54    "            print(f\"Skipping invalid line: {e}\")\n",55    "\n",56    "# Add to Chroma and persist\n",57    "vector_store.add_documents(documents)\n",58    "\n",59    "\n",60    "query = \"What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?\"\n",61    "similar_docs = vector_store.similarity_search(query, k=1)\n"62   ]63  },64  {65   "cell_type": "code",66   "execution_count": 2,67   "id": "43ce0c91",68   "metadata": {},69   "outputs": [70    {71     "data": {72      "text/plain": [73       "'What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?'"74      ]75     },76     "execution_count": 2,77     "metadata": {},78     "output_type": "execute_result"79    }80   ],81   "source": [82    "query"83   ]84  },85  {86   "cell_type": "code",87   "execution_count": null,88   "id": "ffd88868",89   "metadata": {},90   "outputs": [],91   "source": [92    "import os\n",93    "persist_directory = \"./chroma_langchain_db\"\n",94    "os.makedirs(persist_directory, exist_ok=True)  # Create if missing\n",95    "with open(\"./chroma_langchain_db/_write_test.txt\", \"w\") as f:\n",96    "    f.write(\"test\")\n"97   ]98  },99  {100   "cell_type": "code",101   "execution_count": null,102   "id": "1985bd23",103   "metadata": {},104   "outputs": [],105   "source": [106    "from src.core.build_graph import build_graph\n",107    "from langchain_core.runnables.graph import MermaidDrawMethod\n",108    "\n",109    "graph = build_graph()\n",110    "\n",111    "img_data = graph.get_graph().draw_mermaid_png(draw_method=MermaidDrawMethod.API,)\n",112    "\n",113    "with open('graph.png', \"wb\") as f:\n",114    "        f.write(img_data)"115   ]116  },117  {118   "cell_type": "code",119   "execution_count": null,120   "id": "ae7eff4f",121   "metadata": {},122   "outputs": [],123   "source": []124  }125 ],126 "metadata": {127  "kernelspec": {128   "display_name": ".venv",129   "language": "python",130   "name": "python3"131  },132  "language_info": {133   "codemirror_mode": {134    "name": "ipython",135    "version": 3136   },137   "file_extension": ".py",138   "mimetype": "text/x-python",139   "name": "python",140   "nbconvert_exporter": "python",141   "pygments_lexer": "ipython3",142   "version": "3.12.3"143  }144 },145 "nbformat": 4,146 "nbformat_minor": 5147}148