SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.4 KB · 23 lines python
Raw Blame History
1#!/usr/bin/env python32"""apply_patch: the model emits a structured create_file operation; we validate the path and report (dry run, nothing written).3STATUS: LIVE_VERIFIED 2026-09-18 (gpt-5.4-nano; apply_patch_call.operation = {type:create_file, path:'hello.txt', diff:'+OK\\n'}).4Run: .venv/bin/python examples/openai/tools/apply-patch/apply_patch.py5"""6import sys7from pathlib import Path8ROOT = Path(__file__).resolve().parents[4]; sys.path.insert(0, str(ROOT))9from scripts.live import load_env, log_request; load_env()10from openai import OpenAI11client = OpenAI(); MODEL = "gpt-5.4-nano"1213r = client.responses.create(model=MODEL, input="Create a new file hello.txt containing the single line OK using apply_patch.",14                            tools=[{"type": "apply_patch"}], tool_choice={"type": "apply_patch"}, max_output_tokens=128, reasoning={"effort": "low"})15log_request("openai", "POST", "/v1/responses", 200, 0.0002, "apply_patch.py create_file")16call = next(i for i in r.output if i.type == "apply_patch_call")17op = call.operation18print("apply_patch_call:", call.call_id, op.type, op.path, repr(getattr(op, "diff", None)))19ok = ".." not in op.path and not op.path.startswith("/")20output_item = {"type": "apply_patch_call_output", "call_id": call.call_id, "status": "completed" if ok else "failed",21               "output": "dry run: not applied" if ok else "path rejected"}22print("would send:", output_item)23