WooCommerce Code Reference

Connection
in package

Class Connection

Table of Contents

MODEL  = 'gpt-3.5-turbo-1106'
TEXT_COMPLETION_API_URL  = 'https://public-api.wordpress.com/wpcom/v2/text-completion'
fetch_ai_response()  : mixed
The post request.
fetch_ai_responses()  : array<string|int, mixed>|WP_Error
Fetch the AI responses in parallel using the given token and prompts.
get_jwt_token()  : string|WP_Error
Fetch the JWT token.
get_site_id()  : int|WP_Error
Return the site ID.

Constants

TEXT_COMPLETION_API_URL

public mixed TEXT_COMPLETION_API_URL = 'https://public-api.wordpress.com/wpcom/v2/text-completion'

Methods

fetch_ai_response()

The post request.

public fetch_ai_response(string $token, string $prompt[, int $timeout = 15 ][, string $response_format = null ]) : mixed
Parameters
$token : string

The JWT token.

$prompt : string

The prompt to send to the API.

$timeout : int = 15

The timeout for the request.

$response_format : string = null

The response format.

Return values
mixed

fetch_ai_responses()

Fetch the AI responses in parallel using the given token and prompts.

public fetch_ai_responses(string $token, array<string|int, mixed> $prompts[, int $timeout = 15 ][, string $response_format = null ]) : array<string|int, mixed>|WP_Error
Parameters
$token : string

The JWT token.

$prompts : array<string|int, mixed>

The prompts to send to the API.

$timeout : int = 15

The timeout for the request.

$response_format : string = null

The response format.

Return values
array<string|int, mixed>|WP_ErrorThe responses or a WP_Error object.

get_jwt_token()

Fetch the JWT token.

public get_jwt_token(int $site_id) : string|WP_Error
Parameters
$site_id : int

The site ID.

Return values
string|WP_ErrorThe JWT token or a WP_Error object.

get_site_id()

Return the site ID.

public get_site_id() : int|WP_Error
Return values
int|WP_ErrorThe site ID or a WP_Error object.