Sanitize response history for follow-up turns
This commit is contained in:
@@ -49,15 +49,17 @@ export class OpenAIResponsesClient implements ModelClient {
|
|||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const outputText = response.output_text ?? "";
|
||||||
|
|
||||||
await this.events?.emit("model.response", {
|
await this.events?.emit("model.response", {
|
||||||
outputItems: response.output.length,
|
outputItems: response.output.length,
|
||||||
toolCalls: toolCalls.map((toolCall) => toolCall.name),
|
toolCalls: toolCalls.map((toolCall) => toolCall.name),
|
||||||
hasText: response.output_text.length > 0
|
hasText: outputText.length > 0
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
output: response.output,
|
output: sanitizeOutputItems(response.output),
|
||||||
outputText: response.output_text,
|
outputText,
|
||||||
toolCalls
|
toolCalls
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -105,16 +107,29 @@ export class OpenAIResponsesClient implements ModelClient {
|
|||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const outputText = response.output_text ?? "";
|
||||||
|
|
||||||
await this.events?.emit("model.response", {
|
await this.events?.emit("model.response", {
|
||||||
outputItems: response.output.length,
|
outputItems: response.output.length,
|
||||||
toolCalls: toolCalls.map((toolCall) => toolCall.name),
|
toolCalls: toolCalls.map((toolCall) => toolCall.name),
|
||||||
hasText: response.output_text.length > 0
|
hasText: outputText.length > 0
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
output: response.output,
|
output: sanitizeOutputItems(response.output),
|
||||||
outputText: response.output_text,
|
outputText,
|
||||||
toolCalls
|
toolCalls
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeOutputItems(items: unknown[]): unknown[] {
|
||||||
|
return JSON.parse(
|
||||||
|
JSON.stringify(items, (key, value) => {
|
||||||
|
if (key === "parsed_arguments") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
})
|
||||||
|
) as unknown[];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user