enh: image tool response

This commit is contained in:
Timothy Jaeryang Baek
2025-04-02 23:46:39 -07:00
parent 561b2c0b1a
commit faa68fcdaa
4 changed files with 67 additions and 9 deletions

View File

@@ -683,6 +683,31 @@ export const removeDetails = (content, types) => {
return content;
};
export const processDetails = (content) => {
content = removeDetails(content, ['reasoning', 'code_interpreter']);
// This regex matches <details> tags with type="tool_calls" and captures their attributes to convert them to <tool_calls> tags
const detailsRegex = /<details\s+type="tool_calls"([^>]*)>([\s\S]*?)<\/details>/gis;
const matches = content.match(detailsRegex);
if (matches) {
for (const match of matches) {
const attributesRegex = /(\w+)="([^"]*)"/g;
const attributes = {};
let attributeMatch;
while ((attributeMatch = attributesRegex.exec(match)) !== null) {
attributes[attributeMatch[1]] = attributeMatch[2];
}
content = content.replace(
match,
`<tool_calls name="${attributes.name}" result="${attributes.result}"/>`
);
}
}
return content;
};
// This regular expression matches code blocks marked by triple backticks
const codeBlockRegex = /```[\s\S]*?```/g;