Commit
·
f71b653
1
Parent(s):
5d9bb56
Create Chatbot 1.html
Browse files- Chatbot 1.html +57 -0
Chatbot 1.html
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<html>
|
| 2 |
+
<head>
|
| 3 |
+
<title>AI Chatbot</title>
|
| 4 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
|
| 5 |
+
</head>
|
| 6 |
+
<body>
|
| 7 |
+
<div class="container">
|
| 8 |
+
<h1>AI Chatbot</h1>
|
| 9 |
+
|
| 10 |
+
<div id="chatContainer" class="border p-3 mb-3" style="height: 300px; overflow-y: auto;"></div>
|
| 11 |
+
|
| 12 |
+
<form id="messageForm">
|
| 13 |
+
<div class="mb-3">
|
| 14 |
+
<label for="userMessage" class="form-label">User Message</label>
|
| 15 |
+
<input type="text" class="form-control" id="userMessage" required>
|
| 16 |
+
</div>
|
| 17 |
+
<button type="submit" class="btn btn-primary">Send</button>
|
| 18 |
+
</form>
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
|
| 22 |
+
<script>
|
| 23 |
+
function showAssistantMessage(message) {
|
| 24 |
+
var chatContainer = document.getElementById('chatContainer');
|
| 25 |
+
var assistantMessage = document.createElement('div');
|
| 26 |
+
assistantMessage.innerHTML = '<strong>Assistant:</strong> ' + message;
|
| 27 |
+
chatContainer.appendChild(assistantMessage);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
document.getElementById('messageForm').addEventListener('submit', function(event) {
|
| 31 |
+
event.preventDefault();
|
| 32 |
+
|
| 33 |
+
var userMessage = document.getElementById('userMessage').value;
|
| 34 |
+
|
| 35 |
+
var xhr = new XMLHttpRequest();
|
| 36 |
+
xhr.open('POST', 'https://www.literallyanything.io/api/integrations/chatgpt', true);
|
| 37 |
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
| 38 |
+
|
| 39 |
+
xhr.onreadystatechange = function() {
|
| 40 |
+
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
|
| 41 |
+
var response = JSON.parse(xhr.responseText);
|
| 42 |
+
showAssistantMessage(response.response);
|
| 43 |
+
}
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
var data = JSON.stringify({
|
| 47 |
+
"systemPrompt": "Welcome to the AI Chatbot! How can I assist you today?",
|
| 48 |
+
"prompts": [{ "role": "user", "content": userMessage }]
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
+
xhr.send(data);
|
| 52 |
+
|
| 53 |
+
document.getElementById('userMessage').value = '';
|
| 54 |
+
});
|
| 55 |
+
</script>
|
| 56 |
+
</body>
|
| 57 |
+
</html>
|