-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add POC of a testing framework #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18.16.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const TEST_CASES: { | ||
name:string, | ||
expectedOutput: Record<string, unknown>, | ||
startUrl: string, | ||
instructions: string, | ||
}[] = [{ | ||
name: 'fetchActorName', | ||
startUrl: 'https://apify.com', | ||
instructions: `Go to the store page and perform a search for "AI Web Agent". Click the first result. | ||
Extract the name of the Actor and save it in the output as 'actorName'.`, | ||
expectedOutput: { | ||
actorName: 'AI Web Agent', | ||
}, | ||
}]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'zx/globals'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good start, I would make this Actor, which can be push to Apify.
|
||
import fs from 'fs/promises'; | ||
import { TEST_CASES } from './agent_test_cases.js'; | ||
|
||
for (const c of TEST_CASES) { | ||
const input = { | ||
startUrl: c.startUrl, | ||
instructions: c.instructions, | ||
openaiApiKey: process.env.OPENAI_API_KEY, | ||
}; | ||
await fs.writeFile('./storage/key_value_stores/default/INPUT.json', JSON.stringify(input)); | ||
await $`npm run start:dev`; | ||
const outputRaw = await fs.readFile('./storage/key_value_stores/default/OUTPUT.json', { encoding: 'utf8' }); | ||
const output = JSON.parse(outputRaw); | ||
Object.keys(c.expectedOutput).forEach((expectedKey) => { | ||
if (!output[expectedKey]) { | ||
console.log(`ERROR: ${expectedKey} does not exist in the output`); | ||
} else if (c.expectedOutput[expectedKey] !== output[expectedKey]) { | ||
console.log(`ERROR: Expected value for key ${expectedKey} "${c.expectedOutput[expectedKey]}" ` | ||
+ `does not correspond to "${output[expectedKey]}" in the output.`); | ||
} else { | ||
console.log('OK'); | ||
} | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add model as well?