Initial commit: skills library
- 70 skills with code and documentation - Add .gitignore (ignore __pycache__, output/, temp/, venv/) - Clean up test intermediates and caches
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
添加新账号
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
ACCOUNTS_FILE = os.path.join(os.path.dirname(__file__), "../references/accounts.md")
|
||||
|
||||
|
||||
def add_aliyun_account(key, label=None):
|
||||
"""添加阿里云账号"""
|
||||
if not label:
|
||||
# 自动生成标签
|
||||
with open(ACCOUNTS_FILE, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
count = content.count("| 账号") - 1 # 减去表头
|
||||
label = f"账号{count + 1}"
|
||||
|
||||
# 读取现有内容
|
||||
with open(ACCOUNTS_FILE, "r", encoding="utf-8") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# 找到表格最后一行
|
||||
insert_idx = len(lines)
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith("| ---"):
|
||||
insert_idx = i
|
||||
break
|
||||
|
||||
new_row = f"| {label} | {key} | | 正常 |\n"
|
||||
lines.insert(insert_idx, new_row)
|
||||
|
||||
with open(ACCOUNTS_FILE, "w", encoding="utf-8") as f:
|
||||
f.writelines(lines)
|
||||
|
||||
print(f"已添加阿里云账号: {label}")
|
||||
print(f"API Key: {key[:10]}...")
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("用法:")
|
||||
print(" python add_account.py aliyun <api_key> [标签]")
|
||||
print(" python add_account.py openrouter <api_key>")
|
||||
print(" python add_account.py groq <api_key>")
|
||||
print(" python add_account.py deepseek <api_key>")
|
||||
return
|
||||
|
||||
platform = sys.argv[1]
|
||||
api_key = sys.argv[2] if len(sys.argv) > 2 else input("请输入API Key: ")
|
||||
label = sys.argv[3] if len(sys.argv) > 3 else None
|
||||
|
||||
if platform == "aliyun":
|
||||
add_aliyun_account(api_key, label)
|
||||
else:
|
||||
print(f"暂不支持平台: {platform}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
查询各平台API额度
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def check_aliyun_quota():
|
||||
"""查询阿里云百炼额度"""
|
||||
api_key = os.getenv("DASHSCOPE_API_KEY")
|
||||
if not api_key:
|
||||
return {"error": "DASHSCOPE_API_KEY not set"}
|
||||
|
||||
try:
|
||||
url = "https://dashscope.aliyuncs.com/compatible-mode/v1/usage"
|
||||
headers = {"Authorization": f"Bearer {api_key}"}
|
||||
resp = requests.get(url, headers=headers, timeout=10)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
return {"provider": "aliyun", "status": "ok", "data": data}
|
||||
else:
|
||||
return {"provider": "aliyun", "error": resp.text}
|
||||
except Exception as e:
|
||||
return {"provider": "aliyun", "error": str(e)}
|
||||
|
||||
|
||||
def check_openrouter_quota():
|
||||
"""查询OpenRouter额度"""
|
||||
api_key = os.getenv("OPENROUTER_API_KEY")
|
||||
if not api_key:
|
||||
return {"error": "OPENROUTER_API_KEY not set"}
|
||||
|
||||
try:
|
||||
url = "https://openrouter.ai/api/v1/credits"
|
||||
headers = {"Authorization": f"Bearer {api_key}"}
|
||||
resp = requests.get(url, headers=headers, timeout=10)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
return {"provider": "openrouter", "status": "ok", "data": data}
|
||||
else:
|
||||
return {"provider": "openrouter", "error": resp.text}
|
||||
except Exception as e:
|
||||
return {"provider": "openrouter", "error": str(e)}
|
||||
|
||||
|
||||
def check_deepseek_quota():
|
||||
"""查询DeepSeek额度"""
|
||||
api_key = os.getenv("DEEPSEEK_API_KEY")
|
||||
if not api_key:
|
||||
return {"error": "DEEPSEEK_API_KEY not set"}
|
||||
|
||||
try:
|
||||
url = "https://api.deepseek.com/v1/remaining_quota"
|
||||
headers = {"Authorization": f"Bearer {api_key}"}
|
||||
resp = requests.get(url, headers=headers, timeout=10)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
return {"provider": "deepseek", "status": "ok", "data": data}
|
||||
else:
|
||||
return {"provider": "deepseek", "error": resp.text}
|
||||
except Exception as e:
|
||||
return {"provider": "deepseek", "error": str(e)}
|
||||
|
||||
|
||||
def check_groq_quota():
|
||||
"""查询Groq额度(通过OpenAI兼容接口)"""
|
||||
api_key = os.getenv("GROQ_API_KEY")
|
||||
if not api_key:
|
||||
return {"error": "GROQ_API_KEY not set"}
|
||||
|
||||
try:
|
||||
# Groq没有直接的额度查询API,返回提示
|
||||
return {
|
||||
"provider": "groq",
|
||||
"status": "no_api",
|
||||
"message": "Groq无公开额度查询API,请登录Groq Dashboard查看",
|
||||
}
|
||||
except Exception as e:
|
||||
return {"provider": "groq", "error": str(e)}
|
||||
|
||||
|
||||
def main():
|
||||
print(f"=== LLM额度查询 - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} ===\n")
|
||||
|
||||
results = []
|
||||
|
||||
# 阿里云
|
||||
print("[1/4] 阿里云百炼...")
|
||||
result = check_aliyun_quota()
|
||||
results.append(result)
|
||||
if "error" in result:
|
||||
print(f" 错误: {result.get('error')}")
|
||||
else:
|
||||
print(f" OK")
|
||||
|
||||
# OpenRouter
|
||||
print("[2/4] OpenRouter...")
|
||||
result = check_openrouter_quota()
|
||||
results.append(result)
|
||||
if "error" in result:
|
||||
print(f" 错误: {result.get('error')}")
|
||||
elif result.get("status") == "no_api":
|
||||
print(f" {result.get('message')}")
|
||||
else:
|
||||
print(f" OK")
|
||||
|
||||
# DeepSeek
|
||||
print("[3/4] DeepSeek...")
|
||||
result = check_deepseek_quota()
|
||||
results.append(result)
|
||||
if "error" in result:
|
||||
print(f" 错误: {result.get('error')}")
|
||||
else:
|
||||
print(f" OK")
|
||||
|
||||
# Groq
|
||||
print("[4/4] Groq...")
|
||||
result = check_groq_quota()
|
||||
results.append(result)
|
||||
if "error" in result:
|
||||
print(f" 错误: {result.get('error')}")
|
||||
else:
|
||||
print(f" {result.get('message', 'OK')}")
|
||||
|
||||
print("\n=== 详细结果 ===")
|
||||
print(json.dumps(results, indent=2, ensure_ascii=False))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Example script - delete if not needed."""
|
||||
|
||||
print("Hello from skill!")
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
初始化LLM Hub配置
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def create_env_example():
|
||||
content = """# LLM Hub 环境变量配置
|
||||
# 复制此文件为 .env 并填入实际API Key
|
||||
|
||||
# 阿里云百炼 (https://dashscope.console.aliyun.com/)
|
||||
DASHSCOPE_API_KEY=sk-your-key-here
|
||||
|
||||
# OpenRouter (https://openrouter.ai/)
|
||||
OPENROUTER_API_KEY=sk-your-key-here
|
||||
|
||||
# Groq (https://console.groq.com/)
|
||||
GROQ_API_KEY=gsk_your-key-here
|
||||
|
||||
# DeepSeek (https://platform.deepseek.com/)
|
||||
DEEPSEEK_API_KEY=sk-your-key-here
|
||||
|
||||
# 硅基流动 (https://siliconflow.cn/)
|
||||
SILICONFLOW_API_KEY=sk-your-key-here
|
||||
|
||||
# 阶跃星辰 (https://platform.stepfun.com/)
|
||||
STEPFUN_API_KEY=sk-your-key-here
|
||||
"""
|
||||
|
||||
env_file = os.path.join(os.path.dirname(__file__), "../.env.example")
|
||||
with open(env_file, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
print(f"已变量示例文件创建环境: {env_file}")
|
||||
print("请复制为 .env 并填入实际的API Key")
|
||||
|
||||
|
||||
def main():
|
||||
print("=== LLM Hub 配置初始化 ===\n")
|
||||
|
||||
# 创建环境变量示例
|
||||
create_env_example()
|
||||
|
||||
print("\n=== 下一步 ===")
|
||||
print("1. 复制 .env.example 为 .env")
|
||||
print("2. 填入各平台的API Key")
|
||||
print("3. 运行 python scripts/check_quotas.py 查询额度")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/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()
|
||||
Reference in New Issue
Block a user