Skip to content

Commit f997fe3

Browse files
authored
Merge branch 'main' into dev/corwin/improve-mcp-eval-book
2 parents f180e6d + 569af89 commit f997fe3

15 files changed

+1101
-12
lines changed

examples/partners/eval_driven_system_design/receipt_inspection.ipynb

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,9 @@
139139
"\n",
140140
"### 2. Assemble Examples (Gather Data)\n",
141141
"\n",
142-
"It's very rare that a real-world project will start with all the data necessary to get\n",
143-
"to a satisfactory solution, much less to establish confidence.\n",
144-
"\n",
145-
"In our case, we're going to assume that we have a decent sample of system *inputs*, \n",
146-
"in the form of but receipt images, but start without any fully annotated data. We find \n",
147-
"this is a not-unusual situation when automating an existing process. Instead, \n",
148-
"we'll walk through the process of building that out as we go along by collaborating with\n",
149-
"domain experts, and make our evals progressively more comprehensive.\n",
150-
"In our case, we're going to assume that we have a decent sample of system *inputs*\n",
151-
"(here, photographs of receipts), but start without any fully annotated data. We'll walk\n",
152-
"through the process of incrementally expanding our test and training sets as we go along\n",
153-
"and make our evals progressively more comprehensive.\n",
142+
"It's very rare for a real-world project to begin with all the data necessary to achieve a satisfactory solution, let alone establish confidence.\n",
143+
"\n",
144+
"In our case, we'll assume we have a decent sample of system *inputs*, in the form of but receipt images, but start without any fully annotated data. We find this is a not-unusual situation when automating an existing process. We'll walk through the process of incrementally expanding our test and training sets in collaboration with domain experts as we go along and make our evals progressively more comprehensive.\n",
154145
"\n",
155146
"### 3. Build an End-to-End V0 System\n",
156147
"\n",
20 KB
Binary file not shown.

examples/partners/mcp_powered_voice_agents/mcp_powered_agents_cookbook.ipynb

Lines changed: 976 additions & 0 deletions
Large diffs are not rendered by default.
5.87 KB
Binary file not shown.
629 KB
Binary file not shown.
754 KB
Binary file not shown.
1.03 MB
Binary file not shown.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import os
2+
from mcp.server.fastmcp import FastMCP
3+
from openai import OpenAI
4+
from agents import set_tracing_export_api_key
5+
6+
# Create server
7+
mcp = FastMCP("Search Server")
8+
_vector_store_id = ""
9+
10+
def _run_rag(query: str) -> str:
11+
"""Do a search for answers within the knowledge base and internal documents of the user.
12+
Args:
13+
query: The user query
14+
"""
15+
results = client.vector_stores.search(
16+
vector_store_id=_vector_store_id,
17+
query=query,
18+
rewrite_query=True, # Query rewriting generally improves results
19+
)
20+
return results.data[0].content[0].text
21+
22+
23+
def _summarize_rag_response(rag_output: str) -> str:
24+
"""Summarize the RAG response using GPT-4
25+
Args:
26+
rag_output: The RAG response
27+
"""
28+
response = client.responses.create(
29+
model="gpt-4.1-mini",
30+
tools=[{"type": "web_search_preview"}],
31+
input="Summarize the following text concisely: \n\n" + rag_output,
32+
)
33+
return response.output_text
34+
35+
36+
@mcp.tool()
37+
def generate_rag_output(query: str) -> str:
38+
"""Generate a summarized RAG output for a given query.
39+
Args:
40+
query: The user query
41+
"""
42+
print("[debug-server] generate_rag_output: ", query)
43+
rag_output = _run_rag(query)
44+
return _summarize_rag_response(rag_output)
45+
46+
47+
@mcp.tool()
48+
def run_web_search(query: str) -> str:
49+
"""Run a web search for the given query.
50+
Args:
51+
query: The user query
52+
"""
53+
print("[debug-server] run_web_search:", query)
54+
response = client.responses.create(
55+
model="gpt-4.1-mini",
56+
tools=[{"type": "web_search_preview"}],
57+
input=query,
58+
)
59+
return response.output_text
60+
61+
62+
def index_documents(directory: str):
63+
"""Index the documents in the given directory to the vector store
64+
Args:
65+
directory: The directory to index the documents from
66+
"""
67+
# OpenAI supported file extensions for retrieval (see docs)
68+
SUPPORTED_EXTENSIONS = {'.pdf', '.txt', '.md', '.docx', '.pptx', '.csv', '.rtf', '.html', '.json', '.xml'}
69+
# Collect all files in the specified directory
70+
files = [os.path.join(directory, f) for f in os.listdir(directory)]
71+
# Filter files for supported extensions only
72+
supported_files = []
73+
for file_path in files:
74+
_, ext = os.path.splitext(file_path)
75+
if ext.lower() in SUPPORTED_EXTENSIONS:
76+
supported_files.append(file_path)
77+
else:
78+
print(f"[warning] Skipping unsupported file for retrieval: {file_path}")
79+
80+
vector_store = client.vector_stores.create( # Create vector store
81+
name="Support FAQ",
82+
)
83+
global _vector_store_id
84+
_vector_store_id = vector_store.id
85+
86+
for file_path in supported_files:
87+
# Upload each file to the vector store, ensuring the file handle is closed
88+
with open(file_path, "rb") as fp:
89+
client.vector_stores.files.upload_and_poll(
90+
vector_store_id=vector_store.id,
91+
file=fp
92+
)
93+
print(f"[debug-server] uploading file: {file_path}")
94+
95+
96+
if __name__ == "__main__":
97+
oai_api_key = os.environ.get("OPENAI_API_KEY")
98+
if not oai_api_key:
99+
raise ValueError("OPENAI_API_KEY environment variable is not set")
100+
set_tracing_export_api_key(oai_api_key)
101+
client = OpenAI(api_key=oai_api_key)
102+
103+
current_dir = os.path.dirname(os.path.abspath(__file__))
104+
samples_dir = os.path.join(current_dir, "sample_files")
105+
index_documents(samples_dir)
106+
107+
mcp.run(transport="sse")

images/System_flow_partner_mcp.png

164 KB
Loading

images/Traces-1_partner.png

613 KB
Loading

0 commit comments

Comments
 (0)