Spaces:
Paused
Paused
| from fastapi import FastAPI | |
| from controllers import chat_controller, test_controller, admin_controller, health_controller | |
| from core import service_config, session_store, llm_models | |
| from llm_model import LLMModel | |
| from intent_utils import background_training | |
| from log import log | |
| import os | |
| import warnings | |
| # FutureWarning'leri sustur | |
| warnings.simplefilter(action='ignore', category=FutureWarning) | |
| app = FastAPI() | |
| app.include_router(health_controller.router) | |
| app.include_router(chat_controller.router) | |
| app.include_router(test_controller.router) | |
| app.include_router(admin_controller.router) | |
| BASE_PROJECTS_DIR = "/data/projects" | |
| def load_project(project_name, config, project_path): | |
| llm_config = config.get_project_llm_config(project_name) | |
| model_instance = LLMModel() | |
| model_instance.setup(config, llm_config, project_path) | |
| # Intent modeli path | |
| intent_model_path = os.path.join(project_path, "intent", "trained_model") | |
| # Eğer intent modeli klasörü yoksa → eğitim başlat | |
| if not os.path.exists(intent_model_path) or not os.path.isfile(os.path.join(intent_model_path, "config.json")): | |
| log(f"🛠 Intent modeli bulunamadı, eğitim başlatılıyor: {intent_model_path}") | |
| intents = config.get_project_intents(project_name) | |
| os.makedirs(intent_model_path, exist_ok=True) | |
| background_training( | |
| project_name, | |
| intents, | |
| llm_config["intent_model_id"], | |
| intent_model_path, | |
| llm_config["train_confidence_treshold"] | |
| ) | |
| # Eğitim sonrası intent modelini yükle | |
| if os.path.exists(intent_model_path) and os.path.isfile(os.path.join(intent_model_path, "config.json")): | |
| model_instance.load_intent_model(intent_model_path) | |
| else: | |
| log(f"⚠️ Intent modeli yüklenemedi: {intent_model_path}, yükleme atlandı.") | |
| return model_instance | |
| log("🌐 Servis başlatılıyor...") | |
| service_config.load(is_reload=False) | |
| for project_name in service_config.projects: | |
| project_path = os.path.join(BASE_PROJECTS_DIR, project_name) | |
| os.makedirs(project_path, exist_ok=True) | |
| os.makedirs(os.path.join(project_path, "llm", "base_model"), exist_ok=True) | |
| os.makedirs(os.path.join(project_path, "llm", "fine_tune"), exist_ok=True) | |
| os.makedirs(os.path.join(project_path, "intent", "trained_model"), exist_ok=True) | |
| model_instance = load_project(project_name, service_config, project_path) | |
| llm_models[project_name] = model_instance | |
| log(f"✅ '{project_name}' için tüm modeller yüklenip belleğe alındı.") | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) | |