Add Your Heading Text Here
'text-davinci-003', // Specify the model
'prompt' => $user_query,
'max_tokens' => 500,
'temperature' => 0.7
);
// Make a POST request to ChatGPT API
$response = wp_remote_post($api_url, array(
'method' => 'POST',
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $api_key
),
'body' => json_encode($data)
));
// Handle API response
if (is_wp_error($response)) {
return 'Sorry, there was an issue processing your query.';
} else {
$body = wp_remote_retrieve_body($response);
$result = json_decode($body, true);
return $result['choices'][0]['text']; // Return the ChatGPT response
}
}
?>