<?php
namespace Automattic\WooCommerce\Blocks\AI;
use Automattic\Jetpack\Connection\Client;
use Jetpack_Options;
use WP_Error;
use WpOrg\Requests\Exception;
use WpOrg\Requests\Requests;
/**
* Class Connection
*
* @internal
*/
class Connection {
const TEXT_COMPLETION_API_URL = 'https://public-api.wordpress.com/wpcom/v2/text-completion';
const MODEL = 'gpt-3.5-turbo-1106';
/**
* The post request.
*
* @param string $token The JWT token.
* @param string $prompt The prompt to send to the API.
* @param int $timeout The timeout for the request.
* @param string $response_format The response format.
*
* @return mixed
*/
public function fetch_ai_response( $token, $prompt, $timeout = 15, $response_format = null ) {
if ( $token instanceof \WP_Error ) {
return $token;
}
$body = array(
'feature' => 'woocommerce_blocks_patterns',
'prompt' => $prompt,
'token' => $token,
'model' => self::MODEL,
);
if ( $response_format ) {
$body['response_format'] = $response_format;
}
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX