From dc6e6a1187873b049e150b9dbe4522be280d0f13 Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 7 Aug 2025 14:18:05 -0700 Subject: [PATCH 1/5] fixing the links --- .../prompt-optimization-cookbook.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb b/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb index 91905adc47..b71ca5c0ab 100644 --- a/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb +++ b/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb @@ -15,9 +15,9 @@ "source": [ "The GPT-5 Family of models are the smartest models we’ve released to date, representing a step change in the models’ capabilities across the board. GPT-5 is particularly specialized in agentic task performance, coding, and steerability, making it a great fit for everyone from curious users to advanced researchers. \n", "\n", - "GPT-5 will benefit from all the traditional prompting best practices, and to help you construct the best prompt we are introducing a [Prompting Guide for GPT-5](#) explaining how to make the most of its state-of-the-art capabilities. Alongside that, we are introducing a [GPT-5 Specific Prompt Optimizer](#https://platform.openai.com/chat/edit?optimize=true) in our Playground to help users get started on **improving existing prompts** and **migrating prompts** for GPT-5 and other OpenAI models.\n", + "GPT-5 will benefit from all the traditional prompting best practices, and to help you construct the best prompt we are introducing a [Prompting Guide for GPT-5](https://cookbook.openai.com/examples/gpt-5/gpt-5_prompting_guide) explaining how to make the most of its state-of-the-art capabilities. Alongside that, we are introducing a [GPT-5 Specific Prompt Optimizer](https://platform.openai.com/chat/edit?optimize=true) in our Playground to help users get started on **improving existing prompts** and **migrating prompts** for GPT-5 and other OpenAI models.\n", "\n", - "In this cookbook we will go through how you can get spun up quickly to solve your task with GPT-5. We will share results of measurable improvements on common tasks and walk you through how you can use the Prompt Optimizer to do the same.\n" + "In this cookbook we will go through how you can get spun up quickly to solve your task with GPT-5. We will share results of measurable improvements on common tasks and walk you through how you can use the Prompt Optimizer to do the same." ] }, { From a3723324bc22765dcddef704b7364d835425e81b Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 7 Aug 2025 14:25:20 -0700 Subject: [PATCH 2/5] rendering the raw markdown --- .../prompt-optimization-cookbook.ipynb | 88 ++++++++++++++----- 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb b/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb index b71ca5c0ab..af90b9efda 100644 --- a/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb +++ b/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb @@ -548,6 +548,22 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "### Prompt Optimization Results - Coding Tasks\n", + "\n", + "| Metric | Baseline | Optimized | Δ (Opt − Base) |\n", + "|----------------------------|---------:|----------:|---------------:|\n", + "| Avg Time (s) | 7.906 | 6.977 | -0.929 |\n", + "| Peak Memory (KB) | 3626.3 | 577.5 | -3048.8 |\n", + "| Exact (%) | 100.0 | 100.0 | 0.0 |\n", + "| Sorted (%) | 100.0 | 100.0 | 0.0 |\n", + "| LLM Adherence (1–5) | 4.40 | 4.90 | +0.50 |\n", + "| Code Quality (1–5) | 4.73 | 4.90 | +0.16 |\n" + ] } ], "source": [ @@ -573,7 +589,9 @@ " judge_optimized=Path(\"results_llm_as_judge_optimized\")/\"judgement_summary.csv\",\n", ")\n", "\n", - "display(Markdown(md))" + "display(Markdown(md))\n", + "\n", + "print(md)" ] }, { @@ -619,14 +637,6 @@ "We will run FailSafeQA evaluations via the helper script and compare Baseline vs Optimized prompts side by side." ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "c5849f77", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": 3, @@ -834,7 +844,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 11, "id": "c20097e6", "metadata": {}, "outputs": [ @@ -845,10 +855,10 @@ "\n", "**Compliance threshold:** ≥ 6\n", "\n", - "| Metric | Baseline | Optimized | Δ (Opt − Base) |\n", - "|---|---:|---:|---:|\n", - "| Robustness (avg across datapoints) | 0.320 | 0.540 | +0.220 |\n", - "| Context Grounding (avg across datapoints) | 0.800 | 0.950 | +0.150 |\n", + "| Metric | Baseline | Optimized | Δ (Opt − Base) |\n", + "| ----------------------------------------- | -------- | --------- | -------------- |\n", + "| Robustness (avg across datapoints) | 0.320 | 0.540 | +0.220 |\n", + "| Context Grounding (avg across datapoints) | 0.800 | 0.950 | +0.150 |\n", "\n", "_Source files:_ `results_failsafeqa.csv` · `results_failsafeqa.csv`" ], @@ -858,6 +868,22 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "## FailSafeQA — Summary\n", + "\n", + "**Compliance threshold:** ≥ 6\n", + "\n", + "| Metric | Baseline | Optimized | Δ (Opt − Base) |\n", + "| ----------------------------------------- | -------- | --------- | -------------- |\n", + "| Robustness (avg across datapoints) | 0.320 | 0.540 | +0.220 |\n", + "| Context Grounding (avg across datapoints) | 0.800 | 0.950 | +0.150 |\n", + "\n", + "_Source files:_ `results_failsafeqa.csv` · `results_failsafeqa.csv`\n" + ] } ], "source": [ @@ -872,20 +898,39 @@ ") -> str:\n", " d_r = robust_opt - robust_base\n", " d_g = ground_opt - ground_base\n", + "\n", + " # Data rows\n", + " rows = [\n", + " [\"Metric\", \"Baseline\", \"Optimized\", \"Δ (Opt − Base)\"],\n", + " [\"Robustness (avg across datapoints)\", f\"{robust_base:.3f}\", f\"{robust_opt:.3f}\", f\"{d_r:+.3f}\"],\n", + " [\"Context Grounding (avg across datapoints)\", f\"{ground_base:.3f}\", f\"{ground_opt:.3f}\", f\"{d_g:+.3f}\"],\n", + " ]\n", + "\n", + " # Calculate column widths for alignment\n", + " col_widths = [max(len(str(row[i])) for row in rows) for i in range(len(rows[0]))]\n", + "\n", + " # Build table lines with padding\n", + " lines = []\n", + " for i, row in enumerate(rows):\n", + " padded = [str(cell).ljust(col_widths[j]) for j, cell in enumerate(row)]\n", + " lines.append(\"| \" + \" | \".join(padded) + \" |\")\n", + " if i == 0: # after header\n", + " sep = [\"-\" * col_widths[j] for j in range(len(row))]\n", + " lines.append(\"| \" + \" | \".join(sep) + \" |\")\n", + "\n", + " table = \"\\n\".join(lines)\n", + "\n", " return f\"\"\"\n", "## FailSafeQA — Summary\n", "\n", "**Compliance threshold:** ≥ {threshold}\n", "\n", - "| Metric | Baseline | Optimized | Δ (Opt − Base) |\n", - "|---|---:|---:|---:|\n", - "| Robustness (avg across datapoints) | {robust_base:.3f} | {robust_opt:.3f} | {d_r:+.3f} |\n", - "| Context Grounding (avg across datapoints) | {ground_base:.3f} | {ground_opt:.3f} | {d_g:+.3f} |\n", + "{table}\n", "\n", "_Source files:_ `{src_base}` · `{src_opt}`\n", "\"\"\".strip()\n", "\n", - "# Fill in with your reported numbers\n", + "# Usage\n", "md = build_markdown_summary_from_metrics(\n", " robust_base=0.320, ground_base=0.800,\n", " robust_opt=0.540, ground_opt=0.950,\n", @@ -894,7 +939,10 @@ " src_opt=\"results_failsafeqa.csv\",\n", ")\n", "\n", - "display(Markdown(md))" + "# Notebook pretty\n", + "display(Markdown(md))\n", + "\n", + "print(md)" ] }, { From c14d50ea7772867ebeb6db17e43c414305524737 Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 7 Aug 2025 14:30:07 -0700 Subject: [PATCH 3/5] moving cookbook into gpt-5 folder --- .../prompt-optimization-cookbook.ipynb | 0 registry.yaml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename examples/gpt-5/{prompt-optimization-cookbook => }/prompt-optimization-cookbook.ipynb (100%) diff --git a/examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb b/examples/gpt-5/prompt-optimization-cookbook.ipynb similarity index 100% rename from examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb rename to examples/gpt-5/prompt-optimization-cookbook.ipynb diff --git a/registry.yaml b/registry.yaml index c9c9f4699d..41fcac164a 100644 --- a/registry.yaml +++ b/registry.yaml @@ -5,7 +5,7 @@ # authors for each page. - title: GPT-5 Prompt Migration and Improvement Using the New Optimizer - path: examples/gpt-5/prompt-optimization-cookbook/prompt-optimization-cookbook.ipynb + path: examples/gpt-5/prompt-optimization-cookbook.ipynb date: 2025-08-07 authors: - rajpathak-openai From 10eacd5bc2a29e8d7403ec43ffe27650139beebe Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 7 Aug 2025 14:31:09 -0700 Subject: [PATCH 4/5] fix image paths --- examples/gpt-5/prompt-optimization-cookbook.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gpt-5/prompt-optimization-cookbook.ipynb b/examples/gpt-5/prompt-optimization-cookbook.ipynb index af90b9efda..77e83eb81e 100644 --- a/examples/gpt-5/prompt-optimization-cookbook.ipynb +++ b/examples/gpt-5/prompt-optimization-cookbook.ipynb @@ -257,7 +257,7 @@ "\n", "From there press the **Optimize** button. This will open the optimization panel. At this stage, you can either provide specific edits you'd like to see reflected in the prompt or simply press **Optimize** to have it refined according to best practices for the target model and task. To start let's do just this.\n", "\n", - "![optimize_image](../../../images/image_optimize_1.png)\n", + "![optimize_image](../../images/image_optimize_1.png)\n", "\n", "\n", "\n", @@ -269,7 +269,7 @@ "\n", "This is easy using the iterative process of the Prompt Optimizer.\n", "\n", - "![optimize_image](../../../images/image_optimize_2.png)\n", + "![optimize_image](../../images/image_optimize_2.png)\n", "\n" ] }, @@ -280,7 +280,7 @@ "source": [ "Once we are happy with the optimized version of our prompt, we can save it as a [Prompt Object](#https://platform.openai.com/docs/guides/prompt-engineering#reusable-prompts) using a button on the top right of the optimizer. We can use this object within our API Calls which can help with future iteration, version management, and reusability across different applications. \n", "\n", - "![optimize_image](../../../images/image_optimize_3.png)\n" + "![optimize_image](../../images/image_optimize_3.png)\n" ] }, { @@ -621,7 +621,7 @@ "\n", "Most production use cases face imperfect queries and noisy context. **FailSafeQA** is an excellent benchmark that deliberately perturbs both the **query** (misspellings, incompleteness, off-domain phrasing) and the **context** (missing, OCR-corrupted, or irrelevant docs) and reports **Robustness**, **Context Grounding**, and **Compliance**—i.e., can the model answer when the signal exists and abstain when it doesn’t.\n", "\n", - "![FailSafeQA diagram](../../../images/image_optimize_4.png)\n", + "![FailSafeQA diagram](../../images/image_optimize_4.png)\n", "\n", "**Links**\n", "- Paper (arXiv): *Expect the Unexpected: FailSafe Long Context QA for Finance* — https://arxiv.org/abs/2502.06329 \n", @@ -659,7 +659,7 @@ "We can use the prompt optimizer once again to construct a new prompt that is more suitable for this use case. Drawing on best practices for long-context question answering, we know that we should remind our answer model to rely on information in the context section and refuse answers to questions if the context is insufficient. By using the Optimize button once without any arguments we get a reasonable structure for the prompt and end up with this as our optimized prompt.\n", "\n", "\n", - "![optimize_image](../../../images/image_optimize_5.png)\n", + "![optimize_image](../../images/image_optimize_5.png)\n", "\n" ] }, From 6006e5dfb3d958ec72f5f137b1daaf1f6be48550 Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 7 Aug 2025 14:34:15 -0700 Subject: [PATCH 5/5] notes formatting --- .../gpt-5/prompt-optimization-cookbook.ipynb | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/gpt-5/prompt-optimization-cookbook.ipynb b/examples/gpt-5/prompt-optimization-cookbook.ipynb index 77e83eb81e..4709740e17 100644 --- a/examples/gpt-5/prompt-optimization-cookbook.ipynb +++ b/examples/gpt-5/prompt-optimization-cookbook.ipynb @@ -35,7 +35,6 @@ "\n", "Along with tuning the prompt for the target model, the Optimizer is cognizant of the specific task you are trying to accomplish and can apply crucial practices to boost performance in Agentic Workflows, Coding and Multi-Modality. Let's walk through some before-and-afters to see where prompt optimization shines. \n", "\n", - "> [!NOTE]\n", "> Remember that prompting is not a one-size-fits-all experience, so we recommend running thorough experiments and iterating to find the best solution for your problem." ] }, @@ -44,16 +43,24 @@ "id": "8fcbc964", "metadata": {}, "source": [ - "> [!IMPORTANT]\n", + "\n", "> Ensure you have set up your OpenAI API Key set as `OPENAI_API_KEY` and have access to GPT-5\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "5a0d077c", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OPENAI_API_KEY is set!\n" + ] + } + ], "source": [ "import os\n", "\n", @@ -111,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "377cc6f4", "metadata": {}, "outputs": [], @@ -130,12 +137,6 @@ "\"\"\"\n" ] }, - { - "cell_type": "markdown", - "id": "66ae7a26", - "metadata": {}, - "source": [] - }, { "cell_type": "markdown", "id": "01b0e8b3", @@ -969,9 +970,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3.12 (jupyter)", "language": "python", - "name": "python3" + "name": "jupyter-py312" }, "language_info": { "codemirror_mode": { @@ -983,7 +984,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.13" + "version": "3.12.10" } }, "nbformat": 4,