Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I.askGptOnPage and I.askGptOnPageFragment sends Promise to endpoint #4471

Closed
tomaculum opened this issue Aug 26, 2024 · 1 comment · Fixed by #4486
Closed

I.askGptOnPage and I.askGptOnPageFragment sends Promise to endpoint #4471

tomaculum opened this issue Aug 26, 2024 · 1 comment · Fixed by #4486

Comments

@tomaculum
Copy link
Contributor

What are you trying to achieve?

I want to use the I.askGptOnPage() or I.askGptOnPageFragment() function to get a response based on the html code passed to the gpt endpoint.

What do you get instead?

No usable response since the html code was not sent properly:

[
   {
        role: 'user',
        content: 'Is the text "The world’s leading AI-powered developer platform" displayed on the page?'
    },
    {   role: 'user', content: 'Within this HTML: [object Promise]' }
]
npx codeceptjs run --verbose --ai
***************************************
nodeInfo:  22.7.0
osInfo:  macOS 15.1
cpuInfo:  (8) x64 Apple M1
chromeInfo:  128.0.6613.84
edgeInfo:  Not Found
firefoxInfo:  undefined
safariInfo:  18.0
If you need more detailed info, just run this: npx codeceptjs info
***************************************
CodeceptJS v3.6.5 #StandWithUkraine
Using test root "/Users/tom/workspaces/WebstormProjects/test"
Helpers: Playwright, AI
Plugins: screenshotOnFail, tryTo, retryFailedStep, retryTo, eachElement

askgpt --
    [1]  Starting recording promises
    Timeouts: 
 › [Session] Starting singleton browser session
  test askGptOnPage
    I ask gpt on page "Is the text "The world’s leading AI-powered developer platform" displayed on the page?"
⠋  Processing AI request...[
  {
    role: 'user',
    content: 'Is the text "The world’s leading AI-powered developer platform" displayed on the page?'
  },
  { role: 'user', content: 'Within this HTML: [object Promise]' }
]
(node:71080) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
It looks like you've pasted an object reference or the text "[object Promise]" instead of the actual HTML code.

To determine if the text "The world’s leading AI-powered developer platform" is displayed on a web page, you need to check the HTML content of that web page.

Please provide the actual HTML code or a relevant portion of it so I can help you check if that specific text is present.
  ✔ OK in 1919ms


  OK  | 1 passed   // 3s
AI assistant took 2s and used ~1K input tokens. Tokens limit: 10K
  • test source code:
Feature('askgpt');

Scenario('test askGptOnPage',  ({ I }) => {
    I.askGptOnPage('Is the text "The world’s leading AI-powered developer platform" displayed on the page?');
});

Details

  • CodeceptJS version: 3.6.5
  • NodeJS Version: 22.7.0
  • Operating System: macOS 15.1
  • @playwright/test: 1.46.1
  • Configuration file:
require('dotenv').config();
const { setHeadlessWhen, setCommonPlugins } = require('@codeceptjs/configure');
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

/** @type {CodeceptJS.MainConfig} */
exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Playwright: {
      browser: 'chromium',
      url: 'https://www.github.com',
      show: true
    },
    AI: {}
  },
  include: {
    I: './steps_file.js'
  },
  name: 'test',
  ai: {
    maxTokens: 10000,
    request: async (messages) => {
      const { AzureOpenAI } = require("openai");

      const deployment = process.env.AZURE_DEPLOYMENT_ID;
      const endpoint = process.env.AI_API_ENDPOINT
      const apiKey = process.env.AZURE_API_KEY;
      const apiVersion = "2024-07-01-preview";
      const options = { apiKey, endpoint, apiVersion, deployment }
      const client = new AzureOpenAI(options);

      console.log(messages);

      const { choices } = await client.chat.completions.create(
          {
            messages,
            model: '',
            max_tokens: 100
          }
      );
      return choices[0]?.message?.content;
    }
  }
}
@tomaculum tomaculum changed the title I.askGptOnPage and I.askGptOnPageFragment sends Promise I.askGptOnPage and I.askGptOnPageFragment sends Promise to endpoint Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@tomaculum and others