evalstate's picture
download
raw
1.96 kB
import { logger } from './logger.js';
export function stripImageContentFromResult(callResult, { enabled, toolName, outwardFacingName }) {
if (!enabled) {
return callResult;
}
const content = callResult.content;
if (!Array.isArray(content) || content.length === 0) {
return callResult;
}
const filteredContent = content.filter((item) => {
if (!item || typeof item !== 'object') {
return true;
}
const candidate = item;
const typeValue = typeof candidate.type === 'string' ? candidate.type.toLowerCase() : undefined;
return typeValue !== 'image';
});
if (filteredContent.length === content.length) {
return callResult;
}
const removedCount = content.length - filteredContent.length;
logger.debug({ tool: toolName, outwardFacingName, removedCount }, 'Stripped image content from Gradio tool response');
if (filteredContent.length === 0) {
filteredContent.push({
type: 'text',
text: 'Image content omitted due to client configuration (no_image_content=true).',
});
}
return { ...callResult, content: filteredContent };
}
export function extractUrlFromContent(content) {
if (!Array.isArray(content) || content.length === 0) {
return undefined;
}
for (const item of content) {
if (!item || typeof item !== 'object') {
continue;
}
const candidate = item;
if (typeof candidate.url === 'string' && /^https?:\/\//i.test(candidate.url.trim())) {
return candidate.url.trim();
}
if (typeof candidate.text === 'string') {
let text = candidate.text.trim();
text = text.replace(/^image\s+url\s*:\s*/i, '');
if (/^https?:\/\//i.test(text)) {
return text;
}
}
}
return undefined;
}
//# sourceMappingURL=gradio-result-processor.js.map

Xet Storage Details

Size:
1.96 kB
·
Xet hash:
51729bea6a549e6ce964eee4314a8380f1dbd75165d7c6d22506823f87c35a57

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.