Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
12 changes: 6 additions & 6 deletions examples/Reinforcement_Fine_Tuning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,8 @@
"outputs": [],
"source": [
"# Set your training and test file paths\n",
"train_file = \"data/medical_01_verifiable_problem_train_with_prompt.jsonl\"\n",
"test_file = \"data/medical_01_verifiable_problem_val_with_prompt.jsonl\"\n",
"train_file = \"data/medical_01_verifiable_problem_train_simple_prompt.jsonl\"\n",
"test_file = \"data/medical_01_verifiable_problem_val_simple_prompt.jsonl\"\n",
"\n",
"def upload_file(file_path: str) -> str:\n",
" \"\"\"Upload a file to the OpenAI platform for fine-tuning.\"\"\"\n",
Expand Down Expand Up @@ -1389,7 +1389,7 @@
"grader = model_grader_2\n",
"response_format = None\n",
"compute_multiplier = 1.0\n",
"etest_samples = 1\n",
"eval_samples = 1\n",
"eval_interval = 5"
]
},
Expand All @@ -1409,7 +1409,7 @@
"# Launch the RFT job\n",
"payload = dict(\n",
" training_file=train_file_id,\n",
" test_file=test_file_id,\n",
" validation_file=test_file_id,\n",
" model=model,\n",
" suffix=suffix,\n",
" method=dict(\n",
Expand All @@ -1419,7 +1419,7 @@
" response_format=response_format,\n",
" hyperparameters=dict(\n",
" compute_multiplier=compute_multiplier,\n",
" etest_samples=etest_samples,\n",
" eval_samples=eval_samples,\n",
" eval_interval=eval_interval,\n",
" n_epochs=n_epochs,\n",
" reasoning_effort=reasoning_effort,\n",
Expand Down Expand Up @@ -2116,7 +2116,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.12.9"
}
},
"nbformat": 4,
Expand Down
12 changes: 12 additions & 0 deletions examples/o-series/o3o4-mini_prompting_guide.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@
"Validate arguments against the format before sending the call; if you are unsure, ask for clarification instead of guessing.\n",
"```\n",
"\n",
"3. Another note on lazy behavior\n",
"We are aware of rare instances of lazy behavior from o3, such as stating it does not have enough time to complete a task, promising to follow up separately, or giving terse answers even when explicitly prompted to provide more detail. We have found that the following steps help ameliorate this behavior:\n",
"\n",
" a. Start a new conversation for unrelated topics:\n",
" When switching to a new or unrelated topic, begin a fresh conversation thread rather than continuing in the same context. This helps the model focus on the current subject and prevents it from being influenced by previous, irrelevant context, which can sometimes lead to incomplete or lazy responses. For example, if you were previously discussing code debugging and now want to ask about documentation best practices, which does not require previous conversation context, start a new conversation to ensure clarity and focus.\n",
"\n",
" b. Discard irrelevant past tool calls/outputs when the list gets too long, and summarize them as context in the user message:\n",
" If the conversation history contains a long list of previous tool calls or outputs that are no longer relevant, remove them from the context. Instead, provide a concise summary of the important information as part of the user message. This keeps the context manageable and ensures the model has access to only the most pertinent information. For instance, if you have a lengthy sequence of tool outputs, you can summarize the key results and include only that summary in your next message.\n",
"\n",
" c. We are constantly improving our models and expect to have this issue addressed in future versions.\n",
"\n",
"\n",
"### Avoid Chain of Thought Prompting\n",
"Since these models are reasoning models and produce an internal chain of thought, they do not have to be explicitly prompted to plan and reason between toolcalls. Therefore, a developer should not try to induce additional reasoning before each function call by asking the model to plan more extensively. Asking a reasoning model to reason more may actually hurt the performance. \n",
"\n",
Expand Down
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
107 changes: 107 additions & 0 deletions examples/partners/mcp_powered_voice_agents/search_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import os
from mcp.server.fastmcp import FastMCP
from openai import OpenAI
from agents import set_tracing_export_api_key

# Create server
mcp = FastMCP("Search Server")
_vector_store_id = ""

def _run_rag(query: str) -> str:
"""Do a search for answers within the knowledge base and internal documents of the user.
Args:
query: The user query
"""
results = client.vector_stores.search(
vector_store_id=_vector_store_id,
query=query,
rewrite_query=True, # Query rewriting generally improves results
)
return results.data[0].content[0].text


def _summarize_rag_response(rag_output: str) -> str:
"""Summarize the RAG response using GPT-4
Args:
rag_output: The RAG response
"""
response = client.responses.create(
model="gpt-4.1-mini",
tools=[{"type": "web_search_preview"}],
input="Summarize the following text concisely: \n\n" + rag_output,
)
return response.output_text


@mcp.tool()
def generate_rag_output(query: str) -> str:
"""Generate a summarized RAG output for a given query.
Args:
query: The user query
"""
print("[debug-server] generate_rag_output: ", query)
rag_output = _run_rag(query)
return _summarize_rag_response(rag_output)


