umstellen auf python
This commit is contained in:
23
api.php
23
api.php
@@ -1,23 +1,26 @@
|
||||
<?php
|
||||
// Einbinden der Konfigurationsdatei
|
||||
// Include the configuration file
|
||||
require_once 'config.php';
|
||||
|
||||
// Überprüfen, ob eine POST-Anfrage gesendet wurde
|
||||
// Check if a POST request is sent
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Lesen der Eingabe aus dem POST-Body
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$user_message = $input['message'];
|
||||
|
||||
// Hier würden Sie den API-Aufruf an OpenAI mit den Konfigurationsvariablen durchführen
|
||||
// Dies ist ein Platzhalter für die tatsächliche API-Implementierung
|
||||
$response = "Dies ist eine Beispielantwort vom ChatGPT-Assistenten.";
|
||||
// Prepare the command to execute the Python script
|
||||
// Note: Make sure `python` or `python3` is properly configured in your system's PATH.
|
||||
$command = escapeshellcmd("python3 assistant.py '$user_message'");
|
||||
$output = shell_exec($command);
|
||||
|
||||
// Senden der Antwort zurück an das Frontend
|
||||
// Decode the response from Python script
|
||||
$response = json_decode($output, true);
|
||||
|
||||
// Send back the response
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['response' => $response]);
|
||||
echo json_encode(['response' => $response['response']]);
|
||||
} else {
|
||||
// Wenn keine POST-Anfrage, senden Sie einen Fehler
|
||||
// If not a POST request, return an error
|
||||
header('HTTP/1.1 405 Method Not Allowed');
|
||||
echo 'Nur POST-Anfragen sind erlaubt.';
|
||||
echo 'Only POST requests are allowed.';
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user