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,20 @@
|
||||
# LLM Hub 环境变量配置
|
||||
# 复制此文件为 .env 并填入实际API Key
|
||||
|
||||
# 火山方舟 (https://console.volcengine.com/ark)
|
||||
VOLCENGINE_API_KEY=your_volcengine_api_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
|
||||
@@ -0,0 +1,290 @@
|
||||
---
|
||||
name: llm-hub
|
||||
description: LLM资源中心。管理多供应商大模型API、本地Ollama模型、额度监控、自动切换配置。当用户需要查询模型、切换API、管理额度时使用此技能。
|
||||
---
|
||||
|
||||
# LLM Hub - 大模型资源管理中心
|
||||
|
||||
## 概述
|
||||
|
||||
此技能用于统一管理多供应商的大模型API和本地Ollama模型,提供额度监控、自动切换、账号管理等功能。
|
||||
|
||||
## 触发场景
|
||||
|
||||
当用户提及以下内容时激活此技能:
|
||||
- "查一下额度"、"看看各平台剩余"
|
||||
- "切换模型"、"换一个API"
|
||||
- "本地有什么模型"、"Ollama在跑什么"
|
||||
- "帮我注册"、"申请新账号"
|
||||
- "API配置"、"模型对比"
|
||||
|
||||
## 功能模块
|
||||
|
||||
### 1. 模型发现
|
||||
|
||||
#### 本地模型(Ollama)
|
||||
|
||||
```bash
|
||||
# 列出本地模型
|
||||
ollama list
|
||||
|
||||
# 查看运行状态
|
||||
ollama ps
|
||||
|
||||
# 拉取模型
|
||||
ollama pull <model-name>
|
||||
```
|
||||
|
||||
**配置文件位置**: `%USERPROFILE%\.ollama\models`
|
||||
|
||||
#### 云端模型
|
||||
|
||||
支持的供应商和免费额度:
|
||||
|
||||
| 供应商 | 特点 | 推荐模型 | API端点 |
|
||||
|-------|------|---------|---------|
|
||||
| **火山方舟** | Coding Plan ¥7.9/月 | doubao-seed-2.0-pro, doubao-seed-code (视觉) | `https://ark.cn-beijing.volces.com/api/coding/v3` |
|
||||
| DeepSeek | 价格屠夫 | deepseek-v3, deepseek-coder | `https://api.deepseek.com/v1` |
|
||||
| Groq | 免费额度充足 | mixtral-8x7b-32768, llama-3.1-70b | `https://api.groq.com/openai/v1` |
|
||||
| OpenRouter | 有限免费 | deepseek/deepseek-r1 | `https://openrouter.ai/api/v1` |
|
||||
|
||||
### 2. 额度监控
|
||||
|
||||
#### 检查各平台额度
|
||||
|
||||
```bash
|
||||
# 火山方舟 - 通过API查询
|
||||
curl -H "Authorization: Bearer $VOLCENGINE_API_KEY" \
|
||||
https://ark.cn-beijing.volces.com/api/coding/v3/usage
|
||||
|
||||
# OpenRouter - 通过API查询
|
||||
curl -H "Authorization: Bearer $OPENROUTER_API_KEY" \
|
||||
https://openrouter.ai/api/v1/credits
|
||||
|
||||
# DeepSeek - 通过API查询
|
||||
curl -H "Authorization: Bearer $DEEPSEEK_API_KEY" \
|
||||
https://api.deepseek.com/v1/remaining_quota
|
||||
```
|
||||
|
||||
#### 额度记录
|
||||
|
||||
每次使用后更新 `references/usage_records.md`,记录:
|
||||
- 日期时间
|
||||
- 供应商
|
||||
- 模型
|
||||
- 消耗token数
|
||||
- 剩余额度
|
||||
|
||||
### 3. 自动切换配置
|
||||
|
||||
#### 配置文件
|
||||
|
||||
配置文件: `config/providers.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"providers": [
|
||||
{
|
||||
"name": "volcengine",
|
||||
"priority": 1,
|
||||
"api_key_env": "VOLCENGINE_API_KEY",
|
||||
"base_url": "https://ark.cn-beijing.volces.com/api/coding/v3",
|
||||
"models": ["doubao-seed-2.0-pro", "doubao-seed-code"],
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "deepseek",
|
||||
"priority": 2,
|
||||
"api_key_env": "DEEPSEEK_API_KEY",
|
||||
"base_url": "https://api.deepseek.com/v1",
|
||||
"models": ["deepseek-v3", "deepseek-coder"],
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "groq",
|
||||
"priority": 3,
|
||||
"api_key_env": "GROQ_API_KEY",
|
||||
"base_url": "https://api.groq.com/openai/v1",
|
||||
"models": ["mixtral-8x7b-32768", "llama-3.1-70b"],
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"current_provider": "volcengine",
|
||||
"fallback_enabled": true
|
||||
}
|
||||
```
|
||||
|
||||
#### 切换逻辑
|
||||
|
||||
当检测到当前供应商额度不足或API报错时:
|
||||
1. 自动切换到下一个可用的provider
|
||||
2. 记录切换事件到日志
|
||||
3. 发送通知(可选)
|
||||
|
||||
### 4. 账号管理
|
||||
|
||||
#### 火山方舟账号
|
||||
|
||||
当前使用火山方舟 Coding Plan:
|
||||
|
||||
```bash
|
||||
VOLCENGINE_API_KEY=b0359bed-09f2-49e2-a53c-32ba057412e3
|
||||
```
|
||||
|
||||
**账号记录**: `references/accounts.md`
|
||||
|
||||
| 账号 | API Key | 套餐 | 状态 |
|
||||
|-----|---------|------|------|
|
||||
| Coding Plan | b0359...412e3 | ¥7.9/月 | 正常 |
|
||||
|
||||
#### 新账号注册指引
|
||||
|
||||
**火山方舟 Coding Plan**:
|
||||
1. 访问 https://console.volcengine.com/ark/
|
||||
2. 注册/登录账号
|
||||
3. 开通 Coding Plan 套餐
|
||||
4. 获取 API Key
|
||||
|
||||
### 5. 模型对比
|
||||
|
||||
| 场景 | 推荐模型 | 原因 |
|
||||
|-----|---------|------|
|
||||
| 代码生成 | doubao-seed-code, deepseek-coder | 专用模型 |
|
||||
| 中文对话 | doubao-pro, deepseek-v3 | 中文优化 |
|
||||
| 快速响应 | groq+mixtral, llama-3.1-8b | 延迟低 |
|
||||
| 多模态/视觉 | doubao-seed-code | Coding Plan唯一视觉模型 |
|
||||
| 免费优先 | groq, openrouter免费层 | 成本最低 |
|
||||
|
||||
## 使用流程
|
||||
|
||||
### 首次使用
|
||||
|
||||
1. 配置环境变量(见下方)
|
||||
2. 运行 `python scripts/init_config.py` 初始化配置
|
||||
3. 查询各平台额度:`python scripts/check_quotas.py`
|
||||
|
||||
### 日常使用
|
||||
|
||||
1. 查询额度: "帮我查一下各平台额度"
|
||||
2. 切换模型: "切换到Groq"
|
||||
3. 添加账号: "添加一个新的阿里云账号"
|
||||
|
||||
## 环境变量配置
|
||||
|
||||
在系统环境变量或 `.env` 文件中配置:
|
||||
|
||||
```bash
|
||||
# 火山方舟 (Coding Plan)
|
||||
VOLCENGINE_API_KEY=b0359bed-09f2-49e2-a53c-32ba057412e3
|
||||
|
||||
# DeepSeek
|
||||
DEEPSEEK_API_KEY=sk-xxx
|
||||
|
||||
# Groq
|
||||
GROQ_API_KEY=gsk_xxx
|
||||
|
||||
# OpenRouter
|
||||
OPENROUTER_API_KEY=sk-xxx
|
||||
```
|
||||
|
||||
## OpenCode 配置
|
||||
|
||||
要在 OpenCode 的 /models 中添加火山方舟:
|
||||
|
||||
### 方法1:使用环境变量
|
||||
|
||||
```bash
|
||||
# 在系统环境变量中设置
|
||||
VOLCENGINE_API_KEY=b0359bed-09f2-49e2-a53c-32ba057412e3
|
||||
```
|
||||
|
||||
### 方法2:配置文件(推荐)
|
||||
|
||||
火山方舟已在 `~/.config/opencode/config.json` 中配置:
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"provider": {
|
||||
"volcengine": {
|
||||
"npm": "@ai-sdk/openai-compatible",
|
||||
"options": {
|
||||
"baseURL": "https://ark.cn-beijing.volces.com/api/coding/v3",
|
||||
"apiKey": "b0359bed-09f2-49e2-a53c-32ba057412e3"
|
||||
},
|
||||
"models": {
|
||||
"doubao-seed-2.0-pro": {},
|
||||
"doubao-seed-2.0-code": {},
|
||||
"doubao-seed-2.0-lite": {},
|
||||
"doubao-seed-code": {}
|
||||
}
|
||||
},
|
||||
"deepseek": {
|
||||
"npm": "@ai-sdk/openai-compatible",
|
||||
"options": {
|
||||
"baseURL": "https://api.deepseek.com/v1"
|
||||
},
|
||||
"models": {
|
||||
"deepseek-chat": {},
|
||||
"deepseek-coder": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 配置步骤
|
||||
|
||||
1. 创建/编辑配置文件:
|
||||
```bash
|
||||
# Windows
|
||||
notepad %USERPROFILE%\.config\opencode\opencode.json
|
||||
|
||||
# 或用 VS Code
|
||||
code %USERPROFILE%\.config\opencode\opencode.json
|
||||
```
|
||||
|
||||
2. 添加 API Key(两种方式):
|
||||
|
||||
**方式A:写到配置里(不安全)**
|
||||
```jsonc
|
||||
{
|
||||
"provider": {
|
||||
"dashscope": {
|
||||
"options": {
|
||||
"apiKey": "sk-56a8e427c3f7403a90e2cf22f1b9d842"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**方式B:用环境变量(推荐)**
|
||||
- 设置系统环境变量 `DASHSCOPE_API_KEY`
|
||||
|
||||
3. 重启 OpenCode,运行 `/models` 刷新模型列表
|
||||
|
||||
## 文件结构
|
||||
|
||||
```
|
||||
llm-hub/
|
||||
├── SKILL.md # 本文件
|
||||
├── config/
|
||||
│ └── providers.json # 供应商配置
|
||||
├── references/
|
||||
│ ├── usage_records.md # 使用记录
|
||||
│ ├── accounts.md # 账号管理
|
||||
│ └── model_comparison.md # 模型对比表
|
||||
├── scripts/
|
||||
│ ├── check_quotas.py # 查询额度
|
||||
│ ├── switch_provider.py # 切换供应商
|
||||
│ ├── add_account.py # 添加账号
|
||||
│ └── init_config.py # 初始化配置
|
||||
└── .env.example # 环境变量示例
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **火山方舟 Coding Plan** - 主要供应商,视觉模型用 `doubao-seed-code`
|
||||
2. API Key 安全 - 不要提交到Git
|
||||
3. 额度告警 - 低于10%时提醒切换
|
||||
4. 轮询机制 - 多个账号时轮换使用
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"providers": [
|
||||
{
|
||||
"name": "volcengine",
|
||||
"priority": 1,
|
||||
"api_key_env": "VOLCENGINE_API_KEY",
|
||||
"base_url": "https://ark.cn-beijing.volces.com/api/coding/v3",
|
||||
"models": ["doubao-seed-2.0-pro", "doubao-seed-2.0-code", "doubao-seed-2.0-lite", "doubao-seed-code", "doubao-1.5-pro-32k-250115", "doubao-1.5-lite-32k-250115"],
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "deepseek",
|
||||
"priority": 2,
|
||||
"api_key_env": "DEEPSEEK_API_KEY",
|
||||
"base_url": "https://api.deepseek.com/v1",
|
||||
"models": ["deepseek-chat", "deepseek-coder", "deepseek-v3", "deepseek-v3.2"],
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "groq",
|
||||
"priority": 3,
|
||||
"api_key_env": "GROQ_API_KEY",
|
||||
"base_url": "https://api.groq.com/openai/v1",
|
||||
"models": ["mixtral-8x7b-32768", "llama-3.1-70b-versatile", "llama-3.1-8b-instant"],
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "openrouter",
|
||||
"priority": 4,
|
||||
"api_key_env": "OPENROUTER_API_KEY",
|
||||
"base_url": "https://openrouter.ai/api/v1",
|
||||
"models": ["deepseek/deepseek-r1", "mistralai/mistral-small-3", "meta-llama/llama-3.1-8b-instruct"],
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"current_provider": "volcengine",
|
||||
"fallback_enabled": true,
|
||||
"alert_threshold": 0.1,
|
||||
"vision_config": {
|
||||
"default_model": "doubao-seed-code",
|
||||
"note": "火山方舟Coding Plan唯一支持的视觉模型",
|
||||
"auto_switch": false,
|
||||
"ask_before_switch": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
# 账号管理
|
||||
|
||||
## 阿里云百炼账号
|
||||
|
||||
| 账号 | API Key | 剩余额度 | 状态 | 备注 |
|
||||
|-----|---------|---------|------|------|
|
||||
| 账号1 | sk-xxx | | | |
|
||||
| 账号2 | sk-xxx | | | |
|
||||
| 账号3 | sk-xxx | | | |
|
||||
|
||||
## 其他平台
|
||||
|
||||
| 平台 | API Key | 状态 |
|
||||
|-----|---------|------|
|
||||
| OpenRouter | sk-xxx | |
|
||||
| Groq | gsk_xxx | |
|
||||
| DeepSeek | sk-xxx | |
|
||||
| 硅基流动 | sk-xxx | |
|
||||
| 阶跃星辰 | sk-xxx | |
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Example Reference
|
||||
|
||||
This is an example reference file. Delete if not needed.
|
||||
@@ -0,0 +1,49 @@
|
||||
# 模型对比表
|
||||
|
||||
## 按场景推荐
|
||||
|
||||
| 场景 | 推荐模型 | 供应商 | 特点 | 适合 |
|
||||
|-----|---------|-------|------|------|
|
||||
| 👑 **最新最强** | qwen3.5-plus | 阿里云 | 2026.2.16发布,超GPT-5.2,0.8元/百万Token | 所有场景 |
|
||||
| 👑 **最新最强** | qwen3.5-397b-a17b | 阿里云 | 3970亿参数激活170亿,旗舰开源 | 复杂推理 |
|
||||
| 代码生成 | deepseek-coder | DeepSeek | 专用代码模型 | 编程任务 |
|
||||
| 代码生成 | codeqwen:7b | Ollama | 本地可跑 | 低延迟 |
|
||||
| 中文对话 | qwen-plus | 阿里云 | 中文优化 | 日常对话 |
|
||||
| 中文对话 | deepseek-chat | DeepSeek | 性价比高 | 日常对话 |
|
||||
| 快速响应 | mixtral-8x7b-32768 | Groq | 超低延迟 | 实时交互 |
|
||||
| 快速响应 | llama-3.1-8b-instruct | Ollama | 本地快速 | 离线使用 |
|
||||
| 多模态 | qwen2.5vl:7b | Ollama | 看图理解 | 图像分析 |
|
||||
| 多模态 | llama3.2-vision:11b | Ollama | 图像理解强 | 复杂图像 |
|
||||
| 免费优先 | mistral-small-3 | OpenRouter | 免费层可用 | 预算有限 |
|
||||
| 推理能力 | deepseek-r1 | OpenRouter | 推理能力强 | 复杂逻辑 |
|
||||
|
||||
## Qwen3.5 新模型(2026.2.16发布)
|
||||
|
||||
| 模型 | 参数 | 激活参数 | 特点 | API价格 |
|
||||
|-----|------|---------|------|-------|
|
||||
| qwen3.5-plus | 3970亿 | 170亿 | 最强开源,超越GPT-5.2 | 0.8元/百万Token |
|
||||
| qwen3.5-397b-a17b | 3970亿 | 170亿 | 旗舰开源,支持多模态 | 参考plus |
|
||||
|
||||
**新用户福利**: 阿里云百炼新用户送 **100万免费Token**
|
||||
|
||||
## 按硬件选择
|
||||
|
||||
### 16GB VRAM (RTX 3080)
|
||||
|
||||
| 模型 | 量化 | 内存需求 | 速度 |
|
||||
|-----|-----|---------|------|
|
||||
| llama3.1:8b | Q4_K_M | ~5GB | 快 |
|
||||
| qwen2.5:7b | Q4_K_M | ~4.5GB | 快 |
|
||||
| mistral:7b | Q4_K_M | ~4.5GB | 极快 |
|
||||
| phi4:14b | Q4_K_M | ~9GB | 中 |
|
||||
| llama3.2-vision:11b | Q4_K_M | ~7GB | 中 |
|
||||
| qwen2.5vl:7b | Q4_K_M | ~5GB | 中 |
|
||||
|
||||
### 24GB+ VRAM
|
||||
|
||||
| 模型 | 量化 | 内存需求 | 速度 |
|
||||
|-----|-----|---------|------|
|
||||
| qwen2.5:14b | Q4_K_M | ~9GB | 中 |
|
||||
| deepseek-r1:8b | Q4_K_M | ~5GB | 快 |
|
||||
| llama3.3:70b | Q4_K_M | ~40GB | 慢 |
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# 使用记录
|
||||
|
||||
## 2026-02-17
|
||||
|
||||
| 时间 | 供应商 | 模型 | 消耗Token | 剩余额度 |
|
||||
|-----|-------|------|----------|---------|
|
||||
| | | | | |
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# llm-hub - dependencies
|
||||
requests>=0.0.1
|
||||
@@ -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