-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
26 lines (21 loc) · 978 Bytes
/
config.py
File metadata and controls
26 lines (21 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import json
import logging
def load_api_keys():
"""从节点目录下的 config.json 加载 API 密钥"""
gemini_key = None
siliconflow_key = None
try:
node_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(node_dir, 'config.json')
if os.path.exists(config_path):
with open(config_path, 'r', encoding='utf-8') as f:
config = json.load(f)
gemini_key = config.get("gemini_api_key") or config.get("GEMINI_API_KEY")
siliconflow_key = config.get("siliconflow_api_key") or config.get("SILICONFLOW_API_KEY")
else:
logging.warning("config.json not found in the node directory. Please create it from config.json.example.")
except Exception as e:
logging.error(f"Error loading API keys from config.json: {e}")
return gemini_key, siliconflow_key
GEMINI_API_KEY, SILICONFLOW_API_KEY = load_api_keys()