Automattic\WooCommerce\Blocks\Images
Pexels::define_search_term()
Define the search term to be used on Pexels using the AI endpoint.
The search term is a shorter description of the business.
Method of the class: Pexels{}
No Hooks.
Return
Mixed|\WP_Error
.
Usage
// private - for code of main (parent) class only $result = $this->define_search_term( $ai_connection, $token, $business_description );
- $ai_connection(Connection) (required)
- The AI connection.
- $token(string) (required)
- The JWT token.
- $business_description(string) (required)
- The business description.
Pexels::define_search_term() Pexels::define search term code WC 9.4.2
private function define_search_term( $ai_connection, $token, $business_description ) { $prompt = sprintf( 'You are a teacher. Based on the following business description, \'%s\', describe to a child exactly what this store is selling in one or two words and be as precise as you can possibly be. Do not reply with generic words that could cause confusion and be associated with other businesses as a response. Make sure you do not add double quotes in your response. Do not add any explanations in the response', $business_description ); $response = $ai_connection->fetch_ai_response( $token, $prompt, 30 ); if ( is_wp_error( $response ) ) { return $response; } if ( isset( $response['code'] ) && 'completion_error' === $response['code'] ) { return new \WP_Error( 'search_term_definition_failed', __( 'The search term definition failed.', 'woocommerce' ) ); } if ( ! isset( $response['completion'] ) ) { return new \WP_Error( 'search_term_definition_failed', __( 'The search term definition failed.', 'woocommerce' ) ); } return $response['completion']; }