| Server IP : 8.134.250.228 / Your IP : 216.73.217.39 Web Server : Apache System : Linux iZ7xv33p9e9ivk7yhmj7ibZ 5.10.134-18.al8.x86_64 #1 SMP Fri Dec 13 16:56:53 CST 2024 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/www.gobluemade.com/wp-content/plugins/wpforms-lite/src/Integrations/AI/API/ |
Upload File : |
<?php
namespace WPForms\Integrations\AI\API;
use WPForms\Integrations\AI\API\Http\Request;
use WPForms\Integrations\AI\Helpers;
/**
* API class.
*
* @since 1.9.1
*/
class API {
/**
* API limit.
*
* @since 1.9.1
*/
const LIMIT = 100;
/**
* API limit max.
*
* @since 1.9.1
*/
const LIMIT_MAX = 1000;
/**
* Request instance.
*
* @since 1.9.1
*
* @var Request
*/
protected $request;
/**
* Initialize the API.
*
* @since 1.9.1
*/
public function init() {
$this->request = new Request();
}
/**
* Rate the response.
*
* @since 1.9.1
*
* @param bool $helpful Whether the response was helpful.
* @param string $response_id Response ID to rate.
*
* @return array
*/
public function rate( bool $helpful, string $response_id ): array {
$args = [
'helpful' => $helpful,
'responseId' => $response_id,
];
$endpoint = '/rate-response';
$response = $this->request->post( $endpoint, $args );
if ( $response->has_errors() ) {
$error_data = $response->get_error_data();
Helpers::log_error( $response->get_log_message( $error_data ), $endpoint, $args );
return $error_data;
}
return $response->get_body();
}
/**
* Get the limit for the API request.
* Returns limit set by the filter or the default limit.
* The limit is capped at LIMIT_MAX.
*
* @since 1.9.1
*
* @return int
*/
protected function get_limit(): int {
return min(
/**
* Filter the limit for the API request.
*
* @since 1.9.1
*
* @param int $limit Limit for the API request.
*/
(int) apply_filters( 'wpforms_integrations_ai_api_get_limit', self::LIMIT ), // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
self::LIMIT_MAX
);
}
/**
* Prepare the prompt.
*
* @since 1.9.1
*
* @param string $prompt Prompt text.
*
* @return string
*/
protected function prepare_prompt( string $prompt ): string {
// Remove any HTML tags.
$prompt = wp_strip_all_tags( $prompt );
// Remove any extra spaces.
$prompt = preg_replace( '/\s+/', ' ', $prompt );
// Remove any extra characters.
return trim( $prompt, ' .,!?;:' );
}
}