Consider adjusting the API to an OOP design
Hey lucgagan, I really love this project.
I noticed that the API requires you to pass in the same options every time you call auto. Would you consider a more object-oriented approach like this one so users can initialize the function once and then call it repeatedly with the same state? This would also be useful for setting token limits and other configurations due to the nature of the persistent state in objects.
Here's the kind of syntax I was imagining:
import AutoPlaywright from "auto-playwright";
const ap = new AutoPlaywright({
openAiKey: "sk-...",
model: "gpt-4-1106-preview", // this can mirror the model types from OpenAI
// ...whatever else here
});
ap.auto("Get the text of the first link", { page, test })
Let me know what you think, as this would be a bigger change, so I didn't want to start coding anything yet, but I think taking up this approach would have numerous benefits like the ones I mentioned previously. This is also similar to how many other packages behave.
Thanks! Keep up the good work man
I think for most people, a better solution would be to just use Playwright fixtures.
https://playwright.dev/docs/test-fixtures
const test = base.extend<{ auto: TodoPage }>({
auto: async ({ page, test }, use) => {
await use((instructions, options) => {
return auto(instructions, { page, test }, options);
});
},
});
Now you could just use it like:
test("auto Playwright example", async ({ auto, page }) => {
await page.goto("/");
const headerText = await auto("get the header text");
await auto(`Type "${headerText}" in the search box`);
const searchInputHasHeaderText = await auto(`Is the contents of the search box equal to "${headerText}"?`);
expect(searchInputHasHeaderText).toBe(true);
});