Files
ai_academy/internal/models/providers/litellm.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

128 lines
5.3 KiB
Go

// Package providers registers a self-hosted LiteLLM proxy
// (https://github.com/BerriAI/litellm).
//
// Facts (https://docs.litellm.ai/docs/reasoning_content):
// - the proxy speaks plain OpenAI Chat Completions and translates
// `reasoning_effort` for every upstream it fronts, so the OpenAI
// thinking format is used and graded effort is supported. The documented
// vocabulary is minimal | low | medium | high | xhigh | max (mapped onto
// Anthropic budgets of 1024/1024/2048/4096/8192/16384), plus `none` to
// turn thinking off — which is why the vendor level map spells "off" as
// "none" and keeps xhigh and max enabled;
// - both `max_tokens` and `max_completion_tokens` are listed as supported
// input params (https://docs.litellm.ai/docs/completion/input) with no
// stated preference, so the protocol default max_completion_tokens
// stands;
// - the default base URL is a placeholder the operator must replace; its
// hostname contains "litellm" so DetectByURL recognises catalog rows,
// while loopback URLs stay generic (they are SSRF-blocked unless
// whitelisted). The proxy's own default is port 4000, and both
// /v1/chat/completions and /chat/completions are documented;
// - the catalog ships no models: deployments name their own routes.
//
// Unverified: `chat_template_kwargs` is not named in the LiteLLM docs. It
// should reach a vLLM/SGLang upstream under the general rule that "LiteLLM
// treats any non-openai param as a provider-specific param, and passes it to
// the provider in the request body", but a proxy configured with
// allowed_openai_params may drop it, so operators fronting open-weight
// models may need thinking_control=chat_template_kwargs plus that allowlist.
package providers
import (
_ "embed"
"academy/internal/models"
"academy/internal/models/api"
"academy/internal/types"
)
//go:embed assets/litellm.svg
var litellmIcon []byte
// LitellmID is the provider identifier stored on model rows.
const LitellmID = "litellm"
// LitellmBaseURL is a placeholder the operator replaces with a reachable proxy.
const LitellmBaseURL = "http://your_litellm_proxy/v1"
// LitellmRerankBaseURL is the proxy root. LiteLLM documents rerank at /rerank
// rather than /v1/rerank, so it does not hang off the chat base URL.
const LitellmRerankBaseURL = "http://your_litellm_proxy"
func newLitellmProvider() *Definition {
return &Definition{
ID: LitellmID,
Name: "LiteLLM",
Names: map[string]string{"zh-CN": "LiteLLM"},
Description: "Self-hosted LiteLLM proxy: one OpenAI-compatible endpoint to 100+ ",
Descriptions: map[string]string{"zh-CN": "自建 LiteLLM 代理:一个 OpenAI 兼容入口对接 100+ 模型服务。"},
Website: "https://docs.litellm.ai",
Icon: litellmIcon,
API: api.APIOpenAICompletions,
Order: 41,
RequiresAuth: true,
Auth: AuthBearer,
URLPatterns: []string{"litellm"},
DefaultBaseURLs: map[types.ModelType]string{
types.ModelTypeKnowledgeQA: LitellmBaseURL,
types.ModelTypeEmbedding: LitellmBaseURL,
types.ModelTypeRerank: LitellmRerankBaseURL,
types.ModelTypeVLLM: LitellmBaseURL,
},
ModelTypes: []types.ModelType{
types.ModelTypeKnowledgeQA,
types.ModelTypeEmbedding,
types.ModelTypeRerank,
types.ModelTypeVLLM,
types.ModelTypeASR,
},
ExtraFields: []ExtraField{{
Key: models.ExtraScoreScale,
Label: "Rerank score scale",
Labels: map[string]string{"zh-CN": "Rerank 分数标度"},
Type: "select",
Options: []ExtraFieldOption{
{
Label: "Unbounded score (Qwen3-Reranker class)",
Labels: map[string]string{"zh-CN": "无界分数(Qwen3-Reranker 一类)"},
Value: "logit",
},
{
Label: "0..1 relevance (BGE class)",
Labels: map[string]string{"zh-CN": "0~1 相关度(BGE 一类)"},
Value: "probability",
},
},
Placeholder: "match the reranker actually deployed behind this endpoint",
Placeholders: map[string]string{"zh-CN": "按这个端点后面实际部署的重排模型选择"},
// A gateway serves whatever reranker was deployed behind it, and
// the two families disagree. The vendor default follows the
// documentation; the operator knows which model is actually there.
Required: false,
ModelTypes: []types.ModelType{types.ModelTypeRerank},
}},
Compat: VendorCompat{
// Transcriptions keeps the baseline: the proxy serves the OpenAI
// /audio/transcriptions route for whichever upstream it is
// configured with (https://docs.litellm.ai/docs/audio_transcription).
Embeddings: api.EmbeddingsCompat{
// https://docs.litellm.ai/docs/embedding/supported_embedding:
// model, input, user, dimensions, encoding_format; anything else
// is forwarded to the upstream as a provider-specific kwarg.
SendEncodingFormat: api.Ptr(true),
DimensionsField: api.Ptr("dimensions"),
},
OpenAICompletions: api.OpenAICompletionsCompat{
ThinkingFormat: api.Ptr(api.ThinkingFormatOpenAI),
SupportsReasoningEffort: api.Ptr(true),
},
},
// LiteLLM documents the whole ladder plus "none" as the off switch.
ThinkingLevels: api.ThinkingLevelMap{
api.ReasoningOff: api.StringPtr("none"),
api.ReasoningXHigh: api.StringPtr("xhigh"),
api.ReasoningMax: api.StringPtr("max"),
},
}
}