Fuer alle die ChatGPT in Symcon integrieren wollen hier ist ein kleines script .
Um dm die API nutzen zu koennen benoetigt ihr ein Konto und muesst einen api key generieren
Die Kosten koennen auf einen beliebigen wert begrenzt werden
<?php
// Replace with your own API key and endpoint
$api_key = 'hier muesst ihr euren api key eintragen';
$api_endpoint = 'https://api.openai.com/v1/chat/completions';
// Prepare the messages to be sent to the API
$messages = [
[
'role' => 'user',
'content' => 'explain quantum entanglement',
],
];
// Prepare the API request headers
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key,
];
// Prepare the API request body
$body = json_encode([
'model' => 'gpt-3.5-turbo',
'messages' => $messages,
]);
// Initialize cURL and set options
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
// Execute the cURL request and decode the response
$response = curl_exec($curl);
curl_close($curl);
$response_data = json_decode($response, true);
// Extract and print the generated text
$generated_text = $response_data['choices'][0]['message']['content'];
echo 'Generated Text: ' . $generated_text . PHP_EOL;