Automattic\WooCommerce\Admin\API\AI

StoreTitle::generate_ai_title()privateWC 1.0

Generate the store title powered by AI.

Метод класса: StoreTitle{}

Хуков нет.

Возвращает

Строку|WP_Error|WP_REST_Response. The store title generated by AI.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->generate_ai_title( $business_description );
$business_description(строка) (обязательный)
The business description for a given store.

Код StoreTitle::generate_ai_title() WC 9.7.1

private function generate_ai_title( $business_description ) {
	$ai_connection = new Connection();

	$site_id = $ai_connection->get_site_id();
	if ( is_wp_error( $site_id ) ) {
		return $site_id;
	}

	$token = $ai_connection->get_jwt_token( $site_id );
	if ( is_wp_error( $token ) ) {
		return $token;
	}

	$prompt = "Generate a store title for a store that has the following: '$business_description'. The length of the title should be 1 and 3 words. The result should include only the store title without any other explanation, number or punctuation marks";

	$ai_response = $ai_connection->fetch_ai_response( $token, $prompt );
	if ( is_wp_error( $ai_response ) ) {
		return $ai_response;
	}

	if ( ! isset( $ai_response['completion'] ) ) {
		return '';
	}

	return $ai_response['completion'];
}