💬 在线咨询
AI智能客服 · 深度学习 · 专业中医养生
智能中医顾问
欢迎使用锡安养生的AI咨询服务!基于AI大模型,为您提供专业的中医养生解答。
支持咨询的内容包括:体质辨识、四季养生、药膳食疗、运动养生、预约服务、费用查询等。AI助手会以专业中医的角度为您精准解答。
🤖
您好!我是锡安养生的AI养生顾问,很高兴为您服务!
我是基于AI大模型训练的中医AI助手,可以为您提供专业的养生建议。
您可以咨询:
• 体质养生(九种体质特点)
• 四季养生(春夏秋冬调理方法)
• 药膳食疗(经典方剂推荐)
• 张仲景智慧(医圣养生思想)
• 预约服务(咨询流程)
请告诉我您想了解什么?
const chatMessages = document.getElementById(‘chatMessages’);
const chatInput = document.getElementById(‘chatInput’);
const sendBtn = document.getElementById(‘sendBtn’);
document.getElementById(‘welcomeTime’).textContent = getCurrentTime();
function getCurrentTime() {
const now = new Date();
return now.toLocaleTimeString(‘zh-CN’, { hour: ‘2-digit’, minute: ‘2-digit’ });
}
chatInput.addEventListener(‘input’, function() {
this.style.height = ‘auto’;
this.style.height = this.scrollHeight + ‘px’;
if (this.value === ”) {
this.style.height = ’44px’;
}
});
chatInput.addEventListener(‘keypress’, function(e) {
if (e.key === ‘Enter’ && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
// 发送按钮点击事件
sendBtn.addEventListener(‘click’, function() {
sendMessage();
});
function sendMessage(message) {
const text = message || chatInput.value.trim();
if (!text) return;
sendBtn.disabled = true;
addMessage(‘user’, text);
if (!message) {
chatInput.value = ”;
chatInput.style.height = ’44px’;
}
showTypingIndicator();
callAI(text);
}
function sendQuickReply(text) {
sendMessage(text);
}
function addMessage(type, content) {
const messageDiv = document.createElement(‘div’);
messageDiv.className = ‘message ‘ + type;
const avatar = type === ‘user’ ? ‘👤’ : ‘🤖’;
messageDiv.innerHTML = `
${avatar}
${formatMessage(content)}
${getCurrentTime()}
`;
chatMessages.appendChild(messageDiv);
scrollToBottom();
}
function formatMessage(text) {
return text.replace(/\n/g, ‘
‘);
}
function showTypingIndicator() {
const typingDiv = document.createElement(‘div’);
typingDiv.className = ‘message ai’;
typingDiv.id = ‘typingIndicator’;
typingDiv.innerHTML = `
🤖
`;
chatMessages.appendChild(typingDiv);
scrollToBottom();
}
function hideTypingIndicator() {
const typingIndicator = document.getElementById(‘typingIndicator’);
if (typingIndicator) {
typingIndicator.remove();
}
}
function scrollToBottom() {
chatMessages.scrollTop = chatMessages.scrollHeight;
}
async function callAI(message) {
try {
const apiURL = window.location.origin + ‘/ai-chat-api-deepseek-fixed.php’;
const response = await fetch(apiURL, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
},
body: JSON.stringify({
message: message,
conversation_id: ‘session_’ + Date.now()
})
});
const data = await response.json();
hideTypingIndicator();
if (data.success) {
addMessage(‘ai’, data.message);
} else {
let errorMsg = ‘抱歉,服务暂时不可用。’;
if (data.error) {
errorMsg += ‘ 错误:’ + data.error;
}
addMessage(‘ai’, errorMsg);
}
} catch (error) {
hideTypingIndicator();
addMessage(‘ai’, ‘抱歉,网络错误。请检查网络连接后重试。’);
console.error(‘网络错误:’, error);
} finally {
sendBtn.disabled = false;
}
}