import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts";
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { Browserbase } from "npm:@browserbasehq/sdk";
const browserbase = new Browserbase();
const session = await browserbase.createSession();
const browser = await puppeteer.connect({
browserWSEndpoint: browserbase.getConnectURL({ sessionId: session.id, proxy: true }),
});
const page = (await browser.pages())[0];
await page.goto("https://www.google.com");
await page.type("input", "james blake concert");
await page.keyboard.press("Enter");
await page.waitForSelector("#search");
await page.click(".PBBEhf");
const html = await page.$eval("g-accordion", (el) => el.innerHTML);
console.log(html);
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "system", content: "Return concert dates as JSON array. No code fences." },
{ role: "user", content: html },
],
model: "gpt-3.5-turbo",
max_tokens: 3000,
});
console.log(completion.choices[0].message.content);