117 lines
3.7 KiB
Plaintext
117 lines
3.7 KiB
Plaintext
{
|
|
"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
|
|
}
|