neue Version von Perplexity mit Beispielcode von OpenAI
This commit is contained in:
67
index.php
67
index.php
@@ -1,29 +1,60 @@
|
||||
<?php
|
||||
// Include the configuration file
|
||||
require_once 'config.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 lang="de">
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ChatGPT Assistent</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<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>ChatGPT Assistent</h1>
|
||||
<div id="chat-messages"></div>
|
||||
<form id="chat-form">
|
||||
<input type="text" id="user-input" placeholder="Geben Sie Ihre Nachricht ein..." required>
|
||||
<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>
|
||||
<script>
|
||||
// Pass PHP variables to JavaScript
|
||||
const OPENAI_API_KEY = "<?php echo $openai_api_key; ?>";
|
||||
const ASSISTANT_ID = "<?php echo $assistant_id; ?>";
|
||||
</script>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user