chore: import upstream snapshot with attribution
Rebuild Cookbook Website / deploy (push) Has been cancelled
Rebuild Cookbook Website / deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Getting started with Evals, sampled fixture\n",
|
||||
"\n",
|
||||
"This fixture mirrors the Cookbook Evals walkthrough but uses tiny local records instead of running a long benchmark.\n"
|
||||
],
|
||||
"id": "cell-000"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"MODEL = \"gpt-3.5-turbo\" # stale model kept intentionally for review\n",
|
||||
"\n",
|
||||
"schema = \"Table cars_data, columns = [Id, MPG, Cylinders, Horsepower, Year]\"\n",
|
||||
"examples = [\n",
|
||||
" {\"question\": \"Which cars have more than 100 horsepower?\", \"ideal\": \"SELECT Id FROM cars_data WHERE Horsepower > 100\"},\n",
|
||||
" {\"question\": \"How many cars are from 1970?\", \"ideal\": \"SELECT count(*) FROM cars_data WHERE Year = 1970\"},\n",
|
||||
"]\n"
|
||||
],
|
||||
"id": "cell-001"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def make_eval_rows(records):\n",
|
||||
" return [\n",
|
||||
" {\n",
|
||||
" \"input\": [\n",
|
||||
" {\"role\": \"system\", \"content\": f\"Answer with SQLite SQL. {schema}\"},\n",
|
||||
" {\"role\": \"user\", \"content\": record[\"question\"]},\n",
|
||||
" ],\n",
|
||||
" \"ideal\": record[\"ideal\"],\n",
|
||||
" }\n",
|
||||
" for record in records\n",
|
||||
" ]\n",
|
||||
"\n",
|
||||
"eval_rows = make_eval_rows(examples)\n",
|
||||
"eval_rows[0]\n"
|
||||
],
|
||||
"id": "cell-002"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Legacy CLI command kept as a repair target; this cell only records it.\n",
|
||||
"EVAL_COMMAND = \"oaieval gpt-3.5-turbo spider-sql --max_samples 25\"\n",
|
||||
"print(EVAL_COMMAND)\n"
|
||||
],
|
||||
"id": "cell-003"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Manual log-name placeholder kept as a repair target.\n",
|
||||
"log_name = \"240327024443FACXGMKA_gpt-3.5-turbo_spider-sql.jsonl\" # EDIT THIS\n",
|
||||
"local_events = [\n",
|
||||
" {\"type\": \"final_report\", \"data\": {\"accuracy\": 0.5}},\n",
|
||||
" {\"type\": \"sampling\", \"data\": {\"prompt\": eval_rows[0][\"input\"], \"sampled\": \"SELECT Id FROM cars_data WHERE Horsepower > 100\"}},\n",
|
||||
"]\n",
|
||||
"final_report = next(event[\"data\"] for event in local_events if event[\"type\"] == \"final_report\")\n",
|
||||
"final_report\n"
|
||||
],
|
||||
"id": "cell-004"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"pygments_lexer": "ipython3"
|
||||
},
|
||||
"codex_case_study": {
|
||||
"source_repo": "https://github.com/openai/openai-cookbook",
|
||||
"source_path": "examples/evaluation/Getting_Started_with_OpenAI_Evals.ipynb",
|
||||
"source_commit": "96b1d67^",
|
||||
"purpose": "Runtime-sampled pre-repair fixture derived from a Cookbook documentation reliability run.",
|
||||
"sampling_note": "Compact Evals-style maintenance sample with stale model, deprecated CLI, and result-log issues.",
|
||||
"repair_story": {
|
||||
"target_iteration": 2,
|
||||
"repair_depth": "Two-pass cleanup: first modernize the obvious stale Evals flow, then use validation feedback to remove result-log brittleness.",
|
||||
"issue_layers": [
|
||||
"stale model",
|
||||
"deprecated oaieval command",
|
||||
"manual log-name/runtime result dependency"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Function calling for knowledge retrieval, sampled fixture\n",
|
||||
"\n",
|
||||
"This fixture is derived from the Cookbook arXiv retrieval example. It uses two local paper records so execution stays fast while the repair loop still sees legacy tool-calling patterns.\n"
|
||||
],
|
||||
"id": "cell-000"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"GPT_MODEL = \"gpt-4-turbo-preview\" # stale model kept intentionally for the repair loop\n",
|
||||
"\n",
|
||||
"papers = [\n",
|
||||
" {\"title\": \"PPO for sequence generation\", \"article_url\": \"https://example.com/ppo\", \"summary\": \"PPO stabilizes policy updates with clipped objectives.\"},\n",
|
||||
" {\"title\": \"Retrieval augmented generation\", \"article_url\": \"https://example.com/rag\", \"summary\": \"RAG combines retrieval with generation to ground answers.\"},\n",
|
||||
"]\n"
|
||||
],
|
||||
"id": "cell-001"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def get_articles(query, top_k=2):\n",
|
||||
" query_terms = set(query.lower().split())\n",
|
||||
" ranked = sorted(\n",
|
||||
" papers,\n",
|
||||
" key=lambda paper: len(query_terms & set((paper[\"title\"] + \" \" + paper[\"summary\"]).lower().split())),\n",
|
||||
" reverse=True,\n",
|
||||
" )\n",
|
||||
" return ranked[:top_k]\n",
|
||||
"\n",
|
||||
"get_articles(\"ppo reinforcement learning\")\n"
|
||||
],
|
||||
"id": "cell-002"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def read_article_and_summarize(query):\n",
|
||||
" article = get_articles(query, top_k=1)[0]\n",
|
||||
" return f'{article[\"title\"]}: {article[\"summary\"]}'\n",
|
||||
"\n",
|
||||
"read_article_and_summarize(\"ppo sequence generation\")\n"
|
||||
],
|
||||
"id": "cell-003"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Legacy function-calling schema kept as a repair target.\n",
|
||||
"arxiv_functions = [\n",
|
||||
" {\n",
|
||||
" \"name\": \"get_articles\",\n",
|
||||
" \"description\": \"Use this function to get academic papers from a local article index.\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"object\",\n",
|
||||
" \"properties\": {\"query\": {\"type\": \"string\"}},\n",
|
||||
" \"required\": [\"query\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"messages = [{\"role\": \"user\", \"content\": \"How does PPO work?\"}]\n",
|
||||
"print(arxiv_functions[0][\"name\"], messages[0][\"content\"])\n"
|
||||
],
|
||||
"id": "cell-004"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"pygments_lexer": "ipython3"
|
||||
},
|
||||
"codex_case_study": {
|
||||
"source_repo": "https://github.com/openai/openai-cookbook",
|
||||
"source_path": "examples/How_to_call_functions_for_knowledge_retrieval.ipynb",
|
||||
"source_commit": "96b1d67^",
|
||||
"purpose": "Runtime-sampled pre-repair fixture derived from a Cookbook documentation reliability run.",
|
||||
"sampling_note": "Compact knowledge-retrieval maintenance sample with stale model and legacy tool-calling issues.",
|
||||
"repair_story": {
|
||||
"target_iteration": 3,
|
||||
"repair_depth": "Three-pass cleanup: modernize model/API shape, then tighten runnable local setup, then restore the full retrieval teaching flow.",
|
||||
"issue_layers": [
|
||||
"stale chat model",
|
||||
"legacy function-calling schema",
|
||||
"setup/runnability gap",
|
||||
"end-to-end retrieval flow integrity"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Qdrant embedding search, sampled fixture\n",
|
||||
"\n",
|
||||
"This fixture is derived from the Cookbook Qdrant search example. It keeps the same teaching arc with a tiny local article set so validation can execute quickly.\n"
|
||||
],
|
||||
"id": "cell-000"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from math import sqrt\n",
|
||||
"\n",
|
||||
"EMBEDDING_MODEL = \"text-embedding-ada-002\" # legacy model kept intentionally for the repair loop\n",
|
||||
"\n",
|
||||
"articles = [\n",
|
||||
" {\"id\": 1, \"title\": \"Modern art in Europe\", \"url\": \"https://example.com/art\", \"content\": \"Cubism and surrealism reshaped European museums.\"},\n",
|
||||
" {\"id\": 2, \"title\": \"Scottish battle history\", \"url\": \"https://example.com/scotland\", \"content\": \"Bannockburn and Stirling Bridge shaped Scottish history.\"},\n",
|
||||
" {\"id\": 3, \"title\": \"Space telescope discoveries\", \"url\": \"https://example.com/space\", \"content\": \"Modern telescopes reveal planets, galaxies, and stars.\"},\n",
|
||||
"]\n"
|
||||
],
|
||||
"id": "cell-001"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def embed(text: str) -> list[float]:\n",
|
||||
" buckets = [0.0, 0.0, 0.0, 0.0]\n",
|
||||
" for index, char in enumerate(text.lower()):\n",
|
||||
" buckets[index % len(buckets)] += ord(char) / 1000\n",
|
||||
" length = sqrt(sum(value * value for value in buckets)) or 1\n",
|
||||
" return [round(value / length, 4) for value in buckets]\n",
|
||||
"\n",
|
||||
"for article in articles:\n",
|
||||
" article[\"title_vector\"] = embed(article[\"title\"])\n",
|
||||
" article[\"content_vector\"] = embed(article[\"content\"])\n"
|
||||
],
|
||||
"id": "cell-002"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class LocalQdrant:\n",
|
||||
" def __init__(self, rows):\n",
|
||||
" self.rows = rows\n",
|
||||
"\n",
|
||||
" def search(self, collection_name, query_vector, limit=3, query_filter=None):\n",
|
||||
" vector_name, query = query_vector\n",
|
||||
" scored = []\n",
|
||||
" for row in self.rows:\n",
|
||||
" vector = row[f\"{vector_name}_vector\"]\n",
|
||||
" score = sum(a * b for a, b in zip(query, vector))\n",
|
||||
" scored.append((score, row))\n",
|
||||
" return sorted(scored, reverse=True)[:limit]\n",
|
||||
"\n",
|
||||
" def query_points(self, collection_name, query, using=\"title\", limit=3):\n",
|
||||
" return self.search(collection_name, (using, query), limit=limit)\n",
|
||||
"\n",
|
||||
"qdrant = LocalQdrant(articles)\n"
|
||||
],
|
||||
"id": "cell-003"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def query_qdrant(query, collection_name, vector_name=\"title\", top_k=3):\n",
|
||||
" embedded_query = embed(query)\n",
|
||||
" return qdrant.search(\n",
|
||||
" collection_name=collection_name,\n",
|
||||
" query_vector=(vector_name, embedded_query),\n",
|
||||
" limit=top_k,\n",
|
||||
" query_filter=None,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"for score, article in query_qdrant(\"modern art in Europe\", \"Articles\", \"title\"):\n",
|
||||
" print(f'{article[\"title\"]}: {score:.3f}')\n"
|
||||
],
|
||||
"id": "cell-004"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"pygments_lexer": "ipython3"
|
||||
},
|
||||
"codex_case_study": {
|
||||
"source_repo": "https://github.com/openai/openai-cookbook",
|
||||
"source_path": "examples/vector_databases/qdrant/Using_Qdrant_for_embeddings_search.ipynb",
|
||||
"source_commit": "96b1d67^",
|
||||
"purpose": "Runtime-sampled pre-repair fixture derived from a Cookbook documentation reliability run.",
|
||||
"sampling_note": "Compact Qdrant-style maintenance sample with stale embedding-model and query API issues.",
|
||||
"repair_story": {
|
||||
"target_iteration": 1,
|
||||
"repair_depth": "One-pass cleanup: modernize the local Qdrant query path and clarify the sampled fixture framing.",
|
||||
"issue_layers": [
|
||||
"stale embedding model",
|
||||
"deprecated qdrant.search call",
|
||||
"fixture framing/setup clarity"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user