-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
104 lines (87 loc) · 3.12 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
include_once("openAiObject.php");
?>
<?php
session_start();
//pod jmenem chatbota
$chatBotID ="asst_qwNsFaZ9AQVNHOKNqC8wRDoz";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_SESSION['array'])) {
$_SESSION['array'] = [];
}
else{
$array = $_SESSION["array"];
}
if (isset($array)) {
$array = $test->continue($array,$chatBotID);
}else{
$array = $test->continue(array(),$chatBotID);
$_SESSION["array"] = $array;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css.css">
<title>Jednoduchý chat</title>
</head>
<body>
<div class="chat">
<div class="messages">
<?php
if (isset($_POST['message'])) {
if (strlen($_POST['message'])>1) {
$sendMessage = $_POST["message"];
$test->AddInstruction($sendMessage,isset($_POST["table"]));
$test->NewMessage($sendMessage);
$a= $test->CheckReply();
/*$a=array(
new Message("zprava jedna","user"),
new Message("zprava dva","assistent"),
new Message("zprava tři","user"),
new Message("zprava čtiři","assistent"),
new Message("zprava pět","user"),
new Message("zprava sest","assistent"),
new Message("zprava sedm","user"),
new Message("zprava osm","assistent"),
new Message("zprava devet","user"),
new Message("zprava deset","assistent")
);*/
foreach (array_reverse($a) as $key => $value) {
$role = $value->role;
$message =$value->content[0]->text->value;
$message = $test->ReplaceInResponse($message,$role);
// $message=preg_replace('/\[(https:\/\/.*?)]\((https:\/\/.*?)\)/i', '<a href="\1">\2</a>', $message);
//$message =$value->message;
echo("<p class=\"$role\"><strong> $role<br></strong> $message</p>");
}
}
}
?>
</div>
<form method="post">
<textarea class="message" name="message" cols="23" rows="1"></textarea>
<input type="checkbox" name="table" class="checkbox" title="do tabulky">
<input type="submit" class="send" value="Odeslat">
</form>
</div>
<script src="chat.js"></script>
<script>
//automatická aktualizace (zatím není třeba)
/* var userId = 'x'; // Nahraďte 'x' ID uživatele, kterého chcete sledovat
setInterval(function() {
$.ajax({
url: 'get_messages.php',
data: { 'user_id': userId }, // Přidejte ID uživatele jako parametr požadavku
success: function(data) {
$('.messages').html(data);
var messagesDiv = document.querySelector('.messages');
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
});
}, 1000);
*/
</script>
</body>
</html>