pgduc1511
03/30/2025, 2:09 PM[
{
“description”:“Query downloaded files on specific day?“,
“vars”:{
“prompt”:[
“How many files were downloaded on {{weekdays}}?“,
“Show me the file types downloaded every {{weekdays}}.”
],
“weekdays”:[
“sunday”,
“monday”,
“tuesday”,
“wednesday”,
“thursday”,
“friday”,
“saturday”
]
},
“assert”:[
{
“type”:“contains-any”,
“value”:[
“interval=1w download=true | {{weekdays}}=count(_time[day]={{day_index}}) | top(file_type)”
]
}
]
}
]michaelmichaelmichael
03/31/2025, 4:59 AMdefaultTest:
options:
transformVars: |
// Map weekdays to their corresponding numeric indices (1-7)
// Note: In many systems, Sunday is 0, Monday is 1, etc.
// But according to the user's requirement, we're using Sunday as 1, Monday as 2, etc.
const weekdayMap = {
'sunday': 1,
'monday': 2,
'tuesday': 3,
'wednesday': 4,
'thursday': 5,
'friday': 6,
'saturday': 7
};
// In promptfoo, when iterating through an array variable like 'weekdays',
// each iteration will have a single weekday value in 'vars.weekdays'
if (vars.weekdays && typeof vars.weekdays === 'string') {
return { ...vars, day_index: weekdayMap[vars.weekdays.toLowerCase()] || '' };
}
return vars;
https://www.promptfoo.dev/docs/configuration/guide/#transforming-input-variables
Note that this also supports file reference: file://path_to_transform.js:func_name which is my preferred way of writing it.
You can also use a javascript or python test case loader and do the transform there. See https://www.promptfoo.dev/docs/configuration/parameters/#import-from-javascript-or-typescript
Let us know if you get stuck or need more help! Happy to jump on a call.pgduc1511
04/01/2025, 8:41 AMpgduc1511
04/01/2025, 8:45 AMmichaelmichaelmichael
04/02/2025, 1:43 PMpgduc1511
05/11/2025, 3:03 PM