сделай код лучше и сам чат максимально похожим на оригинал - <?php
/*
Plugin Name: ChatGPT Enhanced Integration
Description: A beautifully designed ChatGPT integration with Russian language support, featuring icons and stylish buttons.
Version: 1.0
Author: Your Name
*/

// Prevent direct access
if (!defined('ABSPATH')) exit;

class ChatGPT_Enhanced_Integration {
    private $api_key = 'YOUR_API_KEY_HERE'; // Вставьте ваш API ключ сюда

    public function __construct() {
        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
        add_shortcode('chatgpt', array($this, 'chatgpt_shortcode'));

        add_action('wp_ajax_nopriv_chatgpt_request', array($this, 'handle_request'));
        add_action('wp_ajax_chatgpt_request', array($this, 'handle_request'));
    }

    public function enqueue_scripts() {
        wp_enqueue_script('jquery');
        wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css');
        
        wp_register_script('chatgpt-script', '', [], false, true);
        wp_enqueue_script('chatgpt-script');
        
        wp_add_inline_script('chatgpt-script', "
            jQuery(document).ready(function($) {
                $('#chatgpt-send').click(function() {
                    var message = $('#chatgpt-message').val();
                    if(message.trim() !== '') {
                        $('#chatgpt-chat').append('<div class=\"chat-bubble user\"><span>' + message + '</span></div>');
                        $('#chatgpt-message').val('');
                        $.ajax({
                            url: '" . admin_url('admin-ajax.php') . "',
                            method: 'POST',
                            data: {
                                action: 'chatgpt_request',
                                message: message
                            },
                            success: function(response) {
                                var data = JSON.parse(response);
                                $('#chatgpt-chat').append('<div class=\"chat-bubble bot\"><span>' + data.response + '</span></div>');
                                $('#chatgpt-chat').scrollTop($('#chatgpt-chat')[0].scrollHeight);
                            }
                        });
                    }
                });

                $('#clear-chat').click(function() {
                    $('#chatgpt-chat').empty();
                });
            });
        ");
    }

    public function handle_request() {
        if (isset($_POST['message'])) {
            $message = sanitize_text_field($_POST['message']);
            $response = $this->get_response($message);
            echo wp_json_encode(array('response' => $response));
        }
        wp_die();
    }

    private function get_response($message) {
        $endpoint = 'https://api.openai.com/v1/engines/davinci/completions';

        $args = array(
            'headers' => array(
                'Authorization' => 'Bearer ' . $this->api_key,
                'Content-Type' => 'application/json',
            ),
            'body' => json_encode(array(
                'prompt' => $message,
                'max_tokens' => 150,
                'top_p' => 1.0,
                'frequency_penalty' => 0.5,
                'presence_penalty' => 0.0,
                'stop' => ["\n"]
            )),
        );

        $response = wp_remote_post($endpoint, $args);

        if (is_wp_error($response)) {
            return 'Ошибка: ' . $response->get_error_message();
        }

        $body = wp_remote_retrieve_body($response);
        $result = json_decode($body, true);

        return $result['choices'][0]['text'] ?? 'Нет ответа от API';
    }

    public function chatgpt_shortcode() {
        ob_start();
        ?>
        <div class="chatgpt-container">
            <div class="chatgpt-chat" id="chatgpt-chat"></div>
            <div class="chatgpt-input">
                <textarea id="chatgpt-message" placeholder="Введите сообщение..."></textarea>
                <button id="chatgpt-send"><i class="fas fa-paper-plane"></i> Отправить</button>
            </div>
            <button id="clear-chat"><i class="fas fa-trash-alt"></i> Очистить чат</button>
        </div>
        <style>
            body {
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
                background-color: #f4f4f9;
                margin: 0;
                padding: 20px;
                display: flex;
                justify-content: center;
                align-items: center;
                height: 100vh;
                color: #333;
            }

            .chatgpt-container {
                width: 100%;
                max-width: 700px;
                border-radius: 12px;
                background: linear-gradient(135deg, #ffffff, #e9eafd);
                box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
                overflow: hidden;
                display: flex;
                flex-direction: column;
            }

            .chatgpt-chat {
                height: 400px;
                overflow-y: auto;
                padding: 20px;
                background: #fff;
                border-bottom: 1px solid #eee;
                flex-grow: 1;
            }

            .chatgpt-input {
                display: flex;
                align-items: center;
                border-top: 1px solid #eee;
                background: #fafafa;
            }

            .chatgpt-input textarea {
                flex: 1;
                border: none;
                padding: 15px;
                font-size: 16px;
                resize: none;
                outline: none;
                border-radius: 0;
            }

            .chatgpt-input button {
                padding: 15px 20px;
                border: none;
                background-color: #28a745;
                color: white;
                cursor: pointer;
                transition: background-color 0.3s ease;
                font-size: 16px;
            }

            .chatgpt-input button:hover {
                background-color: #218838;
            }

            .chat-bubble {
                padding: 10px 20px;
                margin-bottom: 10px;
                border-radius: 20px;
                max-width: 70%;
                word-wrap: break-word;
                position: relative;
                box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
            }

            .chat-bubble.user {
                background-color: #0073aa;
                color: white;
                align-self: flex-end;
            }

            .chat-bubble.bot {
                background-color: #f0f0f5;
                color: #333;
                align-self: flex-start;
            }

            #clear-chat {
                width: 100%;
                padding: 10px;
                background-color: #dc3545;
                color: white;
                border: none;
                cursor: pointer;
                transition: background-color 0.3s ease;
                font-size: 16px;
            }

            #clear-chat:hover {
                background-color: #c82333;
            }
        </style>
        <?php
        return ob_get_clean();
    }
}

new ChatGPT_Enhanced_Integration();