Brand Name Generator

function generate_openai_brand_names($prompt, $count = 5) {
    $apiKey = 'your_openai_api_key';  // Replace with your actual OpenAI API key
    $apiUrl = 'https://api.openai.com/v1/completions';

    $data = [
        'model' => 'text-davinci-003',  // Choose the appropriate model
        'prompt' => $prompt,
        'max_tokens' => 50,
        'n' => $count,
        'stop' => "\n",
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $apiUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $apiKey
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    if (!$response) {
        return ['error' => 'API request failed'];
    }

    $decoded = json_decode($response, true);
    return array_column($decoded['choices'], 'text');
}

function display_brand_names_on_wordpress() {
    $brandNames = generate_openai_brand_names("Generate a unique brand name for:", 5);
    if(isset($brandNames['error'])) {
        echo '<div>Error: ' . $brandNames['error'] . '</div>';
    } else {
        echo '<div class="brand-names-list">';
        foreach ($brandNames as $name) {
            echo '<h2>' . htmlspecialchars(trim($name)) . '</h2>';
        }
        echo '</div>';
    }
}
Scroll to Top