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

CYS - AI Improvements #42800

Merged
merged 22 commits into from Dec 15, 2023
Merged

CYS - AI Improvements #42800

merged 22 commits into from Dec 15, 2023

Conversation

nefeline
Copy link
Member

@nefeline nefeline commented Dec 13, 2023

Submission Review Guidelines:

Changes proposed in this Pull Request:

On this PR, a series of changes are made to improve AI content generation and image management, including:

JSON Mode Enabled

  • Enable JSON Mode to ensure the AI model is constrained to only generate strings that parse into valid JSON objects. In practice, this represents an improvement in consistency and performance, as we won't have to rely as much on the built in retry mechanism to ensure the content was generated correctly.

Improvements for images assigned to products

  • Reduce the size of the images uploaded to the media library for products. While the /wpcom/v2/external-media/list/pexels endpoint provides a series of predefined image sizes for usage, none of them were ideal for our use-case when it comes to products, with the images accessible via URL (and ['thumbnails']['large']) being too big and the images accessible via ['thumbnails']['medium'] and ['thumbnails']['small'] being too low quality. Initially, we were relying on the highest quality possible, which would work as expected most of the time. Still, on occasion, when the returned image was too big, it could trigger memory exhaustion errors on servers with limited resources, such as JN, which we have been using for testing. This change ensures that images still have a good resolution while at the same time ensuring that they have a reasonable size for downloading and uploading to the media library without any problems.

  • Similarly to what was already implemented on ai/patterns endpoint, created a transient to store images fetched from Pexels and make them accessible whenever a request to ai/product is made but for some reason interrupted due to unavailability of AI or equivalent, avoiding making additional requests to Pexels and AI to generate a search term and fetch images that were already successfully fetched for that execution in particular. This change should improve performance and also reduce costs with AI.

Updated Prompts

  • All prompts were updated for improved consistency, with specific roles being given to AI depending on the expected output.
  • The prompt for generating the search term to fetch images from Pexels was updated to return multiple words for the search instead of just one while avoiding generic verbiage that could cause inconsistencies on the selected images.
  • The prompt for generating product content was updated to rely on the search term used to fetch the images from Pexels for improved accuracy.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Create a new WooCommerce installation with this version.
  2. Ensure Jetpack is installed and your site is connected with JP.
  3. Ensure you have the WooCommerce Beta Tester plugin installed and activated (available on this monorepo).
  4. Ensure you have the Woo AI plugin installed and activated (available on this monorepo).
  5. Head over to /wp-admin/tools.php?page=woocommerce-admin-test-helper and enable customize-store feature flag:
Screenshot 2023-10-22 at 10 32 24
  1. Head over to WooCommerce -> Home and click on "Start Customizing":
Screenshot 2023-12-14 at 10 14 00
  1. Click Design with AI button
  2. Fill out a business description and proceed
  3. Make sure everything works as expected, and you can have your store with AI-generated content without problems.
latest_ai_demo.mov

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Enhancement - Improve the AI content generation experience within the CYS onboarding flow.

Comment

…ion for the woocommerce-blocks/testimonials-3-columns pattern.
…dpoint callback in case execution is interrupted so images don't have to be fetched from Pexels again.
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Dec 13, 2023
@nefeline nefeline self-assigned this Dec 13, 2023
@@ -245,7 +245,7 @@ private function fetch_and_validate_ai_responses( $ai_connection, $token, $forma
$success = false;
while ( $ai_request_retries < 5 && ! $success ) {
$ai_request_retries ++;
$ai_responses = $ai_connection->fetch_ai_responses( $token, $formatted_prompts, 60 );
$ai_responses = $ai_connection->fetch_ai_responses( $token, $formatted_prompts, 60, 'json_object' );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

github-actions bot commented Dec 13, 2023

Test Results Summary

Commit SHA: d1c7034

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests258003026113m 37s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@nefeline nefeline marked this pull request as ready for review December 14, 2023 13:36
Copy link
Contributor

github-actions bot commented Dec 14, 2023

Hi @albarin, @gigitux,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@nefeline nefeline added the type: enhancement The issue is a request for an enhancement. label Dec 14, 2023
Copy link
Contributor

@albarin albarin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!
It was very interesting to see these prompt updates and they seem to be working great!
🙌

@nefeline nefeline merged commit 6917260 into trunk Dec 15, 2023
26 checks passed
@nefeline nefeline deleted the update/ai-requests-improvements branch December 15, 2023 14:49
@github-actions github-actions bot added this to the 8.5.0 milestone Dec 15, 2023
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Dec 15, 2023
@nigeljamesstevenson nigeljamesstevenson added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: ai needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris team: Kirigami & Origami type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants