From 1077efbe201ea3f29517f5ce4a0cfc3b04c25d1d Mon Sep 17 00:00:00 2001 From: LittleMouse Date: Thu, 27 Mar 2025 19:12:54 +0800 Subject: [PATCH] [fix] Fix config.yaml PATH --- api_server.py | 4 +++- services/model_list.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api_server.py b/api_server.py index 642c60d..f123b65 100644 --- a/api_server.py +++ b/api_server.py @@ -38,7 +38,9 @@ limiter = Limiter(key_func=get_remote_address) class Config: def __init__(self): - with open("config/config.yaml") as f: + current_dir = os.path.dirname(os.path.abspath(__file__)) + config_path = os.path.join(current_dir, "config", "config.yaml") + with open(config_path) as f: self.data = yaml.safe_load(f) config = Config() diff --git a/services/model_list.py b/services/model_list.py index 2929a6e..ce5d299 100644 --- a/services/model_list.py +++ b/services/model_list.py @@ -1,3 +1,4 @@ +import os import logging import asyncio import yaml @@ -15,8 +16,17 @@ class GetModelList: try: if not self._sys_client: self._sys_client = SYSClient(host=self.host, port=self.port) + current_dir = os.path.dirname(os.path.abspath(__file__)) + parent_dir = os.path.dirname(current_dir) + config_path = os.path.join(parent_dir, "config", "config.yaml") - with open('config/config.yaml', 'r') as f: + with open(config_path, 'r') as f: + config = yaml.safe_load(f) + config['models'] = {} + with open(config_path, 'w') as f: + yaml.safe_dump(config, f, default_flow_style=False, sort_keys=False) + + with open(config_path, 'r') as f: config = yaml.safe_load(f) models_config = config.get('models', {}) model_list = await self._get_model_list() @@ -84,7 +94,7 @@ class GetModelList: models_config[mode] = new_entry config['models'] = models_config - with open('config/config.yaml', 'w') as f: + with open(config_path, 'w') as f: yaml.safe_dump(config, f, default_flow_style=False, sort_keys=False) except Exception as e: