UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

56 lines 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AssertTool = void 0; const Tool_1 = require("./Tool"); const PlaywrightUtils_1 = require("../utils/PlaywrightUtils"); const MiscUtils_1 = require("../utils/MiscUtils"); class AssertTool extends Tool_1.Tool { constructor() { super(AssertTool.NAME, "This method will test that a given condition (i.e. the 'assertionToTestFor' field) holds true.", 'AssertToolCoreParameters', 'AssertToolGptParameters', true); } async call(context, parameters) { const screenshot = await PlaywrightUtils_1.PlaywrightUtils.takePngScreenshot(context.page); const gptPrompt = { type: 'user', items: [ { type: 'png', bytes: screenshot }, { type: 'text', text: `Make the following assertion about the given webpage: ${parameters.assertionToTestFor}`, }, ], }; const assertionOutcome = await context.gptClient.getStructuredOutput([gptPrompt], AssertTool.ASSERTION_OUTCOME_SCHEMA); MiscUtils_1.MiscUtils.updateTokenCounts(assertionOutcome, context.metadata); const assertPassed = assertionOutcome.output.assertionPassed ? true : false; const report = assertPassed ? `Assertion PASSED for: ${parameters.assertionToTestFor}\nDetails: ${assertionOutcome.output.details}` : `Assertion FAILED for: ${parameters.assertionToTestFor}\nDetails: ${assertionOutcome.output.details}`; return { isSuccessful: assertPassed, forLlm: report, metadata: assertionOutcome.output, }; } async callFromGpt(context, parameters) { return this.call(context, parameters); } } exports.AssertTool = AssertTool; AssertTool.NAME = 'assert'; AssertTool.ASSERTION_OUTCOME_SCHEMA = { type: 'object', required: ['details', 'assertionPassed'], properties: { details: { type: 'string', description: 'Details of the evaluation itself (i.e. why it passed or failed). Only comment on the evaluation itself, not extraneous details.', }, assertionPassed: { type: 'boolean', description: 'Set to true IFF the assertion holds, otherwise, set to false if the assertion does not hold.', }, }, additionalProperties: false, }; //# sourceMappingURL=AssertTool.js.map