Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,10 @@ export function createApplyPatchTool(): ApplyPatchToolDefinition {
label: "ApplyPatch",
description: APPLY_PATCH_FREEFORM_DESCRIPTION,
parameters: APPLY_PATCH_PARAMS,
// Pi's public grammar hook: models whose provider sets `compat.supportsOpenAIGrammarTools`
// receive apply_patch as a native OpenAI custom tool constrained by the Codex Lark grammar.
// Other providers fall back to the plain function tool.
constrainedSampling: { type: "grammar", variants: { openai_lark: APPLY_PATCH_LARK_GRAMMAR } },
prepareArguments: normalizeApplyPatchArguments,
promptSnippet: "Apply Codex-format file patches with apply_patch",
promptGuidelines: [
Expand Down
6 changes: 6 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ describe("pi-apply-patch", () => {
let capturedToolName: string | undefined;
let capturedDescription: string | undefined;
let capturedFreeform: FreeformToolFormat | undefined;
let capturedConstrainedSampling: ReturnType<typeof createApplyPatchTool>["constrainedSampling"];
const extensionApi = {
registerTool(tool: ReturnType<typeof createApplyPatchTool>) {
capturedToolName = tool.name;
capturedDescription = tool.description;
capturedFreeform = tool.freeform;
capturedConstrainedSampling = tool.constrainedSampling;
},
on() {
return () => {};
Expand All @@ -138,6 +140,10 @@ describe("pi-apply-patch", () => {
syntax: "lark",
definition: APPLY_PATCH_LARK_GRAMMAR,
});
expect(capturedConstrainedSampling).toEqual({
type: "grammar",
variants: { openai_lark: APPLY_PATCH_LARK_GRAMMAR },
});
});

it("#given GPT model after reload with apply_patch already active #when session starts #then keeps apply_patch active", async () => {
Expand Down
Loading