61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
// index.php
|
|
session_start();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$userMessage = $_POST['message'] ?? '';
|
|
|
|
if (!empty($userMessage)) {
|
|
// Python-Skript aufrufen
|
|
$command = escapeshellcmd("python3 assistant_api.py " . escapeshellarg($userMessage));
|
|
$response = shell_exec($command);
|
|
$assistantResponse = json_decode($response, true);
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>OpenAI Assistant Chat</title>
|
|
<style>
|
|
.chat-container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
.message {
|
|
margin: 10px 0;
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
}
|
|
.user-message {
|
|
background-color: #e3f2fd;
|
|
}
|
|
.assistant-message {
|
|
background-color: #f5f5f5;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="chat-container">
|
|
<h1>Chat mit OpenAI Assistant</h1>
|
|
|
|
<form method="POST">
|
|
<textarea name="message" rows="4" cols="50" placeholder="Ihre Nachricht..."></textarea>
|
|
<br>
|
|
<button type="submit">Senden</button>
|
|
</form>
|
|
|
|
<?php if (isset($assistantResponse)): ?>
|
|
<div class="message user-message">
|
|
<strong>Sie:</strong> <?php echo htmlspecialchars($userMessage); ?>
|
|
</div>
|
|
<div class="message assistant-message">
|
|
<strong>Assistant:</strong> <?php echo htmlspecialchars($assistantResponse['response']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</body>
|
|
</html>
|