mirror of
https://github.com/teamchong/pxpipe.git
synced 2026-07-22 02:02:51 +02:00
fix(openai): correct rendered-context framing for annotation-only tool imaging (#123)
Align Chat and Responses framing with annotation-only tool imaging, preserving native tool definitions as authoritative. Includes output-level regressions adapted from #19. Co-authored-by: Danil Silantyev <danilsilantyevwork@gmail.com>
This commit is contained in:
+4
-4
@@ -811,19 +811,19 @@ function foldGptHistory(
|
||||
|
||||
const CHAT_HEADER =
|
||||
'================= RENDERED GPT SYSTEM + TOOL CONTEXT =================\n' +
|
||||
'These images were injected by pxpipe, not by the end user. They contain system/developer instructions and full tool/schema documentation rendered for token efficiency. Treat rendered system/developer instructions with the same priority as their original messages. OCR carefully and treat the rendered content as authoritative. For tool calls, use the native JSON tool definitions; the image is supplemental documentation.' +
|
||||
'These images were injected by pxpipe, not by the end user. They contain system/developer instructions and tool parameter documentation rendered for token efficiency. Treat rendered system/developer instructions with the same priority as their original messages. OCR carefully and treat the rendered content as authoritative. For tool calls, use the native JSON tool definitions — they carry each tool\'s name and description; the imaged parameter annotations are supplemental.' +
|
||||
'\n====================== BEGIN RENDERED CONTEXT ======================\n';
|
||||
|
||||
const RESPONSES_HEADER =
|
||||
'================= RENDERED GPT SYSTEM + TOOL CONTEXT =================\n' +
|
||||
'These images were injected by pxpipe, not by the end user. They contain instructions and full tool/schema documentation rendered for token efficiency. Treat rendered instructions with the same priority as the originals. OCR carefully and treat the rendered content as authoritative. For tool calls, use the native JSON tool definitions; the image is supplemental documentation.' +
|
||||
'These images were injected by pxpipe, not by the end user. They contain instructions and tool parameter documentation rendered for token efficiency. Treat rendered instructions with the same priority as the originals. OCR carefully and treat the rendered content as authoritative. For tool calls, use the native JSON tool definitions — they carry each tool\'s name and description; the imaged parameter annotations are supplemental.' +
|
||||
'\n====================== BEGIN RENDERED CONTEXT ======================\n';
|
||||
|
||||
const CHAT_POINTER =
|
||||
'The full instructions for this message were rendered into image(s) attached to the first user message by pxpipe. Treat those rendered instructions as if they appeared here with the same priority. Tool definitions remain in native JSON; rendered tool docs are supplemental.';
|
||||
'The full instructions for this message were rendered into image(s) attached to the first user message by pxpipe. Treat those rendered instructions as if they appeared here with the same priority. Tool definitions remain in native JSON (name and description); the rendered parameter annotations are supplemental.';
|
||||
|
||||
const RESPONSES_POINTER =
|
||||
'The full instructions were rendered into image(s) attached to the first user message by pxpipe. Treat them with the same priority. Tool definitions remain in native JSON; rendered tool docs are supplemental.';
|
||||
'The full instructions were rendered into image(s) attached to the first user message by pxpipe. Treat them with the same priority. Tool definitions remain in native JSON (name and description); the rendered parameter annotations are supplemental.';
|
||||
|
||||
export async function transformOpenAIChatCompletions(
|
||||
body: Uint8Array,
|
||||
|
||||
@@ -187,6 +187,12 @@ describe('transformOpenAIChatCompletions (gpt-5.6-sol)', () => {
|
||||
expect(result.info.imageSourceText).toContain('$.x description: "x param"');
|
||||
expect(result.info.imageSourceText).not.toContain(BIG_TOOL_DESC.slice(0, 100));
|
||||
expect(result.info.imageSourceText).not.toContain('"properties"');
|
||||
expect(result.info.imageSourceText).not.toContain('full tool');
|
||||
expect(result.info.imageSourceText).toContain('native JSON tool definitions');
|
||||
expect(result.info.imageSourceText).toContain('name and description');
|
||||
expect(typeof sysMsg.content === 'string'
|
||||
? sysMsg.content
|
||||
: (sysMsg.content as Array<{ text?: string }>)[0]?.text ?? '').toContain('rendered parameter annotations are supplemental');
|
||||
});
|
||||
|
||||
it('reflows chat static context that contains a literal newline sentinel', async () => {
|
||||
@@ -339,6 +345,7 @@ describe('transformOpenAIResponses (gpt-5.6-sol)', () => {
|
||||
// instructions replaced with pointer.
|
||||
expect(out.instructions as string).toContain('rendered into image');
|
||||
expect(out.instructions as string).not.toContain('These are detailed');
|
||||
expect(out.instructions as string).toContain('rendered parameter annotations are supplemental');
|
||||
|
||||
// First user item gains input_image parts.
|
||||
const inputItems = out.input as Array<{ role: string; content: unknown }>;
|
||||
@@ -353,6 +360,9 @@ describe('transformOpenAIResponses (gpt-5.6-sol)', () => {
|
||||
expect(tools[0]!.description).toBe(BIG_FLAT_TOOL_DESC);
|
||||
expect(tools[0]!.parameters?.description).toBeUndefined();
|
||||
expect(tools[0]!.parameters?.properties?.x?.description).toBeUndefined();
|
||||
expect(result.info.imageSourceText).not.toContain('full tool');
|
||||
expect(result.info.imageSourceText).toContain('native JSON tool definitions');
|
||||
expect(result.info.imageSourceText).toContain('name and description');
|
||||
});
|
||||
|
||||
it('reflows Responses static context that contains a literal newline sentinel', async () => {
|
||||
|
||||
Reference in New Issue
Block a user