Files
ai_academy/internal/models/providers/siliconflow.go
T
runny 9058149576
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
refactor: 项目更名 WeKnora → Academy
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名)
- 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块)
- docreader proto 描述符采用等长替换,保持序列化字节布局有效
- Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像
- 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
2026-11-13 20:52:51 +08:00

101 lines
4.2 KiB
Go

// Package providers registers SiliconFlow (SiliconCloud), an
// OpenAI-compatible gateway to open-weight models.
//
// Facts (https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions):
// - output cap is `max_tokens`; `max_completion_tokens` is not documented;
// - `enable_thinking` "在推理模式与非推理模式之间切换。该字段适用于大多数推理
// 模型", sent as a top-level boolean, together with `thinking_budget`
// (128 <= value <= 32768). Both work in streaming and non-streaming
// mode and neither is mandatory, so the switch is only sent when the
// caller asks for one;
// - `reasoning_effort` accepts "high" | "max" and "该字段适用于
// Pro/deepseek-ai/DeepSeek-V4、deepseek-ai/DeepSeek-V4-Flash 以及
// Pro/zai-org/GLM-5.2", so every other reasoning entry disables it;
// - usage reports `prompt_cache_hit_tokens` / `prompt_cache_miss_tokens`,
// hence prompt_cache_accounting;
// - response_format accepts text (default), json_object and json_schema;
// - temperature is [0, 2] (default 0.7) and top_p up to 1, unrestricted;
// - one base URL serves chat, embedding, rerank, VLM and ASR, and the only
// credential is a bearer API key, so there are no ExtraFields.
//
// unverified: the reference documents `tools` but not `tool_choice`,
// `parallel_tool_calls` or `stream_options`, so the protocol defaults for
// those three stand untested;
// unverified: `prompt_cache_key` and Anthropic-style cache_control are not
// documented, so neither is sent;
// unverified: the embedding / rerank / ASR entries (ids, dimensions) come
// from the SiliconCloud model pages, and the per-model context windows,
// output caps and prices in models.json are not restated in the API
// reference.
package providers
import (
_ "embed"
"academy/internal/models/api"
"academy/internal/types"
)
//go:embed assets/siliconflow.svg
var siliconflowIcon []byte
// SiliconflowID is the provider identifier stored on model rows.
const SiliconflowID = "siliconflow"
// SiliconflowBaseURL serves every model type.
const SiliconflowBaseURL = "https://api.siliconflow.cn/v1"
func newSiliconflowProvider() *Definition {
return &Definition{
ID: SiliconflowID,
Name: "SiliconFlow",
Names: map[string]string{"zh-CN": "硅基流动 SiliconFlow"},
Description: "deepseek-ai/DeepSeek-V4-Pro, zai-org/GLM-5.2, Qwen/Qwen3.5-397B-A17B, BAAI/bge-m3, etc.",
Website: "https://cloud.siliconflow.cn",
Icon: siliconflowIcon,
API: api.APIOpenAICompletions,
Order: 14,
RequiresAuth: true,
Auth: AuthBearer,
URLPatterns: []string{"siliconflow.cn"},
DefaultBaseURLs: map[types.ModelType]string{
types.ModelTypeKnowledgeQA: SiliconflowBaseURL,
types.ModelTypeEmbedding: SiliconflowBaseURL,
types.ModelTypeRerank: SiliconflowBaseURL,
types.ModelTypeVLLM: SiliconflowBaseURL,
types.ModelTypeASR: SiliconflowBaseURL,
},
ModelTypes: []types.ModelType{
types.ModelTypeKnowledgeQA,
types.ModelTypeEmbedding,
types.ModelTypeRerank,
types.ModelTypeVLLM,
types.ModelTypeASR,
},
Compat: VendorCompat{
Transcriptions: api.TranscriptionsCompat{
// https://api-docs.siliconflow.cn/docs/api/audio-transcriptions-post:
// file and model only — no response_format — and a file of
// "时长不超过 1 小时,文件大小不超过 50MB".
MaxFileBytes: api.Ptr(50 << 20),
},
Embeddings: api.EmbeddingsCompat{
// https://api-docs.siliconflow.cn/docs/api/embeddings-post: model,
// input, encoding_format, and dimensions "仅 Qwen/Qwen3 系列支持"
// — the bge-m3 entry turns it off. The input array schema says
// "当前最大数组大小为 32" (maxItems 32).
SendEncodingFormat: api.Ptr(true),
DimensionsField: api.Ptr("dimensions"),
MaxBatchSize: api.Ptr(32),
},
OpenAICompletions: api.OpenAICompletionsCompat{
MaxTokensField: api.Ptr("max_tokens"),
ThinkingFormat: api.Ptr(api.ThinkingFormatEnableThinking),
ThinkingBudgetField: api.Ptr("thinking_budget"),
SupportsReasoningEffort: api.Ptr(true),
PromptCacheAccounting: api.Ptr(true),
},
},
}
}