@mcp.tool()
def run_web_search(query: str) -> str:
"""Run a web search for the given query.
Args:
query: The user query
"""
print("[debug-server] run_web_search:", query)
response = client.responses.create(
model="gpt-4.1-mini",
tools=[{"type": "web_search_preview"}],
input=query,
)
return response.output_text


def index_documents(directory: str):
"""Index the documents in the given directory to the vector store
Args:
directory: The directory to index the documents from
"""
# OpenAI supported file extensions for retrieval (see docs)
SUPPORTED_EXTENSIONS = {'.pdf', '.txt', '.md', '.docx', '.pptx', '.csv', '.rtf', '.html', '.json', '.xml'}
# Collect all files in the specified directory
files = [os.path.join(directory, f) for f in os.listdir(directory)]
# Filter files for supported extensions only
supported_files = []
for file_path in files:
_, ext = os.path.splitext(file_path)
if ext.lower() in SUPPORTED_EXTENSIONS:
supported_files.append(file_path)
else:
print(f"[warning] Skipping unsupported file for retrieval: {file_path}")

vector_store = client.vector_stores.create( # Create vector store
name="Support FAQ",
)
global _vector_store_id
_vector_store_id = vector_store.id

for file_path in supported_files:
# Upload each file to the vector store, ensuring the file handle is closed
with open(file_path, "rb") as fp:
client.vector_stores.files.upload_and_poll(
vector_store_id=vector_store.id,
file=fp
)
print(f"[debug-server] uploading file: {file_path}")


if __name__ == "__main__":
oai_api_key = os.environ.get("OPENAI_API_KEY")
if not oai_api_key:
raise ValueError("OPENAI_API_KEY environment variable is not set")
set_tracing_export_api_key(oai_api_key)
client = OpenAI(api_key=oai_api_key)

current_dir = os.path.dirname(os.path.abspath(__file__))
samples_dir = os.path.join(current_dir, "sample_files")
index_documents(samples_dir)

mcp.run(transport="sse")
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "8c304b93",
"metadata": {},
"outputs": [],
"source": [
"# install packages\n",
"\n",
"!python3 -m pip install -qU openai pandas wget elasticsearch\n",
"! python3 -m pip install -qU openai pandas wget elasticsearch\n",
"\n",
"# import modules\n",
"\n",
Expand All @@ -54,7 +54,7 @@
"import zipfile\n",
"import pandas as pd\n",
"import json\n",
"import openai"
"from openai import OpenAI"
]
},
{
Expand Down Expand Up @@ -321,25 +321,21 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"id": "57385c69",
"metadata": {},
"outputs": [],
"source": [
"# Get OpenAI API key\n",
"OPENAI_API_KEY = getpass(\"Enter OpenAI API key\")\n",
"\n",
"# Set API key\n",
"openai.api_key = OPENAI_API_KEY\n",
"\n",
"# Define model\n",
"EMBEDDING_MODEL = \"text-embedding-3-small\"\n",
"# Create OpenAI client\n",
"openai_client = OpenAI()\n",
"\n",
"# Define question\n",
"question = 'Is the Atlantic the biggest ocean in the world?'\n",
"\n",
"# Create embedding\n",
"question_embedding = openai.Embedding.create(input=question, model=EMBEDDING_MODEL)\n"
"question_embedding = openai_client.embeddings.create(\n",
" input=question,\n",
" model=\"text-embedding-3-small\"\n",
")"
]
},
{
Expand Down Expand Up @@ -383,7 +379,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"id": "fc834fdd",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -764,7 +760,7 @@
" index = \"wikipedia_vector_index\",\n",
" knn={\n",
" \"field\": \"content_vector\",\n",
" \"query_vector\": question_embedding[\"data\"][0][\"embedding\"],\n",
" \"query_vector\": question_embedding.data[0].embedding,\n",
" \"k\": 10,\n",
" \"num_candidates\": 100\n",
" }\n",
Expand Down
Binary file added images/System_flow_partner_mcp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Traces-1_partner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Traces-2_partner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/partner_mcp_Cookbook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/trace-sk1_partner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/traces_partner_granular.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
# should build pages for, and indicates metadata such as tags, creation date and
# authors for each page.

- title: MCP Powered Voice Agents
path: examples/partners/mcp_powered_voice_agents/mcp_powered_agents_cookbook.ipynb
date: 2025-06-12
authors:
- shikhar-cyber
- Cece Z
- Sibon li
tags:
- mcp
- voice
- agents-sdk
- functions
- tracing

- title: Eval Driven System Design - From Prototype to Production
path: examples/partners/eval_driven_system_design/receipt_inspection.ipynb
date: 2025-06-02
Expand Down Expand Up @@ -866,7 +880,6 @@
- leemthompo
tags:
- embeddings
- completions

- title: Using Hologres as a vector database for OpenAI embeddings
path: >-
Expand Down