Skip to content

Commit ce552e2

Browse files
wip
1 parent 4596343 commit ce552e2

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

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

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616
},
1717
{
1818
"cell_type": "code",
19+
<<<<<<< HEAD
1920
"execution_count": 30,
21+
=======
22+
"execution_count": 68,
23+
>>>>>>> 562e852 (wip)
2024
"metadata": {},
2125
"outputs": [],
2226
"source": [
2327
"import openai\n",
2428
"import os\n",
2529
"\n",
30+
<<<<<<< HEAD
2631
"\n",
32+
=======
33+
>>>>>>> 562e852 (wip)
2734
"client = openai.OpenAI()"
2835
]
2936
},
@@ -44,7 +51,11 @@
4451
"source": [
4552
"openai_sdk_file_path = os.path.dirname(openai.__file__)\n",
4653
"\n",
54+
<<<<<<< HEAD
4755
"# Get some example code files from the OpenAI SDK \n",
56+
=======
57+
"# Get some example code files from the OpenAI SDK\n",
58+
>>>>>>> 562e852 (wip)
4859
"file_paths = [\n",
4960
" os.path.join(openai_sdk_file_path, \"resources\", \"evals\", \"evals.py\"),\n",
5061
" os.path.join(openai_sdk_file_path, \"resources\", \"responses\", \"responses.py\"),\n",
@@ -60,12 +71,20 @@
6071
"cell_type": "markdown",
6172
"metadata": {},
6273
"source": [
74+
<<<<<<< HEAD
6375
"Now, lets generate some responses. "
76+
=======
77+
"Now, lets generate some responses"
78+
>>>>>>> 562e852 (wip)
6479
]
6580
},
6681
{
6782
"cell_type": "code",
83+
<<<<<<< HEAD
6884
"execution_count": null,
85+
=======
86+
"execution_count": 66,
87+
>>>>>>> 562e852 (wip)
6988
"metadata": {},
7089
"outputs": [],
7190
"source": [
@@ -86,6 +105,7 @@
86105
" ],\n",
87106
" model=\"gpt-4o-mini\",\n",
88107
" )\n",
108+
<<<<<<< HEAD
89109
" print(response.output_text)"
90110
]
91111
},
@@ -94,15 +114,24 @@
94114
"metadata": {},
95115
"source": [
96116
"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."
117+
=======
118+
" break\n",
119+
" print(response.id)"
120+
>>>>>>> 562e852 (wip)
97121
]
98122
},
99123
{
100124
"cell_type": "code",
125+
<<<<<<< HEAD
101126
"execution_count": 31,
127+
=======
128+
"execution_count": 49,
129+
>>>>>>> 562e852 (wip)
102130
"metadata": {},
103131
"outputs": [],
104132
"source": [
105133
"grader_system_prompt = \"\"\"\n",
134+
<<<<<<< HEAD
106135
"You are **Code-Explanation Grader**, an expert software engineer and technical writer. \n",
107136
"Your job is to score how well *Model A* explained the purpose and behaviour of a given source-code file.\n",
108137
"\n",
@@ -162,20 +191,88 @@
162191
"Then set `\"result\": \"4.0\"` (example).\n",
163192
"\n",
164193
"Be rigorous and unbiased.\n",
194+
=======
195+
"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",
196+
"\n",
197+
"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",
198+
"\n",
199+
"---\n",
200+
"\n",
201+
"## Things to Consider\n",
202+
"\n",
203+
"- Evaluate the overall value provided to the user\n",
204+
"- 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",
205+
"- Differentiate between minor errors (slight utility reduction) and major errors (significant trust or safety impact).\n",
206+
"- Reward answers that closely follow user instructions.\n",
207+
"- Reserve the highest and lowest reward scores for cases where you have complete certainty about correctness and utility.\n",
208+
"\n",
209+
"\n",
210+
"---\n",
211+
"\n",
212+
"## Secondary Labels to Support Final Utility Score Prediction\n",
213+
"\n",
214+
"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",
215+
"\n",
216+
"Your structured output must match the provided schema:\n",
217+
"\n",
218+
"- `steps`: A JSON array of objects, each containing:\n",
219+
" - `description`: A detailed explanation of your reasoning for each step.\n",
220+
" - `result`: The float score reached based on the reasoning in this step.\n",
221+
"\n",
222+
"### Steps to Predict (in order):\n",
223+
"\n",
224+
"1. **major_errors**\n",
225+
" - *description*: Identify and explain any significant errors.\n",
226+
" - *conclusion*: List major errors found, or indicate \"None\".\n",
227+
"\n",
228+
"2. **minor_errors**\n",
229+
" - *description*: Identify and explain any minor inaccuracies.\n",
230+
" - *conclusion*: List minor errors found, or indicate \"None\".\n",
231+
"\n",
232+
"3. **potential_improvements**\n",
233+
" - *description*: Suggest enhancements that would improve the response.\n",
234+
" - *conclusion*: List suggested improvements, or indicate \"None\".\n",
235+
"\n",
236+
"---\n",
237+
"\n",
238+
"## JSON Response Structure\n",
239+
"\n",
240+
"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",
241+
"- steps: An array of objects representing your reasoning steps. Each step includes:\n",
242+
" - description (string): Detailed reasoning for this step.\n",
243+
" - result (string): The float score derived from this reasoning.\n",
244+
"- result (float): A numeric quality score as a string, in the inclusive range [1,7].\n",
245+
"\n",
246+
"---\n",
247+
"\n",
248+
"## Notes\n",
249+
"\n",
250+
"- Be meticulous in identifying errors, especially subtle or high-impact ones.\n",
251+
"- 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",
252+
"- Never take the AI's responses at face value—verify everything thoroughly.\n",
253+
>>>>>>> 562e852 (wip)
165254
"\"\"\"\n",
166255
"user_input_message = \"\"\"**User input**\n",
167256
"\n",
168257
"{{item.input}}\n",
169258
"\n",
170259
"**Response to evaluate**\n",
171260
"\n",
261+
<<<<<<< HEAD
172262
"{{sample.output_text}}\n",
263+
=======
264+
"{{sample.output_text}\n",
265+
>>>>>>> 562e852 (wip)
173266
"\"\"\""
174267
]
175268
},
176269
{
177270
"cell_type": "code",
271+
<<<<<<< HEAD
178272
"execution_count": 25,
273+
=======
274+
"execution_count": 71,
275+
>>>>>>> 562e852 (wip)
179276
"metadata": {},
180277
"outputs": [],
181278
"source": [
@@ -197,8 +294,12 @@
197294
" \"content\": user_input_message,\n",
198295
" },\n",
199296
" ],\n",
297+
<<<<<<< HEAD
200298
" \"range\": [1, 7],\n",
201299
" \"pass_threshold\": 5.5,\n",
300+
=======
301+
" \"pass_threshold\": 0.5\n",
302+
>>>>>>> 562e852 (wip)
202303
" }\n",
203304
" ]\n",
204305
")"
@@ -213,6 +314,7 @@
213314
},
214315
{
215316
"cell_type": "code",
317+
<<<<<<< HEAD
216318
"execution_count": 26,
217319
"metadata": {},
218320
"outputs": [],
@@ -223,6 +325,17 @@
223325
" data_source={\n",
224326
" \"type\": \"responses\",\n",
225327
" \"source\": {\"type\": \"responses\", \"limit\": len(file_paths)}, # just grab the most recent responses\n",
328+
=======
329+
"execution_count": 72,
330+
"metadata": {},
331+
"outputs": [],
332+
"source": [
333+
"gpt_4o_run = client.evals.runs.create(\n",
334+
" eval_id=logs_eval.id,\n",
335+
" data_source={\n",
336+
" \"type\": \"responses\",\n",
337+
" \"source\": {\"type\": \"responses\", \"limit\": len(file_paths)},\n",
338+
>>>>>>> 562e852 (wip)
226339
" },\n",
227340
")"
228341
]
@@ -236,12 +349,20 @@
236349
},
237350
{
238351
"cell_type": "code",
352+
<<<<<<< HEAD
239353
"execution_count": 27,
240354
"metadata": {},
241355
"outputs": [],
242356
"source": [
243357
"gpt_41_mini_run = client.evals.runs.create(\n",
244358
" name=\"gpt-4.1-mini\",\n",
359+
=======
360+
"execution_count": 73,
361+
"metadata": {},
362+
"outputs": [],
363+
"source": [
364+
"gpt_41_run = client.evals.runs.create(\n",
365+
>>>>>>> 562e852 (wip)
245366
" eval_id=logs_eval.id,\n",
246367
" data_source={\n",
247368
" \"type\": \"responses\",\n",
@@ -264,6 +385,7 @@
264385
},
265386
{
266387
"cell_type": "code",
388+
<<<<<<< HEAD
267389
"execution_count": null,
268390
"metadata": {},
269391
"outputs": [],
@@ -274,12 +396,41 @@
274396
{
275397
"cell_type": "markdown",
276398
"metadata": {},
399+
=======
400+
"execution_count": 74,
401+
"metadata": {},
402+
"outputs": [
403+
{
404+
"data": {
405+
"text/plain": [
406+
"'https://platform.openai.com/evaluations/eval_6822dd1c4d308190855601dc7fe982bd?project_id=proj_YFvXZA3VxHbZx5aSJv6SAM5B&run_id=evalrun_6822dd1f89b88190a3287c706fd599f4'"
407+
]
408+
},
409+
"execution_count": 74,
410+
"metadata": {},
411+
"output_type": "execute_result"
412+
}
413+
],
414+
"source": [
415+
"gpt_41_run.report_url"
416+
]
417+
},
418+
{
419+
"cell_type": "code",
420+
"execution_count": null,
421+
"metadata": {},
422+
"outputs": [],
423+
>>>>>>> 562e852 (wip)
277424
"source": []
278425
}
279426
],
280427
"metadata": {
281428
"kernelspec": {
429+
<<<<<<< HEAD
282430
"display_name": "Python 3",
431+
=======
432+
"display_name": "openai",
433+
>>>>>>> 562e852 (wip)
283434
"language": "python",
284435
"name": "python3"
285436
},

0 commit comments

Comments
 (0)