Skip to content

Commit bb991d4

Browse files
wip
1 parent 6a50759 commit bb991d4

File tree

1 file changed

+76
-78
lines changed

1 file changed

+76
-78
lines changed

examples/evaluation/use-cases/responses-evaluation.ipynb

Lines changed: 76 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
},
1717
{
1818
"cell_type": "code",
19-
"execution_count": 68,
19+
"execution_count": 30,
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
2323
"import openai\n",
2424
"import os\n",
2525
"\n",
26+
"\n",
2627
"client = openai.OpenAI()"
2728
]
2829
},
@@ -59,12 +60,12 @@
5960
"cell_type": "markdown",
6061
"metadata": {},
6162
"source": [
62-
"Now, lets generate some responses"
63+
"Now, lets generate some responses. "
6364
]
6465
},
6566
{
6667
"cell_type": "code",
67-
"execution_count": 66,
68+
"execution_count": null,
6869
"metadata": {},
6970
"outputs": [],
7071
"source": [
@@ -85,89 +86,96 @@
8586
" ],\n",
8687
" model=\"gpt-4o-mini\",\n",
8788
" )\n",
88-
" break\n",
89-
" print(response.id)"
89+
" print(response.output_text)"
90+
]
91+
},
92+
{
93+
"cell_type": "markdown",
94+
"metadata": {},
95+
"source": [
96+
"Note that in order for this to work, you'll have to be doing this on an org where data logging isn't disabled (through zdr, etc). If you aren't sure if this is the case for you, go to https://platform.openai.com/logs?api=responses and see if you can see the responses you just generated."
9097
]
9198
},
9299
{
93100
"cell_type": "code",
94-
"execution_count": 49,
101+
"execution_count": 31,
95102
"metadata": {},
96103
"outputs": [],
97104
"source": [
98105
"grader_system_prompt = \"\"\"\n",
99-
"We've created a consumer-facing Evals product to help AI integrators quickly and clearly understand their models' real-world performance. Your role is to serve as a Universal Evaluator, automatically grading responses to measure how well each model output addresses user needs and expectations.\n",
100-
"\n",
101-
"Given the conversation messages, assign a quality score in the `result` key of the response in the inclusive range between 1.0 (poor) and 7.0 (excellent). Customers will analyze your collective scores and reasoning to gain actionable insights into their models' performance.\n",
102-
"\n",
103-
"---\n",
104-
"\n",
105-
"## Things to Consider\n",
106-
"\n",
107-
"- Evaluate the overall value provided to the user\n",
108-
"- Verify all claims and do not take the AI's statements at face value! Errors might be very hard to find and well hidden.\n",
109-
"- Differentiate between minor errors (slight utility reduction) and major errors (significant trust or safety impact).\n",
110-
"- Reward answers that closely follow user instructions.\n",
111-
"- Reserve the highest and lowest reward scores for cases where you have complete certainty about correctness and utility.\n",
106+
"You are **Code-Explanation Grader**, an expert software engineer and technical writer. \n",
107+
"Your job is to score how well *Model A* explained the purpose and behaviour of a given source-code file.\n",
112108
"\n",
109+
"### What you receive\n",
110+
"1. **File contents** – the full text of the code file (or a representative excerpt). \n",
111+
"2. **Candidate explanation** – the answer produced by Model A that tries to describe what the file does.\n",
113112
"\n",
114-
"---\n",
113+
"### What to produce\n",
114+
"Return a single JSON object that can be parsed by `json.loads`, containing:\n",
115+
"```json\n",
116+
"{\n",
117+
" \"steps\": [\n",
118+
" { \"description\": \"...\", \"result\": \"float\" },\n",
119+
" { \"description\": \"...\", \"result\": \"float\" },\n",
120+
" { \"description\": \"...\", \"result\": \"float\" }\n",
121+
" ],\n",
122+
" \"result\": \"float\"\n",
123+
"}\n",
124+
"```\n",
125+
"• Each object in `steps` documents your reasoning for one category listed under “Scoring dimensions”. \n",
126+
"• Place your final 1 – 7 quality score (inclusive) in the top-level `result` key as a **string** (e.g. `\"5.5\"`).\n",
115127
"\n",
116-
"## Secondary Labels to Support Final Utility Score Prediction\n",
128+
"### Scoring dimensions (evaluate in this order)\n",
117129
"\n",
118-
"To help you assign an accurate final utility score, first analyze and predict several important aspects of the AI response. Crucially, these intermediate evaluations should precede your final utility score prediction.\n",
130+
"1. **Correctness & Accuracy ≈ 45 %** \n",
131+
" • Does the explanation match the actual code behaviour, interfaces, edge cases, and side effects? \n",
132+
" • Fact-check every technical claim; penalise hallucinations or missed key functionality.\n",
119133
"\n",
120-
"Your structured output must match the provided schema:\n",
134+
"2. **Completeness & Depth ≈ 25 %** \n",
135+
" • Are all major components, classes, functions, data flows, and external dependencies covered? \n",
136+
" • Depth should be appropriate to the file’s size/complexity; superficial glosses lose points.\n",
121137
"\n",
122-
"- `steps`: A JSON array of objects, each containing:\n",
123-
" - `description`: A detailed explanation of your reasoning for each step.\n",
124-
" - `result`: The float score reached based on the reasoning in this step.\n",
138+
"3. **Clarity & Organization ≈ 20 %** \n",
139+
" • Is the explanation well-structured, logically ordered, and easy for a competent developer to follow? \n",
140+
" • Good use of headings, bullet lists, and concise language is rewarded.\n",
125141
"\n",
126-
"### Steps to Predict (in order):\n",
142+
"4. **Insight & Usefulness ≈ 10 %** \n",
143+
" • Does the answer add valuable context (e.g., typical use cases, performance notes, risks) beyond line-by-line paraphrase? \n",
144+
" • Highlighting **why** design choices matter is a plus.\n",
127145
"\n",
128-
"1. **major_errors**\n",
129-
" - *description*: Identify and explain any significant errors.\n",
130-
" - *conclusion*: List major errors found, or indicate \"None\".\n",
146+
"### Error taxonomy\n",
147+
"• **Major error** – Any statement that materially misrepresents the file (e.g., wrong API purpose, inventing non-existent behaviour). \n",
148+
"• **Minor error** – Small omission or wording that slightly reduces clarity but doesn’t mislead. \n",
149+
"List all found errors in your `steps` reasoning.\n",
131150
"\n",
132-
"2. **minor_errors**\n",
133-
" - *description*: Identify and explain any minor inaccuracies.\n",
134-
" - *conclusion*: List minor errors found, or indicate \"None\".\n",
151+
"### Numeric rubric\n",
152+
"1 Catastrophically wrong; mostly hallucination or irrelevant. \n",
153+
"2 Many major errors, few correct points. \n",
154+
"3 Several major errors OR pervasive minor mistakes; unreliable. \n",
155+
"4 Mostly correct but with at least one major gap or multiple minors; usable only with caution. \n",
156+
"5 Solid, generally correct; minor issues possible but no major flaws. \n",
157+
"6 Comprehensive, accurate, and clear; only very small nit-picks. \n",
158+
"7 Exceptional: precise, thorough, insightful, and elegantly presented; hard to improve.\n",
135159
"\n",
136-
"3. **potential_improvements**\n",
137-
" - *description*: Suggest enhancements that would improve the response.\n",
138-
" - *conclusion*: List suggested improvements, or indicate \"None\".\n",
160+
"Use the full scale. Reserve 6.5 – 7 only when you are almost certain the explanation is outstanding.\n",
139161
"\n",
140-
"---\n",
162+
"Then set `\"result\": \"4.0\"` (example).\n",
141163
"\n",
142-
"## JSON Response Structure\n",
143-
"\n",
144-
"Once you predicted all the above fields you need to assign a float between 1 and 7 to indicate the response's utility compared to the alternative responses. Use your best judgment for the meaning of `final_score`. Your response should be a JSON that can be loaded with json.loads in Python and contains:\n",
145-
"- steps: An array of objects representing your reasoning steps. Each step includes:\n",
146-
" - description (string): Detailed reasoning for this step.\n",
147-
" - result (string): The float score derived from this reasoning.\n",
148-
"- result (float): A numeric quality score as a string, in the inclusive range [1,7].\n",
149-
"\n",
150-
"---\n",
151-
"\n",
152-
"## Notes\n",
153-
"\n",
154-
"- Be meticulous in identifying errors, especially subtle or high-impact ones.\n",
155-
"- Avoid being too kind by giving overly high scores easily, it's important to often keep a gap at the top to continue having signal for improvement. Only use [6.5, 7) if the answer is truly mind blowing and you don't see how it could have been improved.\n",
156-
"- Never take the AI's responses at face value—verify everything thoroughly.\n",
164+
"Be rigorous and unbiased.\n",
157165
"\"\"\"\n",
158166
"user_input_message = \"\"\"**User input**\n",
159167
"\n",
160168
"{{item.input}}\n",
161169
"\n",
162170
"**Response to evaluate**\n",
163171
"\n",
164-
"{{sample.output_text}\n",
172+
"{{sample.output_text}}\n",
165173
"\"\"\""
166174
]
167175
},
168176
{
169177
"cell_type": "code",
170-
"execution_count": 71,
178+
"execution_count": 25,
171179
"metadata": {},
172180
"outputs": [],
173181
"source": [
@@ -189,7 +197,8 @@
189197
" \"content\": user_input_message,\n",
190198
" },\n",
191199
" ],\n",
192-
" \"pass_threshold\": 0.5\n",
200+
" \"range\": [1, 7],\n",
201+
" \"pass_threshold\": 5.5,\n",
193202
" }\n",
194203
" ]\n",
195204
")"
@@ -204,15 +213,16 @@
204213
},
205214
{
206215
"cell_type": "code",
207-
"execution_count": 72,
216+
"execution_count": 26,
208217
"metadata": {},
209218
"outputs": [],
210219
"source": [
211-
"gpt_4o_run = client.evals.runs.create(\n",
220+
"gpt_4o_mini_run = client.evals.runs.create(\n",
221+
" name=\"gpt-4o-mini\",\n",
212222
" eval_id=logs_eval.id,\n",
213223
" data_source={\n",
214224
" \"type\": \"responses\",\n",
215-
" \"source\": {\"type\": \"responses\", \"limit\": len(file_paths)},\n",
225+
" \"source\": {\"type\": \"responses\", \"limit\": len(file_paths)}, # just grab the most recent responses\n",
216226
" },\n",
217227
")"
218228
]
@@ -226,11 +236,12 @@
226236
},
227237
{
228238
"cell_type": "code",
229-
"execution_count": 73,
239+
"execution_count": 27,
230240
"metadata": {},
231241
"outputs": [],
232242
"source": [
233-
"gpt_41_run = client.evals.runs.create(\n",
243+
"gpt_41_mini_run = client.evals.runs.create(\n",
244+
" name=\"gpt-4.1-mini\",\n",
234245
" eval_id=logs_eval.id,\n",
235246
" data_source={\n",
236247
" \"type\": \"responses\",\n",
@@ -253,35 +264,22 @@
253264
},
254265
{
255266
"cell_type": "code",
256-
"execution_count": 74,
267+
"execution_count": null,
257268
"metadata": {},
258-
"outputs": [
259-
{
260-
"data": {
261-
"text/plain": [
262-
"'https://platform.openai.com/evaluations/eval_6822dd1c4d308190855601dc7fe982bd?project_id=proj_YFvXZA3VxHbZx5aSJv6SAM5B&run_id=evalrun_6822dd1f89b88190a3287c706fd599f4'"
263-
]
264-
},
265-
"execution_count": 74,
266-
"metadata": {},
267-
"output_type": "execute_result"
268-
}
269-
],
269+
"outputs": [],
270270
"source": [
271-
"gpt_41_run.report_url"
271+
"gpt_4o_mini_run.report_url"
272272
]
273273
},
274274
{
275-
"cell_type": "code",
276-
"execution_count": null,
275+
"cell_type": "markdown",
277276
"metadata": {},
278-
"outputs": [],
279277
"source": []
280278
}
281279
],
282280
"metadata": {
283281
"kernelspec": {
284-
"display_name": "openai",
282+
"display_name": "Python 3",
285283
"language": "python",
286284
"name": "python3"
287285
},

0 commit comments

Comments
 (0)