AI
Extends Helper
AI Helper for CodeceptJS.
This helper class provides integration with the AI GPT-3.5 or 4 language model for generating responses to questions or prompts within the context of web pages. It allows you to interact with the GPT-3.5 model to obtain intelligent responses based on HTML fragments or general prompts. This helper should be enabled with any web helpers like Playwright or Puppeteer or WebDriver to ensure the HTML context is available.
Use it only in development mode. It is recommended to run it only inside pause() mode.
Configuration
Section titled “Configuration”This helper should be configured in codecept.conf.{js|ts}
chunkSize: - The maximum number of characters to send to the AI API at once. We split HTML fragments by 8000 chars to not exceed token limit. Increase this value if you use GPT-4.
Parameters
Section titled “Parameters”config
askForPageObject
Section titled “askForPageObject”Generates PageObject for current page using AI.
It saves the PageObject to the output directory. You can review the page object and adjust it as needed and move to pages directory. Prompt can be customized in a global config file.
// create page object for whole pageI.askForPageObject('home');
// create page object with extra promptI.askForPageObject('home', 'implement signIn(username, password) method');
// create page object for a specific elementI.askForPageObject('home', null, '.detail');Asks for a page object based on the provided page name, locator, and extra prompt.
Parameters
Section titled “Parameters”pageNamestring The name of the page to retrieve the object for.extraPrompt(string | null) An optional extra prompt for additional context or information.locator(string | null) An optional locator to find a specific element on the page.
Returns Promise<Object> A promise that resolves to the requested page object.
askGptGeneralPrompt
Section titled “askGptGeneralPrompt”Send a general request to AI and return response.
Parameters
Section titled “Parameters”promptstring
Returns Promise<string> A Promise that resolves to the generated response from the GPT model.
askGptOnPage
Section titled “askGptOnPage”Asks the AI GPT language model a question based on the provided prompt within the context of the current page’s HTML.
I.askGptOnPage('what does this page do?');Parameters
Section titled “Parameters”promptstring The question or prompt to ask the GPT model.
Returns Promise<string> A Promise that resolves to the generated responses from the GPT model, joined by newlines.
askGptOnPageFragment
Section titled “askGptOnPageFragment”Asks the AI a question based on the provided prompt within the context of a specific HTML fragment on the current page.
I.askGptOnPageFragment('describe features of this screen', '.screen');Parameters
Section titled “Parameters”promptstring The question or prompt to ask the GPT-3.5 model.locatorstring The locator or selector used to identify the HTML fragment on the page.
Returns Promise<string> A Promise that resolves to the generated response from the GPT model.