From fd02dbf1dc8715d8698cf79d2052636416e97000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Tue, 21 Nov 2023 09:45:47 +0100 Subject: [PATCH 1/3] Generate the product price with AI --- src/Patterns/ProductUpdater.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Patterns/ProductUpdater.php b/src/Patterns/ProductUpdater.php index e2b8113e6e6..929177228fc 100644 --- a/src/Patterns/ProductUpdater.php +++ b/src/Patterns/ProductUpdater.php @@ -251,6 +251,7 @@ public function update_product_content( $ai_generated_product_content ) { $product->set_name( $ai_generated_product_content['title'] ); $product->set_description( $ai_generated_product_content['description'] ); + $product->set_regular_price( $ai_generated_product_content['price'] ); require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; @@ -292,6 +293,7 @@ public function assign_ai_selected_images_to_dummy_products( $dummy_products_to_ $products_information_list[] = [ 'title' => 'A product title', 'description' => 'A product description', + 'price' => 'The product price', 'image' => [ 'src' => esc_url( $image_src ), 'alt' => esc_attr( $image_alt ), @@ -329,11 +331,14 @@ public function assign_ai_generated_content_to_dummy_products( $ai_connection, $ $expected_results_format = []; foreach ( $products_information_list as $index => $product ) { - $expected_results_format[ $index ] = ''; + $expected_results_format[ $index ] = [ + 'title' => '', + 'price' => '', + ]; } $formatted_prompt = sprintf( - "Generate two-words titles for products using the following prompts for each one of them: '%s'. Ensure each entry is unique and does not repeat the given examples. Do not include backticks or the word json in the response. Here's an example format: '%s'.", + "Generate two-words titles and price for products using the following prompts for each one of them: '%s'. Ensure each entry is unique and does not repeat the given examples. Ensure each product price is a number and corresponds with the product title that is being advertised. Do not include backticks or the word json in the response. Here's an example format: '%s'.", wp_json_encode( $prompts ), wp_json_encode( $expected_results_format ) ); @@ -381,7 +386,8 @@ public function assign_ai_generated_content_to_dummy_products( $ai_connection, $ } foreach ( $products_information_list as $index => $product_information ) { - $products_information_list[ $index ]['title'] = str_replace( '"', '', $completion[ $index ] ); + $products_information_list[ $index ]['title'] = str_replace( '"', '', $completion[ $index ]['title'] ); + $products_information_list[ $index ]['price'] = $completion[ $index ]['price']; } $success = true; From 643e3403467ef456716094d1dad185e577209226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Tue, 21 Nov 2023 12:29:12 +0100 Subject: [PATCH 2/3] Fine tune the prompt to take into account the store currency --- src/Patterns/ProductUpdater.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Patterns/ProductUpdater.php b/src/Patterns/ProductUpdater.php index 929177228fc..3efac1e7dc2 100644 --- a/src/Patterns/ProductUpdater.php +++ b/src/Patterns/ProductUpdater.php @@ -338,8 +338,9 @@ public function assign_ai_generated_content_to_dummy_products( $ai_connection, $ } $formatted_prompt = sprintf( - "Generate two-words titles and price for products using the following prompts for each one of them: '%s'. Ensure each entry is unique and does not repeat the given examples. Ensure each product price is a number and corresponds with the product title that is being advertised. Do not include backticks or the word json in the response. Here's an example format: '%s'.", + "Generate two-words titles and price for products using the following prompts for each one of them: '%s'. Ensure each entry is unique and does not repeat the given examples. Ensure each product price is a number and it's not too low or too high for the corresponding product title being advertised in the following currency: %s. Do not include backticks or the word json in the response. Here's an example format: '%s'.", wp_json_encode( $prompts ), + get_woocommerce_currency(), wp_json_encode( $expected_results_format ) ); From a428e6dfe4fad90cab4b4a6d0838c6dfc451f08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Tue, 21 Nov 2023 13:58:58 +0100 Subject: [PATCH 3/3] Improve the price prompt --- src/Patterns/ProductUpdater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Patterns/ProductUpdater.php b/src/Patterns/ProductUpdater.php index 3efac1e7dc2..ef219b7b7be 100644 --- a/src/Patterns/ProductUpdater.php +++ b/src/Patterns/ProductUpdater.php @@ -338,7 +338,7 @@ public function assign_ai_generated_content_to_dummy_products( $ai_connection, $ } $formatted_prompt = sprintf( - "Generate two-words titles and price for products using the following prompts for each one of them: '%s'. Ensure each entry is unique and does not repeat the given examples. Ensure each product price is a number and it's not too low or too high for the corresponding product title being advertised in the following currency: %s. Do not include backticks or the word json in the response. Here's an example format: '%s'.", + "Generate two-words titles and price for products using the following prompts for each one of them: '%s'. Ensure each entry is unique and does not repeat the given examples. It should be a number and it's not too low or too high for the corresponding product title being advertised. Convert the price to this currency: '%s'. Do not include backticks or the word json in the response. Here's an example format: '%s'.", wp_json_encode( $prompts ), get_woocommerce_currency(), wp_json_encode( $expected_results_format )