[ 'Authorization' => 'Bearer ' . $api_key, 'Content-Type' => 'application/json', ], 'body' => json_encode([ 'model' => $text_model, 'messages' => [['role' => 'system', 'content' => $enhancement_prompt]], ]), 'timeout' => 1000 ]); if (is_wp_error($response_enhancement)) { error_log('Error making enhancement request: ' . $response_enhancement->get_error_message()); return $article_content; // Возвращаем оригинал, если произошла ошибка } $result_enhancement = json_decode(wp_remote_retrieve_body($response_enhancement), true); $enhanced_article_content = $result_enhancement['choices'][0]['message']['content'] ?? $article_content; // Удаление всех комментариев и кодов блоков $enhanced_article_content = preg_replace('//s', '', $enhanced_article_content); $enhanced_article_content = preg_replace('/
.*?<\/code>)/s', '', $enhanced_article_content);
$enhanced_article_content = preg_replace('/(.*?<\/pre>|.*?<\/code>)$/s', '', $enhanced_article_content);
return $enhanced_article_content;
}