From 12653bbd9452a98bd9f3a88f9bc2638ed41cedc1 Mon Sep 17 00:00:00 2001 From: Fisherlen Date: Sat, 21 Mar 2026 20:43:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=89=8D=E7=AB=AF=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AF=B9=E8=AF=9D=E6=A1=86?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=B9=B6=E6=94=B9=E8=BF=9BUI=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=EF=BC=9B=E6=B7=BB=E5=8A=A0API=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChatBot/templates/index.html | 205 +++++++++++++++++++++++++++++++---- ChatBot/test_api.py | 17 +++ 2 files changed, 203 insertions(+), 19 deletions(-) create mode 100644 ChatBot/test_api.py diff --git a/ChatBot/templates/index.html b/ChatBot/templates/index.html index 8f67d22..a3e213e 100644 --- a/ChatBot/templates/index.html +++ b/ChatBot/templates/index.html @@ -1,29 +1,196 @@ - + - Chatbot + + 智能聊天机器人 -
- {% for item in history %} - {% if item.role == 'user' %} -

User: {{ item.content }}

- {% elif item.role == 'system' %} -

Bot: {{ item.content }}

- {% endif %} - {% endfor %} -
-
-
-
- -
+
+
+ 🤖 智能聊天助手 +
+
+ {% for item in history %} + {% if item.role == 'user' %} +
+ +
{{ item.content }}
+
+ {% elif item.role == 'assistant' %} +
+ 助手 +
{{ item.content }}
+
+ {% endif %} + {% endfor %} +
+
+
+ + +
+
+
+ + - \ No newline at end of file + diff --git a/ChatBot/test_api.py b/ChatBot/test_api.py new file mode 100644 index 0000000..a407ec6 --- /dev/null +++ b/ChatBot/test_api.py @@ -0,0 +1,17 @@ +from openai import OpenAI +from dotenv import load_dotenv, find_dotenv + +# 加载 .env 到环境变量 +_ = load_dotenv(find_dotenv()) + +client = OpenAI() + +try: + response = client.chat.completions.create( + messages=[{"role": "user", "content": "Hello, this is a test!"}], + model="gpt-4", + ) + print("API测试成功!") + print(f"响应: {response.choices[0].message.content}") +except Exception as e: + print(f"API测试失败: {str(e)}")