04db423416
- 70 skills with code and documentation - Add .gitignore (ignore __pycache__, output/, temp/, venv/) - Clean up test intermediates and caches
74 lines
1.7 KiB
Python
74 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
切换供应商
|
|
"""
|
|
|
|
import os
|
|
import json
|
|
import sys
|
|
|
|
CONFIG_FILE = os.path.join(os.path.dirname(__file__), "../config/providers.json")
|
|
|
|
|
|
def load_config():
|
|
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
def save_config(config):
|
|
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
|
json.dump(config, f, indent=2, ensure_ascii=False)
|
|
|
|
|
|
def list_providers(config):
|
|
print("可用供应商:")
|
|
for p in config["providers"]:
|
|
status = "✓" if p["enabled"] else "✗"
|
|
current = " ← 当前" if p["name"] == config.get("current_provider") else ""
|
|
print(f" {status} {p['name']}{current}")
|
|
print(f" 模型: {', '.join(p['models'])}")
|
|
|
|
|
|
def switch_provider(target_name):
|
|
config = load_config()
|
|
|
|
# 查找目标供应商
|
|
target = None
|
|
for p in config["providers"]:
|
|
if p["name"] == target_name:
|
|
target = p
|
|
break
|
|
|
|
if not target:
|
|
print(f"错误: 未找到供应商 '{target_name}'")
|
|
return
|
|
|
|
if not target["enabled"]:
|
|
print(f"警告: 供应商 '{target_name}' 当前未启用")
|
|
|
|
config["current_provider"] = target_name
|
|
save_config(config)
|
|
print(f"已切换到供应商: {target_name}")
|
|
|
|
|
|
def main():
|
|
config = load_config()
|
|
|
|
if len(sys.argv) < 2:
|
|
list_providers(config)
|
|
print("\n用法:")
|
|
print(" python switch_provider.py list # 列出所有供应商")
|
|
print(" python switch_provider.py <provider> # 切换到指定供应商")
|
|
return
|
|
|
|
action = sys.argv[1]
|
|
|
|
if action == "list":
|
|
list_providers(config)
|
|
else:
|
|
switch_provider(action)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|