Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions includes/Classifai/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ function is_local_path( string $resource_ref ): bool {
/**
* Safe generic HTTP wrapper compatible with WP VIP.
*
* - Use vip_safe_wp_remote_request() when available.
* - Use vip_safe_wp_remote_request() when available and wanted.
* - Fall back to wp_remote_request() on other scenarios.
* - Respect all call args (timeout, headers, method, etc).
*
Expand All @@ -846,6 +846,9 @@ function is_local_path( string $resource_ref ): bool {
function safe_wp_remote_request( string $method, string $url, array $args = [] ) {
$method = strtoupper( $method );
$args['method'] = $method;
$use_vip = $args['use_vip'] ?? false;

unset( $args['use_vip'] );

// Respect timeout if caller set.
$timeout = isset( $args['timeout'] ) ? (int) $args['timeout'] : 20;
Expand All @@ -860,7 +863,8 @@ function safe_wp_remote_request( string $method, string $url, array $args = [] )
$args['headers']['User-Agent'] = $cached_user_agent;
}

if ( function_exists( 'vip_safe_wp_remote_request' ) ) {
// Use VIP-safe wrapper if available and wanted. Some requests need a longer timeout than VIP allows.
if ( function_exists( 'vip_safe_wp_remote_request' ) && (bool) $use_vip ) {
$fallback = '';
$threshold = 3;
$retry = 20;
Expand Down Expand Up @@ -925,7 +929,7 @@ function safe_file_get_contents( string $file_path, array $args = [] ) {
/**
* Safe GET wrapper compatible with WP VIP.
*
* - Use vip_safe_wp_remote_get() when available.
* - Use vip_safe_wp_remote_get() when available and wanted.
* - Fall back to wp_remote_get() on other scenarios.
* - Respect all call args (timeout, headers, etc).
*
Expand All @@ -942,7 +946,7 @@ function safe_wp_remote_get( string $url, array $args = [] ) {
/**
* Safe POST wrapper compatible with WP VIP.
*
* - Use vip_safe_wp_remote_post() when available.
* - Use vip_safe_wp_remote_post() when available and wanted.
* - Fall back to wp_remote_post() on other scenarios.
* - Respect all call args (timeout, headers, etc).
*
Expand Down
1 change: 1 addition & 0 deletions includes/Classifai/Providers/Azure/ComputerVision.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ protected function authenticate_credentials( string $url, string $api_key ) {
'Content-Type' => 'application/json',
],
'body' => '{"url":"https://classifaiplugin.com/wp-content/themes/fse-classifai-theme/assets/img/header.png"}',
'use_vip' => true,
]
);

Expand Down
1 change: 1 addition & 0 deletions includes/Classifai/Providers/Azure/Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ protected function authenticate_credentials( string $url, string $api_key, strin
'dimensions' => $this->get_dimensions(),
]
),
'use_vip' => true,
]
);

Expand Down
1 change: 1 addition & 0 deletions includes/Classifai/Providers/Azure/OpenAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ protected function authenticate_credentials( string $url, string $api_key, strin
'max_tokens' => 5,
]
),
'use_vip' => true,
]
);

Expand Down
1 change: 1 addition & 0 deletions includes/Classifai/Providers/Azure/Speech.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public function connect_to_service( array $args = array() ): array {
'Ocp-Apim-Subscription-Key' => $default['api_key'],
'Content-Type' => 'application/json',
),
'use_vip' => true,
);

// Create request URL.
Expand Down
4 changes: 2 additions & 2 deletions includes/Classifai/Providers/ElevenLabs/ElevenLabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected function get_models( string $api_key = '' ) {
return new WP_Error( 'auth', esc_html__( 'Please enter your ElevenLabs API key.', 'classifai' ) );
}

$response = $this->request( $this->get_api_url( $this->model_path ), $api_key, 'get' );
$response = $this->request( $this->get_api_url( $this->model_path ), $api_key, 'get', [ 'use_vip' => true ] );

if ( is_wp_error( $response ) ) {
return $response;
Expand Down Expand Up @@ -260,7 +260,7 @@ protected function get_voices( string $api_key = '' ) {
return new WP_Error( 'auth', esc_html__( 'Please enter your ElevenLabs API key.', 'classifai' ) );
}

$response = $this->request( $this->get_api_url( 'voices?per_page=100' ), $api_key, 'get' );
$response = $this->request( $this->get_api_url( 'voices?per_page=100' ), $api_key, 'get', [ 'use_vip' => true ] );

if ( is_wp_error( $response ) ) {
return $response;
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/GoogleAI/GoogleAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function get_models( string $api_key = '' ) {

// Make request to ensure credentials work.
$request = new APIRequest( $api_key );
$response = $request->get( $this->model_url );
$response = $request->get( $this->model_url, [ 'use_vip' => true ] );

if ( is_wp_error( $response ) ) {
return $response;
Expand Down
1 change: 1 addition & 0 deletions includes/Classifai/Providers/Localhost/Ollama.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function get_models( array $args = [] ): array {
$this->get_api_model_url( $default['endpoint_url'] ),
[
'timeout' => 30, // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
'use_vip' => true,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public function get_models( array $args = [] ): array {
$this->get_api_model_url( $default['endpoint_url'] ),
[
'timeout' => 30, // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
'use_vip' => true,
]
);

Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/OpenAI/OpenAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function authenticate_credentials( string $api_key = '' ) {

// Make request to ensure credentials work.
$request = new APIRequest( $api_key );
$response = $request->get( $this->model_url );
$response = $request->get( $this->model_url, [ 'use_vip' => true ] );

return ! is_wp_error( $response ) ? true : $response;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/TogetherAI/TogetherAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function get_models( string $api_key = '' ) {
}

$request = new APIRequest( $api_key );
$response = $request->get( $this->get_api_url( $this->model_path ) );
$response = $request->get( $this->get_api_url( $this->model_path ), [ 'use_vip' => true ] );

if ( is_wp_error( $response ) ) {
return $response;
Expand Down
3 changes: 2 additions & 1 deletion includes/Classifai/Providers/Watson/NLU.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ protected function nlu_authentication_check( array $settings ) {
$base_url = trailingslashit( $settings[ static::ID ]['endpoint_url'] ) . 'v1/analyze';
$url = esc_url( add_query_arg( [ 'version' => WATSON_NLU_VERSION ], $base_url ) );
$options = [
'body' => wp_json_encode(
'body' => wp_json_encode(
[
'text' => 'Lorem ipsum dolor sit amet.',
'language' => 'en',
Expand All @@ -393,6 +393,7 @@ protected function nlu_authentication_check( array $settings ) {
],
]
),
'use_vip' => true,
];

$response = $request->post( $url, $options );
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/XAI/Grok.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ protected function get_models( string $api_key = '' ) {

// Make request to ensure credentials work.
$request = new APIRequest( $api_key );
$response = $request->get( $this->models_url );
$response = $request->get( $this->models_url, [ 'use_vip' => true ] );

if ( is_wp_error( $response ) ) {
return $response;
Expand Down
1 change: 1 addition & 0 deletions includes/Classifai/Services/ServicesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public function check_license_key( string $email, string $license_key ): bool {
'license_key' => $license_key,
'email' => $email,
],
'use_vip' => true,
]
);

Expand Down