namespace WPForms\Integrations\AI\API;
use WPForms\Integrations\AI\API\Http\Request;
use WPForms\Integrations\AI\Helpers;
$this->request = new Request();
* @param bool $helpful Whether the response was helpful.
* @param string $response_id Response ID to rate.
public function rate( bool $helpful, string $response_id ): array {
'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 $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.
protected function get_limit(): int {
* Filter the limit for the API request.
* @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
* @param string $prompt Prompt text.
protected function prepare_prompt( string $prompt ): string {
$prompt = wp_strip_all_tags( $prompt );
// Remove any extra spaces.
$prompt = preg_replace( '/\s+/', ' ', $prompt );
// Remove any extra characters.
return trim( $prompt, ' .,!?;:' );