Home / Admin / Prompt Generator Tool
Duplicate Snippet

Embed Snippet on Your Site

Prompt Generator Tool

Code Preview
php
<?php
<?php
// OpenAI API endpoint
$endpoint = 'https://api.openai.com/v1/completions';
// Prompt to send to the API
$prompt = 'Generate a creative writing prompt related to fantasy creatures.';
// Data to send to the API
$data = array(
    'prompt' => $prompt,
    'max_tokens' => 100, // Adjust max_tokens as needed
    'temperature' => 0.7, // Adjust temperature as needed (higher value for more creative responses)
    'n' => 1 // Number of completions to generate
);
// Encode data
$postData = json_encode($data);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Bearer YOUR_API_KEY' // Replace YOUR_API_KEY with your actual API key
));
// Execute cURL request
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    // Decode response
    $responseData = json_decode($response, true);
    // Output generated completion
    echo "Generated Prompt: " . $responseData['choices'][0]['text'];
}
// Close cURL
curl_close($ch);

Comments

Add a Comment