From 64f58ab5ecc5eddf2ae417ca0431d84d8f7dc5c3 Mon Sep 17 00:00:00 2001 From: Kakune55 Date: Tue, 16 Jan 2024 12:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF=E4=BA=A4?= =?UTF-8?q?=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- templates/index.html | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 43be818..e1bcfd7 100644 --- a/main.py +++ b/main.py @@ -49,7 +49,7 @@ def post_data(): code , output , tokenUsed = gpt4Turbo.service(userRequest['prompt']) db.reduce_value(userRequest['userkey'], tokenUsed) - log.newLog(flask.request.headers.get('X-Forwarded-For'), tokenUsed, userRequest["model"], userRequest['userkey']) + log.newLog(flask.request.headers.get('X-Forwarded-For').split(",")[0], tokenUsed, userRequest["model"], userRequest['userkey']) return {"code":code,"output":output,"surplus":surplusToken} diff --git a/templates/index.html b/templates/index.html index 4ac2ed2..7fd1bc9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -36,6 +36,7 @@ +
@@ -112,6 +113,7 @@ document.getElementById("loadingico").style.display = ""; const userMessage = userInput.value; // 获取用户输入的消息 appendMessage('你', userMessage); // 在聊天界面中添加用户消息 + chatMessages.scrollTop = chatMessages.scrollHeight; //自动滚动 userInput.value = ''; // 清空输入框 // 立即禁用发送按钮 @@ -241,6 +243,7 @@ userhs0 = message; boths0 = data["output"]; loading = false; + chatMessages.scrollTop = chatMessages.scrollHeight; //自动滚动 document.getElementById("loadingico").style.display = "none"; // 可以根据返回的数据执行相应的操作 }) @@ -249,6 +252,19 @@ alert('请求出错:', error); }); } + + document.addEventListener('DOMContentLoaded', function () { //回车发送消息功能 + function handleKey(event) { + if (event.keyCode === 13) { + // 在这里执行你希望回车键触发的操作 + sendButton.click(); // 模拟按钮点击 + } + } + // 绑定事件到输入框 + userInput.addEventListener('keypress', handleKey); + }); + +