forked from samuelgjekic/SamiCustomGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.php
98 lines (84 loc) · 3.77 KB
/
chat.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
<?php
use SamiCustomGPT\Handlers\KnowledgeBaseBuilder;
use SamiCustomGPT\Models\Leads_Bot;
session_start();
use SamiCustomGPT\Models\CustomBotDataModel;
// Embed SamiCustomGPT
use LLPhant\OpenAIConfig;
use SamiCustomGPT\CustomBotClient;
use SamiCustomGPT\Handlers\CustomBotDataHandler;
require_once $_SERVER['DOCUMENT_ROOT'] . '/SamiCustomGPT/chatbot/Interfaces/IKnowledgeBaseHandler.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/SamiCustomGPT/chatbot/Interfaces/ICustomBotClient.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/SamiCustomGPT/chatbot/Handlers/CustomBotDataHandler.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/SamiCustomGPT/chatbot/Handlers/KnowledgeBaseHandler.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/SamiCustomGPT/chatbot/Models/CustomBotDataModel.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/SamiCustomGPT/chatbot/CustomBotClient.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
// Testing custom gpt bot
$config = new OpenAIConfig();
$config->apiKey = '';
$bot_model = new CustomBotDataModel();
$customgpt;
$bot_model->setInstructions(' ');
/* Will create a file from URL, AI will use the file to answer question, then delete the file.
This can be changed to not delete the file, by simply having the vectorFile creation done somewhere other than
chat.php and removing the unlink. */
$filename = '/' . KnowledgeBaseBuilder::createVectorFileFromUrl('https://samicustomgpt.bredfy.com/','/');
$bot_files = [$filename];
$bot_model->setFiles($bot_files);
$bot_model->setTitle('SamiCustomGPT');
$bot_model->setDesc(('The official SamiCustomGPT chatbot'));
$customgpt = new CustomBotClient($bot_model,$config);
unlink($_SERVER['DOCUMENT_ROOT'] . $filename);
// Check if the message parameter is set
if (isset($_POST['message'])) {
$message = $_POST['message'];
// Send the message and return the response
$response = $customgpt->SendConversationToBot($message);
echo json_encode(array("response" => $response, "assistantName" => $bot_model->getTitle()));
exit; // End script execution after sending the response
}
?>
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SamiCustomGPT</title>
<link rel="stylesheet" href="/styles/chatbot.css">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
</head>
<body>
<div id="chatAvatar">
<i class="fas fa-comment chat-icon"></i>
</div>
<div class="chat-container" id="chatCont">
<div class="close-button" id="closeButton">×</div>
<div class="chat-title">SamiCustomGPT</div>
<div class="chat-box" id="chatBox">
<div class="message assistant-message">
<div class="avatar">Sami</div>
<div class="message-content">
<div class="message-title">SamiCustomGPT:</div>
<div class="message-text">Hey there! How can I help you?
<div class="faq-container-deprecated">
<button class="faq-button">What are your hours of operation?</button>
<button class="faq-button">What services do you offer?</button>
<button class="faq-button">How can I contact support?</button>
</div>
</div>
</div>
</div>
</div>
<div class="input-container">
<input type="text" id="messageInput" placeholder="Write your message...">
<button id="sendButton">Send</button>
</div>
<div class="powered-by-text">Created by Samuel Gjekic</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="/chat.js"></script>
</body>
</html>