-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Add coding agent with GPT-5.1 cookbook guide #2238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "def apply_unified_diff(original: str, diff: str, create: bool = False) -> str:\n", | ||
| " \"\"\"\n", | ||
| " Simple \"diff\" applier (adapt this based on your environment)\n", | ||
| "\n", | ||
| " - For create_file, the diff can be the full desired file contents,\n", | ||
| " optionally with leading '+' on each line.\n", | ||
| " - For update_file, we treat the diff as the new file contents:\n", | ||
| " keep lines starting with ' ' or '+', drop '-' lines and diff headers.\n", | ||
| "\n", | ||
| " This avoids context/delete mismatch errors while still letting the model\n", | ||
| " send familiar diff-like patches.\n", | ||
| " \"\"\"\n", | ||
| " if not diff:\n", | ||
| " return original\n", | ||
| "\n", | ||
| " lines = diff.splitlines()\n", | ||
| " body: list[str] = []\n", | ||
| "\n", | ||
| " for line in lines:\n", | ||
| " if not line:\n", | ||
| " body.append(\"\")\n", | ||
| " continue\n", | ||
| "\n", | ||
| " # Skip typical unified diff headers / metadata\n", | ||
| " if line.startswith(\"@@\") or line.startswith(\"---\") or line.startswith(\"+++\"):\n", | ||
| " continue\n", | ||
| "\n", | ||
| " prefix = line[0]\n", | ||
| " content = line[1:]\n", | ||
| "\n", | ||
| " if prefix in (\"+\", \" \"):\n", | ||
| " body.append(content)\n", | ||
| " elif prefix in (\"-\", \"\\\\\"):\n", | ||
| " # skip deletions and \"\\ No newline at end of file\"\n", | ||
| " continue\n", | ||
| " else:\n", | ||
| " # If it doesn't look like diff syntax, keep the full line\n", | ||
| " body.append(line)\n", | ||
| "\n", | ||
| " text = \"\\n\".join(body)\n", | ||
| " if diff.endswith(\"\\n\"):\n", | ||
| " text += \"\\n\"\n", | ||
| " return text\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix apply_patch diff application
The apply_unified_diff helper (lines 878‑920 of examples/Build_a_coding_agent_with_GPT-5.1.ipynb) ignores the existing file contents and simply concatenates the lines that appear in the diff hunk. Standard unified diffs only include the modified region plus a little context, so when the agent issues an update_file operation, the resulting file is replaced with just that tiny hunk and every other line disappears. Running the second half of the tutorial will therefore corrupt any non‑trivial file as soon as apply_patch is used. The patch function needs to actually apply the diff against original (or require the model to send the full file contents) instead of discarding all untouched lines.
Useful? React with 👍 / 👎.
No description provided.