Phase 0: 專案初始化 - 建立專案結構、環境設定與 LLM 服務模組
This commit is contained in:
50
app.py
Normal file
50
app.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
DIT_C 主程式入口
|
||||
"""
|
||||
|
||||
from flask import Flask, jsonify
|
||||
from config import Config
|
||||
from models import db
|
||||
|
||||
|
||||
def create_app(config_class=Config):
|
||||
"""應用程式工廠"""
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config_class)
|
||||
|
||||
# 初始化擴展
|
||||
db.init_app(app)
|
||||
|
||||
# 註冊 Blueprint (後續擴展)
|
||||
# from routes.auth import auth_bp
|
||||
# from routes.admin import admin_bp
|
||||
# from routes.api import api_bp
|
||||
# app.register_blueprint(auth_bp)
|
||||
# app.register_blueprint(admin_bp)
|
||||
# app.register_blueprint(api_bp)
|
||||
|
||||
# 健康檢查端點
|
||||
@app.route('/health')
|
||||
def health_check():
|
||||
return jsonify({"status": "ok", "message": "DIT_C is running"})
|
||||
|
||||
# 測試 LLM 連線
|
||||
@app.route('/test-llm')
|
||||
def test_llm():
|
||||
from services.llm_service import llm_service, LLMServiceError
|
||||
try:
|
||||
models = llm_service.get_available_models()
|
||||
return jsonify({
|
||||
"status": "ok",
|
||||
"available_models": models,
|
||||
"default_model": Config.OLLAMA_DEFAULT_MODEL
|
||||
})
|
||||
except LLMServiceError as e:
|
||||
return jsonify({"status": "error", "message": str(e)}), 500
|
||||
|
||||
return app
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = create_app()
|
||||
app.run(host='0.0.0.0', port=5000, debug=Config.DEBUG)
|
||||
Reference in New Issue
Block a user