Files
ai_academy/internal/models/providers/academycloud.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 the Academy managed model service.
//
// unverified: this is a first-party endpoint with no published API
// reference — https://weknora.weixin.qq.com/docs documents the Academy
// product, not the model gateway's wire protocol. Every fact below is taken
// from this repository's own clients rather than from vendor documentation,
// and is cited accordingly:
// - one host serves chat, embedding, rerank and VLM. Chat completions and
// VLM live at /api/v1/chat/completions rather than the OpenAI default
// path (internal/models/vlm/academycloud.go), embeddings at
// /api/v1/embeddings (internal/models/embedding/academycloud.go) and
// rerank at /api/v1/rerank (internal/models/rerank/academycloud.go).
// Only the chat path goes through the Endpoint hook; the other three
// clients build their own URLs;
// - requests are signed with the tenant's AppID / AppSecret through
// modelutils.Sign (internal/models/utils/signer.go), which sends
// X-APPID, X-API-Key, X-Request-ID, X-Timestamp, X-Nonce and an
// X-Signature that is the MD5 of the RFC3986-encoded, key-sorted
// parameter string including the MD5 of the body. There is no bearer
// key, hence the AuthSigned style and a fresh request id per call;
// - credentials are provisioned through the dedicated initialization
// endpoint (internal/handler/academycloud.go), so Validate performs no
// key check here;
// - the model names the product provisions are chat, embedding, rerank and
// vlm (frontend/src/utils/academyCloudModels.ts). models.json is left
// empty on purpose: no context window, output cap or price is published
// for them, and the embedding dimension is probed at runtime through
// GET /api/v1/models/academycloud/status.
//
// unverified: SupportsMultiContent is kept false so chat messages are
// flattened to plain text, but nothing documents that restriction and the
// VLM client posts image_url parts to the very same /api/v1/chat/completions
// path, so it may only apply to the chat model. The value is left as-is
// because the transport test pins it.
//
// unverified: PromptCacheAccounting is kept false; the gateway is not
// documented to report prompt-cache counters, and none have been observed.
package providers
import (
_ "embed"
"net/http"
"strings"
"academy/internal/models/api"
modelutils "academy/internal/models/utils"
"academy/internal/types"
"github.com/google/uuid"
)
//go:embed assets/academycloud.svg
var academyCloudIcon []byte
// AcademyCloudID is the provider identifier stored on model rows.
const AcademyCloudID = "academycloud"
// AcademyCloudBaseURL is the single service entry point; per-capability paths are
// appended by the Endpoint hook and the embedding / rerank clients.
const AcademyCloudBaseURL = "https://weknora.weixin.qq.com"
func newAcademyCloudProvider() *Definition {
return &Definition{
ID: AcademyCloudID,
Name: "Academy Cloud",
Names: map[string]string{"zh-CN": "Academy 云服务"},
Description: "Academy managed models: chat, embedding, rerank, vlm",
Descriptions: map[string]string{"zh-CN": "Academy云服务,模型:chat, embedding, rerank, vlm"},
Website: AcademyCloudBaseURL,
Icon: academyCloudIcon,
API: api.APIOpenAICompletions,
Order: 1,
RequiresAuth: true,
Auth: AuthSigned,
URLPatterns: []string{"weknora.weixin.qq.com"},
DefaultBaseURLs: map[types.ModelType]string{
types.ModelTypeKnowledgeQA: AcademyCloudBaseURL,
types.ModelTypeEmbedding: AcademyCloudBaseURL,
types.ModelTypeRerank: AcademyCloudBaseURL,
types.ModelTypeVLLM: AcademyCloudBaseURL,
},
ModelTypes: []types.ModelType{
types.ModelTypeKnowledgeQA,
types.ModelTypeEmbedding,
types.ModelTypeRerank,
types.ModelTypeVLLM,
},
Compat: VendorCompat{
Embeddings: api.EmbeddingsCompat{
// The OpenAI body on the service's own path, signed like the
// rest of it.
Path: api.Ptr("/api/v1/embeddings"),
DimensionsField: api.Ptr("dimensions"),
RequestTimeout: api.Ptr(60),
},
Rerank: api.RerankCompat{
Path: api.Ptr("/api/v1/rerank"),
// The only rerank vendor that has ever had a client deadline
// here. Without it a hung endpoint holds the retrieval stage
// for as long as the caller's context allows.
RequestTimeout: api.Ptr(60),
},
OpenAICompletions: api.OpenAICompletionsCompat{
SupportsMultiContent: api.Ptr(false),
PromptCacheAccounting: api.Ptr(false),
},
},
Signer: func(creds api.Credentials) api.AuthFunc {
return func(req *http.Request, body []byte) {
headers := modelutils.Sign(creds.AppID, creds.AppSecret, uuid.NewString(), string(body))
for k, v := range headers {
req.Header.Set(k, v)
}
}
},
Endpoint: func(r EndpointRequest) (string, map[string]string) {
switch r.ModelType {
case types.ModelTypeEmbedding, types.ModelTypeRerank, types.ModelTypeASR:
// Those clients build their own paths; fall back.
return "", nil
}
return strings.TrimRight(r.BaseURL, "/") + "/api/v1/chat/completions", nil
},
// AppID / AppSecret are written by the dedicated initialization
// endpoint; only structural checks happen there.
Validate: func(_ *Config) error { return nil },
}
}