#!/usr/bin/env python3 """ 配置加载工具 从 skill config/settings.json 读取配置 """ import os import json from pathlib import Path def load_config(config_path=None): """加载配置,从配置文件读取""" if config_path is None: config_path = Path(__file__).parent.parent / "config" / "settings.json" if config_path.exists(): with open(config_path, "r", encoding="utf-8") as f: config = json.load(f) print(f"[OK] Load config from {config_path}") return config print(f"[ERROR] Config file not found: {config_path}") return None def get_api_key(config_path=None): """获取API Key""" config = load_config(config_path) if config: return config.get("image_api", {}).get("key") return None if __name__ == "__main__": import sys # 支持命令行指定配置文件路径 config_path = sys.argv[1] if len(sys.argv) > 1 else None key = get_api_key(config_path) if key: print(f"API Key: {key[:10]}...{key[-10:]}") else: print("未找到API Key")