|
371 | 371 | "* **Native OpenAI tools first** (web browsing, file ingestion) before reinventing low‑level retrieval. "
|
372 | 372 | ]
|
373 | 373 | },
|
374 |
| - { |
375 |
| - "cell_type": "code", |
376 |
| - "execution_count": null, |
377 |
| - "id": "91eed7c2", |
378 |
| - "metadata": {}, |
379 |
| - "outputs": [ |
380 |
| - { |
381 |
| - "name": "stdout", |
382 |
| - "output_type": "stream", |
383 |
| - "text": [ |
384 |
| - "API_KEY and CSE_ID are: AIzaSyCQH3GUXJwnqOmvBp9U12P54eScvMJLH7c 50c7decc940664df9\n" |
385 |
| - ] |
386 |
| - }, |
387 |
| - { |
388 |
| - "ename": "TypeError", |
389 |
| - "evalue": "An asyncio.Future, a coroutine or an awaitable is required", |
390 |
| - "output_type": "error", |
391 |
| - "traceback": [ |
392 |
| - "\u001b[31m---------------------------------------------------------------------------\u001b[39m\n", |
393 |
| - "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)\n", |
394 |
| - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 19\u001b[39m\n", |
395 |
| - "\u001b[32m 16\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mAPI_KEY and CSE_ID are: \u001b[39m\u001b[33m\"\u001b[39m, api_key, cse_id)\n", |
396 |
| - "\u001b[32m 18\u001b[39m nest_asyncio.apply()\n", |
397 |
| - "\u001b[32m---> \u001b[39m\u001b[32m19\u001b[39m results = \u001b[43masyncio\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mget_results_for_search_term\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mAI Trends\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n", |
398 |
| - "\u001b[32m 21\u001b[39m \u001b[38;5;66;03m# Pretty-print the JSON response (or a friendly message if no results).\u001b[39;00m\n", |
399 |
| - "\u001b[32m 22\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m results:\n", |
400 |
| - "\n", |
401 |
| - "\u001b[36mFile \u001b[39m\u001b[32m~/workspace-28/openai-cookbook/.venv/lib/python3.13/site-packages/nest_asyncio.py:28\u001b[39m, in \u001b[36m_patch_asyncio.<locals>.run\u001b[39m\u001b[34m(main, debug)\u001b[39m\n", |
402 |
| - "\u001b[32m 26\u001b[39m loop = asyncio.get_event_loop()\n", |
403 |
| - "\u001b[32m 27\u001b[39m loop.set_debug(debug)\n", |
404 |
| - "\u001b[32m---> \u001b[39m\u001b[32m28\u001b[39m task = \u001b[43masyncio\u001b[49m\u001b[43m.\u001b[49m\u001b[43mensure_future\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmain\u001b[49m\u001b[43m)\u001b[49m\n", |
405 |
| - "\u001b[32m 29\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n", |
406 |
| - "\u001b[32m 30\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m loop.run_until_complete(task)\n", |
407 |
| - "\n", |
408 |
| - "\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/tasks.py:742\u001b[39m, in \u001b[36mensure_future\u001b[39m\u001b[34m(coro_or_future, loop)\u001b[39m\n", |
409 |
| - "\u001b[32m 740\u001b[39m should_close = \u001b[38;5;28;01mFalse\u001b[39;00m\n", |
410 |
| - "\u001b[32m 741\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n", |
411 |
| - "\u001b[32m--> \u001b[39m\u001b[32m742\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[33m'\u001b[39m\u001b[33mAn asyncio.Future, a coroutine or an awaitable \u001b[39m\u001b[33m'\u001b[39m\n", |
412 |
| - "\u001b[32m 743\u001b[39m \u001b[33m'\u001b[39m\u001b[33mis required\u001b[39m\u001b[33m'\u001b[39m)\n", |
413 |
| - "\u001b[32m 745\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m loop \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", |
414 |
| - "\u001b[32m 746\u001b[39m loop = events.get_event_loop()\n", |
415 |
| - "\n", |
416 |
| - "\u001b[31mTypeError\u001b[39m: An asyncio.Future, a coroutine or an awaitable is required" |
417 |
| - ] |
418 |
| - } |
419 |
| - ], |
420 |
| - "source": [ |
421 |
| - "from ai_research_assistant_resources.utils.web_search_and_util import get_results_for_search_term\n", |
422 |
| - "import json\n", |
423 |
| - "from dotenv import load_dotenv\n", |
424 |
| - "import os\n", |
425 |
| - "import asyncio\n", |
426 |
| - "import nest_asyncio\n", |
427 |
| - "\n", |
428 |
| - "load_dotenv('.env')\n", |
429 |
| - "\n", |
430 |
| - "api_key = os.getenv('API_KEY')\n", |
431 |
| - "cse_id = os.getenv('CSE_ID')\n", |
432 |
| - "\n", |
433 |
| - "if not api_key or not cse_id:\n", |
434 |
| - " raise ValueError(\"API_KEY and CSE_ID must be set as environment variables or in a .env file\")\n", |
435 |
| - "else:\n", |
436 |
| - " print(\"API_KEY and CSE_ID are: \", api_key, cse_id)\n", |
437 |
| - "\n", |
438 |
| - "nest_asyncio.apply()\n", |
439 |
| - "results = asyncio.run(get_results_for_search_term(\"AI Trends\"))\n", |
440 |
| - "\n", |
441 |
| - "# Pretty-print the JSON response (or a friendly message if no results).\n", |
442 |
| - "if results:\n", |
443 |
| - " print(json.dumps(results, indent=2))\n", |
444 |
| - "else:\n", |
445 |
| - " print(\"No results returned. Check your API credentials or search term.\")" |
446 |
| - ] |
447 |
| - }, |
448 | 374 | {
|
449 | 375 | "cell_type": "markdown",
|
450 | 376 | "id": "1bdcab82",
|
|
0 commit comments