Skip to content

Commit 9230441

Browse files
use openai web saerch, update models used
1 parent 02159ed commit 9230441

File tree

9 files changed

+336
-323
lines changed

9 files changed

+336
-323
lines changed

authors.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# You can optionally customize how your information shows up cookbook.openai.com over here.
44
# If your information is not present here, it will be pulled from your GitHub profile.
55

6+
moustafa-openai:
7+
name: "Moustafa Elhadary"
8+
website: "https://www.linkedin.com/in/moustafaelhadary/"
9+
avatar: "https://avatars.githubusercontent.com/u/198829901?v=4"
10+
611
theophile-openai:
712
name: "Theophile Sautory"
813
website: "https://www.linkedin.com/in/theophilesautory"

examples/agents_sdk/AI_Research_Assistant_Cookbook.ipynb

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@
5858
"\n",
5959
"| Step | Purpose | Model |\n",
6060
"|------|---------|-------|\n",
61-
"| **Query Expansion** | Draft multi‑facet prompts / hypotheses | `gpt‑4o` |\n",
62-
"| **Search‑Term Generation** | Expand/clean user query into rich keyword list | `gpt‑4o` |\n",
63-
"| **Conduct Research** | Run web & internal searches, rank & summarise results | `gpt‑4o` + tools |\n",
64-
"| **Draft Report** | Produce first narrative with reasoning & inline citations | `o1` / `gpt‑4o` |\n",
65-
"| **Report Expansion** | Polish formatting, add charts / images / appendix | `gpt‑4o` + tools |"
61+
"| **Query Expansion** | Draft multi‑facet prompts / hypotheses | `o4-mini` |\n",
62+
"| **Search‑Term Generation** | Expand/clean user query into rich keyword list | `gpt‑4.1` |\n",
63+
"| **Conduct Research** | Run web & internal searches, rank & summarise results | `gpt‑4.1` + tools |\n",
64+
"| **Draft Report** | Produce first narrative with reasoning & inline citations | `o3` |\n",
65+
"| **Report Expansion** | Polish formatting, add charts / images / appendix | `gpt‑4.1` + tools |"
6666
]
6767
},
6868
{
@@ -97,10 +97,18 @@
9797
},
9898
{
9999
"cell_type": "code",
100-
"execution_count": null,
100+
"execution_count": 1,
101101
"id": "3a16ac1f",
102102
"metadata": {},
103-
"outputs": [],
103+
"outputs": [
104+
{
105+
"name": "stdout",
106+
"output_type": "stream",
107+
"text": [
108+
"Note: you may need to restart the kernel to use updated packages.\n"
109+
]
110+
}
111+
],
104112
"source": [
105113
"%pip install openai openai-agents --quiet"
106114
]
@@ -139,10 +147,18 @@
139147
},
140148
{
141149
"cell_type": "code",
142-
"execution_count": null,
150+
"execution_count": 2,
143151
"id": "620f9e40",
144152
"metadata": {},
145-
"outputs": [],
153+
"outputs": [
154+
{
155+
"name": "stdout",
156+
"output_type": "stream",
157+
"text": [
158+
"🚫 Guardrail tripped – not an AI topic: The user's request focuses on the luxury goods market, which pertains to market trends in the luxury sector rather than artificial intelligence. Therefore, it is not about AI.\n"
159+
]
160+
}
161+
],
146162
"source": [
147163
"from ai_research_assistant_resources.agents_tools_registry.query_expansion_agent import QueryExpansionAgent\n",
148164
"from agents import InputGuardrailTripwireTriggered\n",
@@ -162,7 +178,7 @@
162178
},
163179
{
164180
"cell_type": "code",
165-
"execution_count": 1,
181+
"execution_count": 3,
166182
"id": "77364239",
167183
"metadata": {},
168184
"outputs": [
@@ -172,13 +188,17 @@
172188
"text": [
173189
"\n",
174190
"The task is not clear. The agent asks:\n",
175-
" Could you please specify the timeframe for the research report (e.g., current year, last 5 years, last 10 years, or all time)? Also, are there specific sectors or applications within AI (such as machine learning, robotics, natural language processing, etc.) you want to focus on?\n",
191+
" 1. What timeframe should the report cover (e.g., the past year, the past five years, up to current date)?\n",
192+
"2. Should the report focus on specific AI subfields (e.g., natural language processing, computer vision, reinforcement learning) or provide a general overview?\n",
193+
"3. Are there particular industries or application domains (e.g., healthcare, finance, manufacturing) you want the report to emphasize?\n",
194+
"4. What length or depth do you expect for the report (e.g., a brief summary, a detailed 20-page analysis)?\n",
195+
"5. Who is the target audience for the report (e.g., technical researchers, business executives, policymakers)?\n",
176196
"\n",
177197
"\n",
178-
"user input: 5 years healthcare\n",
198+
"user input: 5 years, AI in healthcare, exec summary \n",
179199
"\n",
180200
"Expanded query:\n",
181-
" Draft a comprehensive research report analyzing the latest trends in artificial intelligence (AI) developments within the healthcare industry over the past five years. The report should evaluate advancements in machine learning, deep learning, natural language processing, medical imaging, and other relevant AI applications, while also examining regulatory, ethical, and operational impacts on healthcare delivery. Include detailed case studies, emerging research areas, and recommendations for future innovation in the industry.\n"
201+
" Draft an executive summary research report on the latest trends in AI developments in healthcare over the past five years. Summarize key advancements across major subfields such as diagnostic imaging, predictive analytics, natural language processing for clinical documentation, and personalized medicine. Highlight impactful case studies, emerging technologies, regulatory considerations, and potential challenges. Provide high-level insights on market adoption, ROI metrics, and strategic recommendations for healthcare executives.\n"
182202
]
183203
}
184204
],
@@ -234,17 +254,17 @@
234254
},
235255
{
236256
"cell_type": "code",
237-
"execution_count": 2,
257+
"execution_count": 4,
238258
"id": "f15e0c10",
239259
"metadata": {},
240260
"outputs": [
241261
{
242262
"name": "stdout",
243263
"output_type": "stream",
244264
"text": [
245-
"1. AI trends in healthcare 2025\n",
246-
"2. Machine learning advancements in medical imaging\n",
247-
"3. Ethical impacts of AI in healthcare 2025\n"
265+
"1. Latest AI trends in healthcare 2025 report\n",
266+
"2. Advancements in AI for diagnostic imaging and predictive analytics 2020-2025\n",
267+
"3. Impactful AI case studies in healthcare and market adoption analysis 2025\n"
248268
]
249269
}
250270
],
@@ -283,52 +303,37 @@
283303
},
284304
{
285305
"cell_type": "code",
286-
"execution_count": 3,
306+
"execution_count": 5,
287307
"id": "7b7260c5",
288308
"metadata": {},
289309
"outputs": [
290310
{
291311
"name": "stdout",
292312
"output_type": "stream",
293313
"text": [
294-
"Search Query 1. AI trends in healthcare 2025\n",
295-
"Search Query 2. Machine learning advancements in medical imaging\n",
296-
"Search Query 3. Ethical impacts of AI in healthcare 2025\n",
297-
"Failed to retrieve https://www.unesco.org/en/artificial-intelligence/recommendation-ethics: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))\n",
298-
"Error: skipped URL: https://www.unesco.org/en/artificial-intelligence/recommendation-ethics\n",
314+
"Search Query 1: Latest AI trends in healthcare 2025 report\n",
315+
"Search Query 2: Advancements in AI for diagnostic imaging and predictive analytics 2020-2025\n",
316+
"Search Query 3: Impactful AI case studies in healthcare and market adoption analysis 2025\n",
299317
"Results written to research_results.json\n"
300318
]
301319
}
302320
],
303321
"source": [
304322
"from ai_research_assistant_resources.utils.web_search_and_util import get_results_for_search_term\n",
305323
"import json\n",
306-
"from dotenv import load_dotenv\n",
307-
"import os\n",
308-
"\n",
309-
"load_dotenv('.env')\n",
310-
"\n",
311-
"api_key = os.getenv('API_KEY')\n",
312-
"cse_id = os.getenv('CSE_ID')\n",
313-
"\n",
314-
"if not api_key or not cse_id:\n",
315-
" raise ValueError(\"API_KEY and CSE_ID must be set as environment variables or in a .env file\")\n",
316324
"\n",
317325
"research_results = []\n",
318326
"\n",
319-
"for i, query in enumerate(search_terms_raw.Search_Queries, start=1):\n",
320-
" print(f\"Search Query {i}. {query}\")\n",
321-
" results = get_results_for_search_term(query)\n",
322-
" research_results.append(results)\n",
327+
"for idx, query in enumerate(search_terms_raw.Search_Queries, 1):\n",
328+
" print(f\"Search Query {idx}: {query}\")\n",
329+
" research_results.append(get_results_for_search_term(query))\n",
323330
"\n",
324-
"# Pretty-print the JSON response (or a friendly message if no results).\n",
325-
"if results:\n",
326-
" # Write results to a file\n",
331+
"if research_results: \n",
327332
" with open(\"research_results.json\", \"w\", encoding=\"utf-8\") as f:\n",
328333
" json.dump(research_results, f, indent=2, ensure_ascii=False)\n",
329334
" print(\"Results written to research_results.json\")\n",
330335
"else:\n",
331-
" print(\"No results returned. Check your API credentials or search term.\")"
336+
" print(\"No results returned.\")\n"
332337
]
333338
},
334339
{
@@ -341,7 +346,7 @@
341346
},
342347
{
343348
"cell_type": "code",
344-
"execution_count": 5,
349+
"execution_count": 6,
345350
"id": "076a6f22",
346351
"metadata": {},
347352
"outputs": [
@@ -407,7 +412,7 @@
407412
},
408413
{
409414
"cell_type": "code",
410-
"execution_count": null,
415+
"execution_count": 7,
411416
"id": "7ad9315b",
412417
"metadata": {},
413418
"outputs": [],
@@ -544,7 +549,7 @@
544549
],
545550
"metadata": {
546551
"kernelspec": {
547-
"display_name": ".venv",
552+
"display_name": "openai",
548553
"language": "python",
549554
"name": "python3"
550555
},
@@ -558,7 +563,7 @@
558563
"name": "python",
559564
"nbconvert_exporter": "python",
560565
"pygments_lexer": "ipython3",
561-
"version": "3.13.1"
566+
"version": "3.12.9"
562567
}
563568
},
564569
"nbformat": 4,

0 commit comments

Comments
 (0)