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)}")