Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions examples/huggingface_demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3bc5c094",
"metadata": {},
"source": [
"# OpenDeepSearch + Hugging Face Demo\n",
"Run this notebook to quickly test OpenDeepSearch with Hugging Face Inference API.\n",
"\n",
"👉 Requirements:\n",
"- A Hugging Face account and API token (https://huggingface.co/settings/tokens)\n",
"- `opendeepsearch` installed in your environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "52831ffe",
"metadata": {},
"outputs": [],
"source": [
"from opendeepsearch import OpenDeepSearchTool\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1defad09",
"metadata": {},
"outputs": [],
"source": [
"# 1. Set your Hugging Face API key\n",
"# 👉 Replace with your token from https://huggingface.co/settings/tokens\n",
"os.environ[\"HUGGINGFACE_API_KEY\"] = \"your-hf-api-key\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5be1fa20",
"metadata": {},
"outputs": [],
"source": [
"# 2. Initialize the search agent with a Hugging Face model\n",
"search_agent = OpenDeepSearchTool(\n",
" model_name=\"facebook/bart-large-mnli\", # ✅ correct model name\n",
" reranker=\"jina\"\n",
")\n",
"\n",
"if not search_agent.is_initialized:\n",
" search_agent.setup()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "084c2120",
"metadata": {},
"outputs": [],
"source": [
"# 3. Run a sample query\n",
"query = \"Is Hugging Face great for NLP?\"\n",
"result = search_agent.forward(query)\n",
"\n",
"print(\"🔍 Query:\", query)\n",
"print(\"✅ Result:\", result)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}