Files
tokens-reef/docs/reports/CHINESE_MODELS_AUDIT.md
User 686454bf22
Some checks failed
CI / test (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
Security Scan / backend-security (push) Has been cancelled
Security Scan / frontend-security (push) Has been cancelled
docs: add project review and update development guide
- Add comprehensive PROJECT_REVIEW.md with development experience summary
- Update DEV_GUIDE.md with standardized conventions and best practices
- Move audit reports to docs/reports/ and update .gitignore
- Document Windows compatibility issues and solutions
- Add PR checklist and testing standards
2026-04-13 06:44:25 +08:00

289 lines
8.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Sub2API 国内模型支持审查报告
**审查日期**: 2026/04/12
**项目路径**: D:/project/sub2api
---
## 一、国内模型支持现状
### 1.1 已实现的国内模型支持
#### 前端模型白名单 (`frontend/src/composables/useModelWhitelist.ts`)
| 厂商 | 模型系列 | 状态 |
|------|----------|------|
| **智谱 GLM** | glm-4, glm-4v, glm-4-plus, glm-4-air, glm-4-long, glm-4-flash, glm-4.5, glm-4.6, glm-3-turbo, chatglm_*, cogview-3, cogvideo | ✅ 已添加 |
| **阿里通义** | qwen-turbo, qwen-plus, qwen-max, qwen-long, qwen2-*, qwen2.5-*, qwen3-*, qwq-32b | ✅ 已添加 |
| **DeepSeek** | deepseek-chat, deepseek-coder, deepseek-reasoner, deepseek-v3, deepseek-r1, deepseek-r1-distill-* | ✅ 已添加 |
| **月之暗面** | moonshot-v1-8k/32k/128k, kimi-latest | ✅ 已添加 |
| **字节豆包** | doubao-pro-*, doubao-lite-*, doubao-vision-*, doubao-1.5-* | ✅ 已添加 |
| **MiniMax** | abab6.5-chat, abab6.5s-chat, abab6-chat, abab5.5-chat | ✅ 已添加 |
| **百度文心** | ernie-4.0-*, ernie-3.5-*, ernie-speed-*, ernie-lite-*, ernie-tiny | ✅ 已添加 |
| **讯飞星火** | spark-desk, spark-lite, spark-pro, spark-max, spark-ultra | ✅ 已添加 |
| **腾讯混元** | hunyuan-lite, hunyuan-standard, hunyuan-pro, hunyuan-turbo, hunyuan-large, hunyuan-vision, hunyuan-code | ✅ 已添加 |
| **零一万物** | yi-large, yi-medium, yi-spark, yi-vision, yi-1.5-* | ✅ 已添加 |
#### 前端模型图标 (`frontend/src/components/common/ModelIcon.vue`)
| 厂商 | 图标支持 |
|------|----------|
| 阿里通义 (qwen) | ✅ |
| DeepSeek | ✅ |
| 月之暗面 (moonshot/kimi) | ✅ |
| MiniMax | ✅ |
| 智谱 GLM | ❌ 缺失 |
| 字节豆包 | ❌ 缺失 |
| 百度文心 | ❌ 缺失 |
| 讯飞星火 | ❌ 缺失 |
| 腾讯混元 | ❌ 缺失 |
| 零一万物 Yi | ❌ 缺失 |
#### 后端URL白名单 (`backend/internal/config/config.go`)
```go
viper.SetDefault("security.url_allowlist.upstream_hosts", []string{
"api.openai.com",
"api.anthropic.com",
"api.kimi.com", // ✅ 月之暗面
"open.bigmodel.cn", // ✅ 智谱
"api.minimaxi.com", // ✅ MiniMax
// ❌ 缺失: 阿里云、字节、百度、讯飞、腾讯、零一万物
})
```
#### 后端定价数据 (`backend/resources/model-pricing/model_prices_and_context_window.json`)
| 厂商 | 定价数据 |
|------|----------|
| DeepSeek | ✅ 已包含 (7处) |
| 其他国内模型 | ❌ **全部缺失** |
#### 后端计费服务 (`backend/internal/service/billing_service.go`)
```go
// initFallbackPricing() - 回退定价
// ❌ 完全缺失国内模型的回退定价
// getFallbackPricing() - 模型匹配
// ❌ 仅支持 Claude/Gemini/GPT无国内模型匹配逻辑
```
#### 后端Kimi兼容 (`backend/internal/service/gateway_service.go`)
```go
// ✅ 支持 Kimi 风格的 cached_tokens 响应处理
// 兼容 Kimi cached_tokens → cache_read_input_tokens
```
---
## 二、缺失功能清单
### 2.1 高优先级(影响核心功能)
| 问题 | 位置 | 影响 |
|------|------|------|
| **计费服务无国内模型定价** | `billing_service.go` | 国内模型请求**无法正确计费** |
| **定价数据缺失** | `model_prices_and_context_window.json` | 动态定价无法获取国内模型价格 |
| **回退定价缺失** | `billing_service.go:initFallbackPricing()` | 动态定价不可用时计费失败 |
### 2.2 中优先级(影响用户体验)
| 问题 | 位置 | 影响 |
|------|------|------|
| URL白名单不完整 | `config.go` | 部分国内API无法访问 |
| 模型图标缺失 | `ModelIcon.vue` | 部分模型无品牌图标 |
### 2.3 低优先级
| 问题 | 位置 | 影响 |
|------|------|------|
| 无国内模型特殊处理 | `gateway_service.go` | 部分模型可能有特殊响应格式 |
---
## 三、具体改进建议
### 3.1 计费服务改进 (`billing_service.go`)
**需要添加的回退定价**:
```go
// DeepSeek
s.fallbackPrices["deepseek-chat"] = &ModelPricing{
InputPricePerToken: 2.8e-7, // $0.28 per MTok
OutputPricePerToken: 4.2e-7, // $0.42 per MTok
CacheReadPricePerToken: 2.8e-8, // $0.028 per MTok
}
s.fallbackPrices["deepseek-reasoner"] = &ModelPricing{
InputPricePerToken: 2.8e-7,
OutputPricePerToken: 4.2e-7,
CacheReadPricePerToken: 2.8e-8,
}
// 通义千问
s.fallbackPrices["qwen-turbo"] = &ModelPricing{...}
s.fallbackPrices["qwen-plus"] = &ModelPricing{...}
s.fallbackPrices["qwen-max"] = &ModelPricing{...}
// 智谱 GLM
s.fallbackPrices["glm-4"] = &ModelPricing{...}
// ... 其他模型
```
**需要添加的匹配逻辑** (`getFallbackPricing`):
```go
// DeepSeek
if strings.Contains(modelLower, "deepseek") {
if strings.Contains(modelLower, "reasoner") || strings.Contains(modelLower, "r1") {
return s.fallbackPrices["deepseek-reasoner"]
}
return s.fallbackPrices["deepseek-chat"]
}
// 通义千问
if strings.Contains(modelLower, "qwen") || strings.Contains(modelLower, "qwq") {
if strings.Contains(modelLower, "max") {
return s.fallbackPrices["qwen-max"]
}
if strings.Contains(modelLower, "plus") {
return s.fallbackPrices["qwen-plus"]
}
return s.fallbackPrices["qwen-turbo"]
}
// 智谱 GLM
if strings.Contains(modelLower, "glm-") || strings.Contains(modelLower, "chatglm") {
return s.fallbackPrices["glm-4"]
}
// ... 其他厂商
```
### 3.2 定价数据补充 (`model_prices_and_context_window.json`)
需要添加以下模型的定价数据:
- qwen-turbo, qwen-plus, qwen-max, qwen-long, qwen2.5-*, qwen3-*
- glm-4, glm-4-plus, glm-4-air, glm-4-flash, glm-4.5, glm-4.6
- moonshot-v1-*, kimi-latest
- doubao-pro-*, doubao-lite-*, doubao-1.5-*
- abab6.5-chat, abab6.5s-chat
- ernie-4.0-*, ernie-3.5-*
- spark-desk-*, spark-*
- hunyuan-*
- yi-large, yi-medium, yi-*
### 3.3 URL白名单补充 (`config.go`)
```go
viper.SetDefault("security.url_allowlist.upstream_hosts", []string{
// 现有
"api.openai.com",
"api.anthropic.com",
"api.kimi.com",
"open.bigmodel.cn",
"api.minimaxi.com",
// 需要添加
"dashscope.aliyuncs.com", // 阿里云通义
"ark.cn-beijing.volces.com", // 字节豆包
"aip.baidubce.com", // 百度文心
"spark-api.xf-yun.com", // 讯飞星火
"hunyuan.tencentcloudapi.com", // 腾讯混元
"api.lingyiwanwu.com", // 零一万物
})
```
### 3.4 前端图标补充 (`ModelIcon.vue`)
```typescript
const providerIcons: Record<string, ProviderIcon> = {
// 现有
qwen: { ... },
deepseek: { ... },
moonshot: { ... },
minimax: { ... },
// 需要添加
zhipu: { /* 智谱图标 */ },
baidu: { /* 百度图标 */ },
spark: { /* 讯飞图标 */ },
hunyuan: { /* 腾讯图标 */ },
yi: { /* 零一万物图标 */ },
doubao: { /* 字节图标 */ },
}
// 模型匹配逻辑补充
if (modelLower.includes('glm') || modelLower.includes('chatglm')) return 'zhipu'
if (modelLower.includes('ernie')) return 'baidu'
if (modelLower.includes('spark')) return 'spark'
if (modelLower.includes('hunyuan')) return 'hunyuan'
if (modelLower.includes('yi-') || modelLower.includes('yi-large')) return 'yi'
if (modelLower.includes('doubao')) return 'doubao'
```
---
## 四、测试建议
### 4.1 计费测试
```go
// billing_service_test.go
func TestGetFallbackPricing_ChineseModels(t *testing.T) {
tests := []struct {
name string
model string
expectNilPricing bool
}{
{"deepseek chat", "deepseek-chat", false},
{"deepseek reasoner", "deepseek-reasoner", false},
{"deepseek r1", "deepseek-r1", false},
{"qwen max", "qwen-max", false},
{"qwen turbo", "qwen-turbo", false},
{"glm-4", "glm-4", false},
{"moonshot v1", "moonshot-v1-8k", false},
{"doubao pro", "doubao-pro-256k", false},
{"abab chat", "abab6.5-chat", false},
{"ernie 4.0", "ernie-4.0-8k", false},
{"spark max", "spark-max", false},
{"hunyuan pro", "hunyuan-pro", false},
{"yi large", "yi-large", false},
}
// ...
}
```
---
## 五、总结
### 国内模型支持完成度
| 模块 | 完成度 | 说明 |
|------|--------|------|
| 前端模型白名单 | 100% | 所有主流国内模型已添加 |
| 前端模型图标 | 40% | 仅4家厂商有图标 |
| 后端URL白名单 | 30% | 仅3家厂商在白名单 |
| 后端定价数据 | 10% | 仅DeepSeek有定价 |
| 后端计费服务 | 0% | **完全缺失** |
### 核心问题
**国内模型支持目前处于"前端可用、后端不可用"的状态**
1. ✅ 前端可以显示和选择国内模型
2. ❌ 后端无法正确计费(会导致计费失败或免费使用)
3. ❌ 部分国内API因URL白名单限制无法访问
### 建议优先级
1. **立即修复**:添加计费服务的国内模型定价支持
2. **尽快完成**:补充定价数据文件
3. **逐步完善**URL白名单、模型图标
---
**审查完成时间**: 2026/04/12