Delete app.py
Browse files
app.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
print(sys.path)
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
from flask import Flask, request, jsonify, render_template, send_from_directory
|
| 6 |
-
from flask_cors import CORS
|
| 7 |
-
import os
|
| 8 |
-
from llama3 import LlaMa3 # 导入您的 LlaMa3 类
|
| 9 |
-
|
| 10 |
-
app = Flask(__name__)
|
| 11 |
-
CORS(app)
|
| 12 |
-
|
| 13 |
-
# 实例化 LlaMa3 模型
|
| 14 |
-
llama3_model = LlaMa3()
|
| 15 |
-
|
| 16 |
-
@app.route('/')
|
| 17 |
-
def index():
|
| 18 |
-
# 返回 HTML 页面
|
| 19 |
-
return render_template('index.html')
|
| 20 |
-
|
| 21 |
-
@app.route('/chat', methods=['POST'])
|
| 22 |
-
def chat():
|
| 23 |
-
# 获取前端发送的用户消息
|
| 24 |
-
user_message = request.json.get('message', '')
|
| 25 |
-
|
| 26 |
-
if not user_message.strip():
|
| 27 |
-
return jsonify({"response": "请输入有效内容!"}), 400
|
| 28 |
-
|
| 29 |
-
try:
|
| 30 |
-
# 构造聊天上下文
|
| 31 |
-
messages = [{"role": "user", "content": user_message}]
|
| 32 |
-
|
| 33 |
-
# 调用 LlaMa3 的 chat 方法生成回复
|
| 34 |
-
ai_response = llama3_model.chat(messages)
|
| 35 |
-
|
| 36 |
-
# 返回 AI 的回复
|
| 37 |
-
return jsonify({"response": ai_response})
|
| 38 |
-
except Exception as e:
|
| 39 |
-
print(f"Error during llama3 call: {e}")
|
| 40 |
-
return jsonify({"response": "发生错误,请稍后重试!"}), 500
|
| 41 |
-
|
| 42 |
-
@app.route('/favicon.ico')
|
| 43 |
-
def favicon():
|
| 44 |
-
return send_from_directory(os.path.join(app.root_path, 'static'),
|
| 45 |
-
'favicon.ico', mimetype='image/vnd.microsoft.icon')
|
| 46 |
-
|
| 47 |
-
if __name__ == '__main__':
|
| 48 |
-
app.run(debug=True, host='127.0.0.1', port=5000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|