MCPcopy
hub / github.com/promptfoo/promptfoo / collectFileMetadata

Function collectFileMetadata

src/evaluatorHelpers.ts:121–152  ·  view source on GitHub ↗
(vars: Record<string, VarValue>)

Source from the content-addressed store, hash-verified

119 * @returns An object mapping variable names to their file metadata
120 */
121export function collectFileMetadata(vars: Record<string, VarValue>): FileMetadata {
122 const fileMetadata: FileMetadata = {};
123
124 for (const [varName, value] of Object.entries(vars)) {
125 if (typeof value === 'string' && value.startsWith('file://')) {
126 const filePath = path.resolve(cliState.basePath || '', value.slice('file://'.length));
127 const fileExtension = filePath.split('.').pop() || '';
128
129 if (isImageFile(filePath)) {
130 fileMetadata[varName] = {
131 path: value, // Keep the original file:// notation
132 type: 'image',
133 format: fileExtension,
134 };
135 } else if (isVideoFile(filePath)) {
136 fileMetadata[varName] = {
137 path: value,
138 type: 'video',
139 format: fileExtension,
140 };
141 } else if (isAudioFile(filePath)) {
142 fileMetadata[varName] = {
143 path: value,
144 type: 'audio',
145 format: fileExtension,
146 };
147 }
148 }
149 }
150
151 return fileMetadata;
152}
153
154/**
155 * Gets MIME type from file extension

Callers 2

createRunEvalStateFunction · 0.90

Calls 5

isImageFileFunction · 0.90
isVideoFileFunction · 0.90
isAudioFileFunction · 0.90
resolveMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…