Using BrainTrust with TestingBot
Braintrust Organization
To get started, make sure you create a new Braintrust organization. Next, install the necessary dependencies:
Install dependencies
To use Braintrust with TestingBot, you need to install the following dependencies:
Variables
To use TestingBot with Braintrust, you need to set the following environment variables: TESTINGBOT_KEY
and TESTINGBOT_SECRET
.
You will also need to set up the AI API Key that you are using. Braintrust supports various AI providers, such as OpenAI, Anthropic and others.
Tools
Braintrust allows you to create tools that can be used by agents. In this example, we will create a tool that takes a URL parameter and will use Readability to convert the HTML.
import * as braintrust from "braintrust";
import { z } from "zod";
import { chromium } from "playwright-core";
async function loadPage({ url }: { url: string }) {
const { id } = await createSession();
const browser = await chromium.connectOverCDP(
wsEndpoint: `wss://cloud.testingbot.com/playwright?key=${testingBotKey}&secret=${testingBotSecret}&browserName=chrome&browserVersion=latest`,
);
const defaultContext = browser.contexts()[0];
const page = defaultContext.pages()[0];
await page.goto(url);
const readable: { title?: string; textContent?: string } =
await page.evaluate(`
import('https://cdn.skypack.dev/@mozilla/readability').then(readability => {
return new readability.Readability(document).parse()
})`);
const text = `${readable.title}\n${readable.textContent}`;
return { page: text };
}
const project = braintrust.projects.create({ name: "TestingBot API Tool" });
project.tools.create({
handler: loadPage,
parameters: z.object({
url: z.string(),
}),
returns: z.object({
page: z.string(),
}),
name: "Load page",
slug: "load-page",
description: "Load a page from the internet",
ifExists: "replace",
});
Deploy tool
You can now deploy the tool to Braintrust. You can do this by running the following command:
Once the tool is deployed, you will see the tool listed in the Library's Tools section. Now you can specify a URL and use the "Load page" tool to use the TestingBot tool.