Hello, for learning purpose i generate the code to use Chat GPT with php. Code hint are generated from ChatGPT
<?php
require 'vendor/autoload.php';
function generateChatResponse($message) {
$openaiApiKey = 'KEY;
$url = 'https://api.openai.com/v1/chat/completions';
$client = new GuzzleHttp\Client();
$headers = [
'Authorization' => 'Bearer ' . $openaiApiKey,
'Content-Type' => 'application/json',
];
$data = [
'messages' => [['role' => 'system', 'content' => 'You are a PHP developer.']],
'max_tokens' => 50, // Adjust the response length as per your requirements.
'model' => 'gpt-3.5-turbo',
];
$response = $client->post($url, [
'headers' => $headers,
'json' => $data,
]);
$responseBody = json_decode($response->getBody(), true);
$reply = $responseBody['choices'][0]['message']['content'];
return $reply;
}
$userMessage = 'Hello, how can I integrate ChatGPT with PHP?';
$chatReply = generateChatResponse($userMessage);
echo $chatReply; // Output the generated response
but soon when i render that file i am getting error
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://api.openai.com/v1/chat/completions
resulted in a 429 Too Many Requests
response: { “error”: { “message”: “You exceeded your current quota, please check your plan and billing details.”, (truncated…)"
also please guide me, how my credit used? I never create api before just created that. Is that trial balance auto deleted? is any way i can restore that credit again please.
With PHP the best and easy way to integrate please guide me