317 lines
9.0 KiB
HTML
317 lines
9.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>AI 客服系统</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
height: 100vh;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.chat-container {
|
|
width: 90%;
|
|
max-width: 600px;
|
|
height: 80vh;
|
|
background: white;
|
|
border-radius: 20px;
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.chat-header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.chat-header h1 {
|
|
font-size: 1.5rem;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.chat-header p {
|
|
opacity: 0.9;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.session-id {
|
|
font-size: 0.8rem;
|
|
opacity: 0.7;
|
|
margin-top: 5px;
|
|
}
|
|
|
|
.chat-messages {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 20px;
|
|
background: #f8f9fa;
|
|
}
|
|
|
|
.message {
|
|
margin-bottom: 15px;
|
|
display: flex;
|
|
align-items: flex-start;
|
|
}
|
|
|
|
.message.user {
|
|
flex-direction: row-reverse;
|
|
}
|
|
|
|
.message-avatar {
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 1.2rem;
|
|
margin: 0 10px;
|
|
}
|
|
|
|
.message.bot .message-avatar {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
}
|
|
|
|
.message.user .message-avatar {
|
|
background: #28a745;
|
|
}
|
|
|
|
.message-content {
|
|
max-width: 70%;
|
|
padding: 12px 16px;
|
|
border-radius: 18px;
|
|
word-wrap: break-word;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.message.bot .message-content {
|
|
background: white;
|
|
border: 1px solid #e0e0e0;
|
|
color: #333;
|
|
}
|
|
|
|
.message.user .message-content {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
}
|
|
|
|
.chat-input-container {
|
|
padding: 20px;
|
|
background: white;
|
|
border-top: 1px solid #e0e0e0;
|
|
}
|
|
|
|
.chat-input-wrapper {
|
|
display: flex;
|
|
gap: 10px;
|
|
}
|
|
|
|
.chat-input {
|
|
flex: 1;
|
|
padding: 12px 20px;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 25px;
|
|
font-size: 1rem;
|
|
outline: none;
|
|
transition: border-color 0.3s;
|
|
}
|
|
|
|
.chat-input:focus {
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.send-btn {
|
|
padding: 12px 24px;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 25px;
|
|
cursor: pointer;
|
|
font-size: 1rem;
|
|
transition: transform 0.2s, box-shadow 0.2s;
|
|
}
|
|
|
|
.send-btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.send-btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.typing-indicator {
|
|
display: none;
|
|
padding: 12px 16px;
|
|
background: white;
|
|
border-radius: 18px;
|
|
border: 1px solid #e0e0e0;
|
|
}
|
|
|
|
.typing-indicator.active {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
}
|
|
|
|
.typing-indicator span {
|
|
width: 8px;
|
|
height: 8px;
|
|
background: #999;
|
|
border-radius: 50%;
|
|
animation: typing 1.4s infinite;
|
|
}
|
|
|
|
.typing-indicator span:nth-child(2) {
|
|
animation-delay: 0.2s;
|
|
}
|
|
|
|
.typing-indicator span:nth-child(3) {
|
|
animation-delay: 0.4s;
|
|
}
|
|
|
|
@keyframes typing {
|
|
0%, 60%, 100% { transform: translateY(0); }
|
|
30% { transform: translateY(-10px); }
|
|
}
|
|
|
|
.welcome-message {
|
|
text-align: center;
|
|
color: #666;
|
|
padding: 20px;
|
|
font-size: 0.9rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="chat-container">
|
|
<div class="chat-header">
|
|
<h1>🤖 AI 客服助手</h1>
|
|
<p>基于 LangChain + LangGraph 构建</p>
|
|
<div class="session-id">会话ID: <span id="sessionId">{{ session_id }}</span></div>
|
|
</div>
|
|
|
|
<div class="chat-messages" id="chatMessages">
|
|
<div class="welcome-message">
|
|
👋 你好!我是 AI 客服助手,请问有什么可以帮您的?
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chat-input-container">
|
|
<div class="typing-indicator" id="typingIndicator">
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
</div>
|
|
<div class="chat-input-wrapper">
|
|
<input
|
|
type="text"
|
|
class="chat-input"
|
|
id="chatInput"
|
|
placeholder="请输入您的问题..."
|
|
onkeypress="handleKeyPress(event)"
|
|
>
|
|
<button class="send-btn" id="sendBtn" onclick="sendMessage()">
|
|
发送
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const sessionId = document.getElementById('sessionId').textContent;
|
|
const chatMessages = document.getElementById('chatMessages');
|
|
const chatInput = document.getElementById('chatInput');
|
|
const sendBtn = document.getElementById('sendBtn');
|
|
const typingIndicator = document.getElementById('typingIndicator');
|
|
|
|
function handleKeyPress(event) {
|
|
if (event.key === 'Enter') {
|
|
sendMessage();
|
|
}
|
|
}
|
|
|
|
function addMessage(content, isUser) {
|
|
const messageDiv = document.createElement('div');
|
|
messageDiv.className = `message ${isUser ? 'user' : 'bot'}`;
|
|
messageDiv.innerHTML = `
|
|
<div class="message-avatar">${isUser ? '👤' : '🤖'}</div>
|
|
<div class="message-content">${escapeHtml(content)}</div>
|
|
`;
|
|
chatMessages.appendChild(messageDiv);
|
|
chatMessages.scrollTop = chatMessages.scrollHeight;
|
|
}
|
|
|
|
function showTyping() {
|
|
typingIndicator.classList.add('active');
|
|
}
|
|
|
|
function hideTyping() {
|
|
typingIndicator.classList.remove('active');
|
|
}
|
|
|
|
function escapeHtml(text) {
|
|
const div = document.createElement('div');
|
|
div.textContent = text;
|
|
return div.innerHTML;
|
|
}
|
|
|
|
async function sendMessage() {
|
|
const message = chatInput.value.trim();
|
|
if (!message) return;
|
|
|
|
// 添加用户消息
|
|
addMessage(message, true);
|
|
chatInput.value = '';
|
|
|
|
// 显示输入中
|
|
showTyping();
|
|
sendBtn.disabled = true;
|
|
|
|
try {
|
|
const response = await fetch('/chat', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
message: message,
|
|
session_id: sessionId
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
hideTyping();
|
|
addMessage(data.response, false);
|
|
} catch (error) {
|
|
hideTyping();
|
|
addMessage('抱歉,服务出现错误,请稍后重试。', false);
|
|
console.error('Error:', error);
|
|
} finally {
|
|
sendBtn.disabled = false;
|
|
}
|
|
}
|
|
|
|
// 聚焦输入框
|
|
chatInput.focus();
|
|
</script>
|
|
</body>
|
|
</html>
|