1

I am using GPT 3.5 Chat Completion API to write a 2000 words article, but it produces only about 1000 words response regardless of the topic. So I am trying to get it to write one half of the article in 1000 words at a time, but it only responds with the second half:-

// Request headers
$headers = [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $apiKey,
];

// API endpoint URL
$url = 'https://api.openai.com/v1/chat/completions';

// Request payload
$data = [
    'model' => 'gpt-3.5-turbo-16k',
    'messages' => [
        [
        'role' => 'system',
        'content' => "write first half of a blog post for the keyword provided by the user in 1000 words"
        ],
        [
        'role' => 'user',
        'content' => "drones"
        ],
        [
        'role' => 'system',
        'content' => "write second half of the same blog post for the keyword provided by the user in another 1000 words"
        ],
        [
        'role' => 'user',
        'content' => "drones"
        ],
    ]
];

// Send the API request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);

// Process the API response
if ($response === false) {
    // Request failed
    echo 'Error: ' . curl_error($ch);
} else {
    // Request succeeded
    $responseData = json_decode($response, true);
    // Process the response data
    echo "<pre>";
    print_r($responseData);
    echo "</pre>";
}
Grey Lover
  • 31
  • 1
  • 1
  • 11

0 Answers0