as $suggestion ) {
$suggestions[] = $this->cleanSuggestion( $suggestion );
}
return array_unique( array_filter( $suggestions ) );
}
/**
* Cleans the given post content.
*
* @since 4.5.5
*
* @param string $postContent The post content to clean.
* @return string The cleaned post content.
*/
private function cleanPostContent( $postContent ) {
$postContent = strip_shortcodes( wp_strip_all_tags( $postContent ) );
$postContent = normalize_whitespace( $postContent );
$postContent = preg_replace( '/\v+/', ' ', $postContent ); // Remove new lines.
$postContent = aioseo()->helpers->decodeHtmlEntities( $postContent );
$postContent = wp_trim_words( $postContent, 800 );
return $postContent;
}
/**
* Cleans the given title/description suggestion.
*
* @since 4.5.5
*
* @param string $suggestion The suggestion to clean.
* @return string The cleaned suggestion.
*/
private function cleanSuggestion( $suggestion ) {
$suggestion = stripslashes_deep( wp_filter_nohtml_kses( wp_strip_all_tags( $suggestion ) ) );
$suggestion = aioseo()->helpers->decodeHtmlEntities( $suggestion );
$suggestion = preg_replace( '/\v+/', '', $suggestion );
// Trim quotes from beginning/end and redundant whitespace.
$suggestion = preg_replace( '/^["\']/', '', $suggestion );
$suggestion = preg_replace( '/["\']$/', '', $suggestion );
$suggestion = trim( normalize_whitespace( $suggestion ) );
// Replace the focus KW with the actual focus KW to preserve the casing.
if ( $this->focusKw ) {
$escapedFocusKw = aioseo()->helpers->escapeRegex( $this->focusKw );
$escapedReplaceFocusKw = aioseo()->helpers->escapeRegexReplacement( $this->focusKw );
$suggestion = preg_replace( "/\b{$escapedFocusKw}\b/i", $escapedReplaceFocusKw, $suggestion );
}
$suggestion = ucfirst( $suggestion );
return $suggestion;
}
/**
* Returns the initial messages for the AI.
*
* @since 4.5.5
*
* @return array The initial messages.
*/
private function getMessages() {
$languageCode = get_locale();
$instructions = [
'You will be provided with an online blog article.',
];
if ( 'en_US' !== $languageCode ) {
$instructions[2] = "Make sure each suggestion is in the same language as the article. The relevant language code is {$languageCode}.";
}
if ( $this->focusKw ) {
$instructions[3] = "Second, ensure each suggestion contains the keyword '{$this->focusKw}'.";
}
$instructions[5] = 'Finally, make sure every suggestion starts and ends with triple double quotes in order to delimit them.';
switch ( $this->target ) {
case 'description':
$instructions[1] = 'First, generate 5 suggestions that can be used as the meta description for the article, based on its text.';
$instructions[4] = 'Then, make sure each suggestion is between 120 and 160 characters long.';
break;
case 'title':
default:
$instructions[1] = 'First, generate 5 suggestions that can be used as the SEO title for the article, based on its text.';
$instructions[4] = 'Then, make sure each suggestion is between 50 and 70 characters long and in title case.';
break;
}
$userMessage = 'Below is the article\'s content, delimited with three consecutive double quotes.' . "\n\n" . '"""' . $this->postContent . '"""';
ksort( $instructions, SORT_NUMERIC );
return [
[
'role' => 'system',
'content' => implode( "\n", array_filter( $instructions ) )
],
[
'role' => 'user',
'content' => $userMessage
]
];
}
/**
* Returns the request args.
*
* @since 4.5.5
*
* @param array $messages The messages to send to the AI.
* @return array The request args.
*/
private function getRequestArgs( $messages ) {
$args = [
'timeout' => 120,
'headers' => [
'Authorization' => 'Bearer ' . aioseo()->options->advanced->openAiKey,
'Content-Type' => 'application/json'
],
'body' => [
'max_tokens' => $this->maxTokens,
'temperature' => $this->temperature,
'model' => $this->model,
'stop' => null,
'n' => $this->amountOfResults,
'messages' => $messages
],
'sslverify' => false
];
$args['body'] = wp_json_encode( $args['body'] );
return $args;
}
/**
* Returns the API URL.
*
* @since 4.3.2
*
* @return string The API URL.
*/
public function getUrl() {
if ( defined( 'AIOSEO_AI_URL' ) ) {
return AIOSEO_AI_URL;
}
return $this->baseUrl;
}
}
Fatal error: Uncaught Error: Class "AIOSEO\Plugin\Pro\Ai\Ai" not found in /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php:322
Stack trace:
#0 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php(97): AIOSEO\Plugin\AIOSEO->load()
#1 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php(76): AIOSEO\Plugin\AIOSEO->init()
#2 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php(414): AIOSEO\Plugin\AIOSEO::instance()
#3 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/all_in_one_seo_pack.php(96): aioseo()
#4 /home/valigeria/public_html/wp-settings.php(517): include_once('/home/valigeria...')
#5 /home/valigeria/public_html/wp-config.php(111): require_once('/home/valigeria...')
#6 /home/valigeria/public_html/wp-load.php(50): require_once('/home/valigeria...')
#7 /home/valigeria/public_html/wp-blog-header.php(13): require_once('/home/valigeria...')
#8 /home/valigeria/public_html/index.php(17): require('/home/valigeria...')
#9 {main}
thrown in /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php on line 322