donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
59 lines (55 loc) • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnalyzePageTextTool = void 0;
const Tool_1 = require("./Tool");
const MiscUtils_1 = require("../utils/MiscUtils");
class AnalyzePageTextTool extends Tool_1.Tool {
constructor() {
super(AnalyzePageTextTool.NAME, `Run an analysis on the current webpage's full raw text. Note that since this runs an analysis on the raw text,
rather than, the HTML of the page, the raw text may be a bit jumbled, have its styling lost, careful
positioning lost, etc. This tool is useful if there happens to be a lot of text on a page, and it would be
tedious to scroll through the entirety of the page in order to get enough context to run an analysis.
If there is context relevant to running the analysis that would not be found in the webpage text itself,
perhaps context given in another message, prompt, overall object, etc, then provide it in the
"additionalRelevantContext" parameter.`, 'AnalyzePageTextToolCoreParameters', 'AnalyzePageTextToolGptParameters', true);
}
async call(context, parameters) {
const page = context.page;
const webpageRawText = await page.evaluate(() => document.body.innerText);
const prompt = `
\`\`\`
${webpageRawText}
\`\`\`
Above is the raw textual content of the webpage ${page.url()}
Note that since this is the raw textual content, the text may be a bit jumbled, have its styling lost,
careful positioning lost, etc.
Run the following analysis on the above raw website text:
${parameters.analysisToRun}
`;
const resp = await context.gptClient.getMessage([
{
type: 'user',
items: [
{
type: 'text',
text: prompt,
},
],
},
]);
MiscUtils_1.MiscUtils.updateTokenCounts(resp, context.metadata);
return {
isSuccessful: true,
forLlm: resp.text,
metadata: {
analysis: resp.text,
},
};
}
callFromGpt(context, parameters) {
return this.call(context, parameters);
}
}
exports.AnalyzePageTextTool = AnalyzePageTextTool;
AnalyzePageTextTool.NAME = 'analyzePageText';
//# sourceMappingURL=AnalyzePageTextTool.js.map