<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Chat and Learning System</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
.chat-container {
width: 100%;
max-width: 600px;
height: 80%;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
overflow: hidden;
}
.chat-window {
flex-grow: 1;
padding: 20px;
overflow-y: scroll;
display: flex;
flex-direction: column;
}
.message {
margin: 10px 0;
}
.user-message {
align-self: flex-end;
background-color: #007bff;
color: white;
padding: 10px 15px;
border-radius: 15px;
max-width: 80%;
}
.ai-message {
align-self: flex-start;
background-color: #eaeaea;
padding: 10px 15px;
border-radius: 15px;
max-width: 80%;
}
.chat-input {
display: flex;
padding: 10px;
background-color: #f1f1f1;
border-top: 1px solid #ddd;
}
.chat-input input {
flex-grow: 1;
padding: 10px;
border: none;
border-radius: 20px;
margin-right: 10px;
outline: none;
}
.chat-input button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 20px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-window" id="chatWindow">
<!-- ข้อความสนทนาจะถูกแสดงที่นี่ -->
</div>
<div class="chat-input">
<input type="text" id="userInput" placeholder="พิมพ์คำถามของคุณ...">
<button onclick="sendMessage()">ส่ง</button>
</div>
</div>
<script>
const chatWindow = document.getElementById('chatWindow');
function sendMessage() {
const userInput = document.getElementById('userInput').value;
if (userInput.trim() !== '') {
// แสดงข้อความของผู้ใช้
displayMessage(userInput, 'user-message');
// ส่งข้อความไปที่ AI (ในที่นี้แค่ตัวอย่าง static)
setTimeout(() => {
const aiResponse = getAIResponse(userInput);
displayMessage(aiResponse, 'ai-message');
}, 1000); // เวลาในการตอบ
}
document.getElementById('userInput').value = '';
}
function displayMessage(message, className) {
const messageElement = document.createElement('div');
messageElement.classList.add('message', className);
messageElement.innerText = message;
chatWindow.appendChild(messageElement);
chatWindow.scrollTop = chatWindow.scrollHeight; // เลื่อนลงอัตโนมัติ
}
function getAIResponse(userInput) {
// การตอบกลับของ AI ในที่นี้สามารถพัฒนาเพิ่มเติมได้
// ตัวอย่าง AI ที่ตอบกลับแบบเบื้องต้น
const responses = {
"สวัสดี": "สวัสดีค่ะ! มีอะไรให้ช่วยเหลือไหม?",
"คุณชื่ออะไร": "ฉันคือ AI ที่นี่เพื่อช่วยเหลือคุณ",
"วันนี้อากาศเป็นยังไง": "ขอโทษค่ะ ตอนนี้ฉันยังไม่สามารถตรวจสอบสภาพอากาศได้"
};
return responses[userInput] || "ขอโทษค่ะ ฉันยังไม่เข้าใจคำถามนี้ แต่ฉันจะพยายามเรียนรู้";
}
</script>
</body>
</html>