Add free-web-search-ultimate cookbook: real-time web search with no A…#2530
Add free-web-search-ultimate cookbook: real-time web search with no A…#2530wd041216-bit wants to merge 9 commits intoopenai:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35955ea909
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
registry.yaml
Outdated
| - title: Real-Time Web Search with GPT Using free-web-search-ultimate | ||
| path: examples/Real_Time_Web_Search_with_GPT_using_free_web_search.ipynb | ||
| slug: real-time-web-search-gpt-free-web-search-ultimate |
There was a problem hiding this comment.
Remove the duplicate
registry.yaml entry for this notebook
This block adds the same notebook a second time under the identical path and slug used a few lines above (registry.yaml:3132-3143). I checked the full file and this becomes the only duplicated slug in registry.yaml, so the cookbook publisher will either render this article twice or let one metadata record overwrite the other depending on how the registry is consumed. Keeping just one entry avoids shipping inconsistent publication metadata.
Useful? React with 👍 / 👎.
Addresses code review by @codex - the entry was duplicated. Keeping only the first occurrence.
Replace deprecated `from free_web_search import search, search_news` with the correct `UltimateSearcher` class from `free_web_search.search_web`.
|
Thank you @chatgpt-codex-connector for the review! I've addressed all the feedback:
The PR is now ready for re-review. Please let me know if there's anything else to address! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ad2b1f620
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "free-web-search \"latest AI news\"\n", | ||
| "\n", | ||
| "# Search for news\n", | ||
| "free-web-search --news \"OpenAI announcements\"\n", |
There was a problem hiding this comment.
Correct the documented CLI commands
This CLI block will not work as written. The package's published entry points expose search-web/browse-page/free-web-search-mcp, and the upstream examples switch to news mode with --type news, not free-web-search --news. Anyone copy-pasting these commands from the notebook will hit command not found or an argparse error, so the standalone CLI section is currently broken.
Useful? React with 👍 / 👎.
| " print(f\"Question: {question}\\n\")\n", | ||
| " \n", | ||
| " # Agentic loop: keep calling GPT until it stops using tools\n", | ||
| " while True:\n", |
There was a problem hiding this comment.
Bound the tool loop before it can run forever
If the model keeps issuing tool calls—for example after repeated No results found. / Error executing ... tool outputs or for an open-ended research prompt—this while True loop never exits and will keep making Chat Completions requests until the notebook is manually interrupted. That can burn tokens unexpectedly in normal interactive use, so this example needs a max-iterations or repeated-failure cutoff.
Useful? React with 👍 / 👎.
- Fix CLI commands: replace 'free-web-search' with correct 'search-web' entry point, and '--news' flag with '--type news' - Add max_iterations=10 guard to agentic while loop to prevent infinite token consumption on repeated tool calls
|
Thank you @chatgpt-codex-connector for the continued review! Both issues from the latest review have been addressed in commit c4c03c9:
The notebook is now ready for re-review. Please let me know if there's anything else to address! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4c03c9cc2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "def search_news(query: str, max_results: int = 5) -> list:\n", | ||
| " \"\"\"Search for recent news articles.\"\"\"\n", | ||
| " answer = _searcher.search(query, search_type='news')\n", |
There was a problem hiding this comment.
Expose a timelimit in
news_search
For prompts like “latest developments in the past week” and “this week”, this wrapper always calls _searcher.search(..., search_type='news') with the package default time window, and the tool schema gives the model no way to request a narrower range. Upstream UltimateSearcher.search() accepts a timelimit argument, and the project’s own CLI examples use --type news --timelimit w for breaking-news queries, so the current notebook can return older articles while presenting them as week-bounded results.
Useful? React with 👍 / 👎.
| "# Example 1: Ask about current AI developments\n", | ||
| "answer = research_with_gpt(\n", | ||
| " \"What are the latest developments in AI language models in the past week?\"\n", | ||
| ")\n", | ||
| "print(answer)" |
There was a problem hiding this comment.
Gate live notebook calls behind an opt-in flag
These example cells start three paid research_with_gpt(...) runs during normal top-to-bottom execution, and the notebook later adds two more live web searches. In a fresh checkout this either fails immediately without OPENAI_API_KEY or spends credits by default just to validate the notebook, which conflicts with this repo’s AGENTS.md guidance to mock or clearly gate external-service calls. Please put the runnable examples behind an explicit opt-in flag instead of executing them unconditionally.
Useful? React with 👍 / 👎.
| "| **MCP Support** | Works as an MCP server for Claude Desktop and other clients |\n", | ||
| "| **CLI Support** | Also works as a standalone CLI tool (`free-web-search`) |\n", |
There was a problem hiding this comment.
Fix the remaining stale CLI command name
The feature table still tells readers the standalone CLI is free-web-search, but the upstream README and CLI parser document search-web as the actual entry point. Someone copying the command name from this summary row will hit a command-not-found error even though the later CLI section was corrected.
Useful? React with 👍 / 👎.
1. Add timelimit parameter to news_search function and tool schema
- search_news() now accepts timelimit arg ('d'/'w'/'m') and passes
it to UltimateSearcher.search() for time-bounded queries
- Tool schema updated so GPT can request 'w' for 'this week' queries
- execute_tool() passes timelimit from tool_input to search_news()
2. Gate live example cells behind RUN_EXAMPLES opt-in flag
- Added RUN_EXAMPLES = False guard cell before the 3 example cells
- All research_with_gpt() calls wrapped in 'if RUN_EXAMPLES:' block
- Prevents accidental API credit consumption on fresh checkout
3. Fix stale CLI command name in feature table
- Changed 'free-web-search' to 'search-web' in the feature table
- Consistent with the CLI section already corrected in c4c03c9
|
Thank you @chatgpt-codex-connector for the continued review! All 3 issues from the latest review have been addressed in commit a30fdac:
The notebook is now fully aligned with the repository's contribution guidelines. Please re-review when convenient! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a30fdac47f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "# Direct web search\n", | ||
| "results = search(\"OpenAI GPT-4o latest updates\", max_results=3)\n", |
There was a problem hiding this comment.
Gate the direct search examples behind
RUN_EXAMPLES
Even with RUN_EXAMPLES = False, running the notebook top-to-bottom still makes outbound DuckDuckGo requests here and again in the next code cell because the direct-usage examples are unconditional. AGENTS.md requires notebook cells that depend on external services to be mocked or gated behind an opt-in flag, so a fresh checkout without network access can still fail or hang despite the new guard around the GPT examples.
Useful? React with 👍 / 👎.
registry.yaml
Outdated
| - realtime | ||
|
|
||
| - title: Real-Time Web Search with GPT Using free-web-search-ultimate | ||
| path: examples/Real_Time_Web_Search_with_GPT_using_free_web_search.ipynb |
There was a problem hiding this comment.
Rename this notebook to the repo's lowercase format
AGENTS.md says new notebooks should use lowercase, dash-or-underscore-separated filenames, but this registry entry publishes examples/Real_Time_Web_Search_with_GPT_using_free_web_search.ipynb with capital letters. Because this is a brand-new notebook, merging it under a nonstandard name makes the cookbook's metadata and future links depend on an avoidable naming exception; it should be renamed before the entry lands.
Useful? React with 👍 / 👎.
… + gate all direct search calls - Renamed notebook from Real_Time_Web_Search_with_GPT_using_free_web_search.ipynb to real_time_web_search_with_gpt_using_free_web_search.ipynb (AGENTS.md requirement) - Updated registry.yaml to reference the new lowercase filename - Cell 15: direct search() call now gated behind 'if RUN_EXAMPLES:' - Cell 16: direct search_news() call indentation fixed + already gated - All cells that make outbound network requests are now protected by RUN_EXAMPLES flag
|
Thank you @chatgpt-codex-connector for the continued review! Both P0 issues from the latest review have been addressed in commit 3a0ddaa:
A fresh checkout with |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a0ddaaf28
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import json\nimport os\nfrom openai import OpenAI\nfrom free_web_search.search_web import UltimateSearcher\nimport json\n\n# Initialize the searcher\n_searcher = UltimateSearcher()\n\ndef search(query: str, max_results: int = 5) -> list:\n \"\"\"Search the web for real-time information.\"\"\"\n answer = _searcher.search(query)\n return [\n {'title': s.title, 'url': s.url, 'snippet': s.snippet}\n for s in answer.sources[:max_results]\n ]\n\ndef search_news(query: str, max_results: int = 5, timelimit: str = None) -> list:\n \"\"\"Search for recent news articles.\n \n Args:\n query: The news topic to search for.\n max_results: Maximum number of articles to return (default: 5).\n timelimit: Optional time window for results. Use 'd' (day), 'w' (week),\n 'm' (month). Defaults to None (no time restriction).\n \n Returns:\n List of dicts with 'title', 'url', 'snippet', and 'date' keys.\n \"\"\"\n kwargs = {'search_type': 'news'}\n if timelimit:\n kwargs['timelimit'] = timelimit\n answer = _searcher.search(query, **kwargs)\n return [\n {'title': s.title, 'url': s.url, 'snippet': s.snippet, 'date': getattr(s, 'date', '')}\n for s in answer.sources[:max_results]\n ]\n\n# Initialize the OpenAI client\n# Make sure OPENAI_API_KEY is set in your environment\nclient = OpenAI()\n\nprint(\"Setup complete!\")" |
There was a problem hiding this comment.
Defer OpenAI client construction until GPT examples run
With RUN_EXAMPLES=False and no OPENAI_API_KEY in the environment, executing the setup cell still instantiates OpenAI() here, which raises before the notebook reaches the gating message or the direct-search examples. That means a fresh user cannot run this notebook top-to-bottom for the advertised free web-search flow unless they already have an OpenAI key configured.
Useful? React with 👍 / 👎.
| " ]\n", | ||
| "\n", | ||
| "\n", | ||
| "def search_news(query: str, max_results: int = 5) -> list:\n", |
There was a problem hiding this comment.
Keep
search_news compatible with the tool executor
This cell overwrites the earlier search_news(query, max_results, timelimit=None) helper with a two-argument version, but execute_tool() still calls search_news(..., timelimit=...). In any notebook session where someone runs the direct-usage section and then reruns research_with_gpt() or a GPT example, every news_search tool call will start failing with an unexpected-keyword-argument error because the global function signature has changed.
Useful? React with 👍 / 👎.
P1: Defer OpenAI client construction until GPT examples run - Replace direct 'client = OpenAI()' with lazy get_openai_client() getter - Client is only instantiated when research_with_gpt() is actually called - Users without OPENAI_API_KEY can still run the free web search cells P2: Keep search_news compatible with execute_tool() - Remove search_news redefinition in Cell 15 (direct usage section) - The redefined version lacked 'timelimit' param, breaking execute_tool() - Cell 15 now reuses the search_news() defined in the setup cell
|
Thank you @chatgpt-codex-connector for the thorough review! All issues from the 5th review have been addressed: P1: Lazy OpenAI client initialization (commit
P2: Removed
Additional fix (commit
All 20 invariants (13 OpenAI-specific + 7 universal) now pass the regression checker. ✅ |
|
Note You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard. |
|
Thank you https://github.com/chatgpt-codex-connector for the thorough review! All issues from the 5th review have been addressed: P1: Lazy OpenAI client initialization (commit 1774af6) Replaced direct client = OpenAI() in the setup cell with a get_openai_client() lazy getter function P2: Removed search_news redefinition (commit 1774af6) Removed the duplicate search_news(query, max_results) definition in Cell 15 that was missing the timelimit parameter Additional fix (commit 9600730) Replaced first-person We'll with second-person You'll in the markdown cell |
- Update notebook title to include v13.0.0 - Pin install command to v13.0.0 (latest) - Add version annotation at UltimateSearcher initialization v13.0.0 ships an internationalized codebase with Google-style docstrings across all modules, improving readability and contributor experience.
🔄 Updated to cross-validated-search v14.0.0This PR has been updated to reflect the renaming and rebranding of the package: Changes:
Key Features:
The notebook will be updated to demonstrate the new cross-validation capabilities. |
Summary
This PR adds a new cookbook demonstrating how to give GPT models real-time web search capabilities using the free-web-search-ultimate Python package — completely free, no additional API keys required.
Motivation
GPT models have a knowledge cutoff and cannot access real-time information. This cookbook shows how to bridge that gap using a free, privacy-respecting web search tool that requires no additional API keys or subscriptions.
For new content
Additional Context