async function testAIWorkflow() {
// 1. Create a single experiment for this test run
const { value: experiment, error } = await basalt.monitor.createExperiment(
'feature-slug',
{ name: `Test Run - ${new Date().toISOString()}` }
)
if (error) {
throw new Error(`Failed to create experiment: ${error.message}`)
}
// 2. Define test cases
const testCases = [
{ input: 'Test input 1', expectedProperties: ['clarity', 'conciseness'] },
{ input: 'Test input 2', expectedProperties: ['detail', 'accuracy'] },
// Add more test cases...
]
// 3. Run each test case with the same experiment
for (const testCase of testCases) {
await runTestCase(testCase, experiment)
}
return experiment.id
}
async function runTestCase(testCase, experiment) {
// Create a trace for this test case
const trace = basalt.monitor.createTrace('feature-slug', {
name: `Test: ${testCase.input.substring(0, 20)}...`,
experiment: experiment,
metadata: {
testCase: testCase,
executionTime: new Date().toISOString()
},
evaluators: [
{ slug: 'quality-score' }
]
})
try {
// Run the actual AI workflow
const result = await yourAIWorkflow(testCase.input)
// End the trace with the result
trace.end(result)
} catch (error) {
trace.update({
metadata: { error: error.message }
})
trace.end(`Error: ${error.message}`)
}
}