diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/public/asdf.html b/public/asdf.html new file mode 100644 index 0000000..d3b97c9 --- /dev/null +++ b/public/asdf.html @@ -0,0 +1,193 @@ + + + + + + Chat API + + + + +
+
+
+ + + +
+
+ + + + diff --git a/public/index.html b/public/index.html index 31a1cc8..edc94ca 100644 --- a/public/index.html +++ b/public/index.html @@ -25,7 +25,6 @@ box-sizing: border-box; overflow-y: auto; } - @media (max-width: 768px) { .chat-container { max-width: 100%; @@ -92,16 +91,6 @@ align-items: center; justify-content: center; } - font-size: 16px; - opacity: 0.7; - transition: opacity 0.2s; - padding: 0; - display: flex; - align-items: center; - justify-content: center; - - - } @@ -119,13 +108,11 @@ let conversationHistory = []; function formatMarkdown(text) { - // 处理换行符 text = text.replace(/\n/g, '
'); - // 简单Markdown格式化 - text = text.replace(/\*\*(.*?)\*\*/g, '$1'); // 加粗 - text = text.replace(/\*(.*?)\*/g, '$1'); // 斜体 - text = text.replace(/`(.*?)`/g, '$1'); // 代码 - text = text.replace(/\[(.*?)\]\((.*?)\)/g, '$1'); // 链接 + text = text.replace(/\*\*(.*?)\*\*/g, '$1'); + text = text.replace(/\*(.*?)\*/g, '$1'); + text = text.replace(/`(.*?)`/g, '$1'); + text = text.replace(/\[(.*?)\]\((.*?)\)/g, '$1'); return text; } @@ -138,29 +125,26 @@ return; } - // 添加用户消息 const userMessageDiv = document.createElement('div'); userMessageDiv.className = 'message user-message'; userMessageDiv.innerHTML = `
${message}
- `; messageContainer.appendChild(userMessageDiv); try { - // 添加当前消息到对话历史 - conversationHistory.push({ role: 'user', content: message }); + conversationHistory.push({ role: 'user', content: message }); - const response = await fetch('/api/chat', { - method: 'POST', - headers: { - - }, - body: JSON.stringify({ - message, - history: conversationHistory - }) - }); + const response = await fetch('/api/chat', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + message, + history: conversationHistory + }) + }); const data = await response.json(); if (data.status === 'success') { @@ -169,11 +153,9 @@ botMessageDiv.className = 'message bot-message'; botMessageDiv.innerHTML = `
${formattedText}
- `; messageContainer.appendChild(botMessageDiv); - // 添加AI回复到对话历史 conversationHistory.push({ role: 'assistant', content: data.response.output.text }); } else { const errorMessageDiv = document.createElement('div'); @@ -189,13 +171,10 @@ messageContainer.appendChild(errorMessageDiv); } - // 清空输入框 document.getElementById('messageInput').value = ''; - // 滚动到底部 messageContainer.scrollTop = messageContainer.scrollHeight; } - // 清空对话历史 function clearHistory() { conversationHistory = []; document.getElementById('messageContainer').innerHTML = ''; @@ -212,3 +191,5 @@ + +