Drop ZHANLU_MODELS and ZHANLU_DEFAULT_MODEL config

Model list is always fetched live from the gateway model-info endpoint, so the
static fallback list was dead config with stale IDs (GLM-4.7 vs zhanlu/glm-4.7).
Default to zhanlu/auto when the request omits model.
This commit is contained in:
2026-08-05 15:06:38 +08:00
parent 7d8a5b6f74
commit 81076e1170
4 changed files with 4 additions and 26 deletions
+2 -6
View File
@@ -50,8 +50,6 @@ ZHANLU_LISTEN_ADDR=:8080
ZHANLU_CREDENTIALS_FILE=/opt/zhanlu-proxy/credentials.json ZHANLU_CREDENTIALS_FILE=/opt/zhanlu-proxy/credentials.json
ZHANLU_MOBILE_LOGIN_BASE_URL=https://ecloud.10086.cn ZHANLU_MOBILE_LOGIN_BASE_URL=https://ecloud.10086.cn
ZHANLU_MOBILE_MODEL_BASE_URL=https://ecloud.10086.cn/api/query/aigateway ZHANLU_MOBILE_MODEL_BASE_URL=https://ecloud.10086.cn/api/query/aigateway
ZHANLU_MODELS=GLM-4.7,MiniMax-M2.5
ZHANLU_DEFAULT_MODEL=GLM-4.7
ZHANLU_UPSTREAM_TIMEOUT=300s ZHANLU_UPSTREAM_TIMEOUT=300s
ZHANLU_LOGIN_PASSWORD=change-this-login-password ZHANLU_LOGIN_PASSWORD=change-this-login-password
OPENAI_COMPAT_API_KEY=change-this-local-secret OPENAI_COMPAT_API_KEY=change-this-local-secret
@@ -152,7 +150,7 @@ curl http://127.0.0.1:8080/v1/models
```powershell ```powershell
curl http://127.0.0.1:8080/v1/chat/completions ` curl http://127.0.0.1:8080/v1/chat/completions `
-H "Content-Type: application/json" ` -H "Content-Type: application/json" `
-d '{"model":"GLM-4.7","messages":[{"role":"user","content":"hello"}],"stream":false}' -d '{"model":"zhanlu/auto","messages":[{"role":"user","content":"hello"}],"stream":false}'
``` ```
流式: 流式:
@@ -160,7 +158,7 @@ curl http://127.0.0.1:8080/v1/chat/completions `
```powershell ```powershell
curl -N http://127.0.0.1:8080/v1/chat/completions ` curl -N http://127.0.0.1:8080/v1/chat/completions `
-H "Content-Type: application/json" ` -H "Content-Type: application/json" `
-d '{"model":"GLM-4.7","messages":[{"role":"user","content":"hello"}],"stream":true}' -d '{"model":"zhanlu/auto","messages":[{"role":"user","content":"hello"}],"stream":true}'
``` ```
### 工具调用 ### 工具调用
@@ -198,8 +196,6 @@ curl http://127.0.0.1:8080/v1/models `
| `ZHANLU_PHONE_PUBLIC_KEY_PEM` | 插件内置手机号登录公钥 | 手机号验证码登录加密手机号和一次性 secret 使用的 RSA 公钥,通常不需要设置 | | `ZHANLU_PHONE_PUBLIC_KEY_PEM` | 插件内置手机号登录公钥 | 手机号验证码登录加密手机号和一次性 secret 使用的 RSA 公钥,通常不需要设置 |
| `ZHANLU_APIKEY_AUTH_SM2_PRIVATE_KEY` | 插件内置 SM2 私钥 | 换取模型 API Key 时 `X-Auth-Signature` 使用的 SM2 私钥,通常不需要设置 | | `ZHANLU_APIKEY_AUTH_SM2_PRIVATE_KEY` | 插件内置 SM2 私钥 | 换取模型 API Key 时 `X-Auth-Signature` 使用的 SM2 私钥,通常不需要设置 |
| `ZHANLU_PLUGIN_VERSION` | `1.4.2` | 请求头 `plugin_version` | | `ZHANLU_PLUGIN_VERSION` | `1.4.2` | 请求头 `plugin_version` |
| `ZHANLU_MODELS` | `GLM-4.7,MiniMax-M2.5` | `/v1/models` 回退模型列表;有凭据时优先从模型网关拉取 |
| `ZHANLU_DEFAULT_MODEL` | `GLM-4.7` | 请求未传 `model` 时使用的默认模型 |
| `ZHANLU_UPSTREAM_TIMEOUT` | `300s` | 上游请求超时 | | `ZHANLU_UPSTREAM_TIMEOUT` | `300s` | 上游请求超时 |
| `ZHANLU_STREAM_IDLE_TIMEOUT` | `300s` | 预留的流式空闲超时配置 | | `ZHANLU_STREAM_IDLE_TIMEOUT` | `300s` | 预留的流式空闲超时配置 |
| `ZHANLU_LOGIN_PASSWORD` | 空 | `/login` 管理页面密码;设置后登录成功跳转到 `/admin/login` 管理湛卢凭据 | | `ZHANLU_LOGIN_PASSWORD` | 空 | `/login` 管理页面密码;设置后登录成功跳转到 `/admin/login` 管理湛卢凭据 |
-16
View File
@@ -21,8 +21,6 @@ type Config struct {
PublicKeyPEM string PublicKeyPEM string
PhonePublicKeyPEM string PhonePublicKeyPEM string
SM2PrivateKey string SM2PrivateKey string
Models []string
DefaultModel string
OpenAIAPIKey string OpenAIAPIKey string
LoginPassword string LoginPassword string
PluginVersion string PluginVersion string
@@ -45,7 +43,6 @@ func Load() (Config, error) {
PublicKeyPEM: getenv("ZHANLU_PUBLIC_KEY_PEM", defaultPublicKeyPEM), PublicKeyPEM: getenv("ZHANLU_PUBLIC_KEY_PEM", defaultPublicKeyPEM),
PhonePublicKeyPEM: getenv("ZHANLU_PHONE_PUBLIC_KEY_PEM", defaultPhonePublicKeyPEM), PhonePublicKeyPEM: getenv("ZHANLU_PHONE_PUBLIC_KEY_PEM", defaultPhonePublicKeyPEM),
SM2PrivateKey: getenv("ZHANLU_APIKEY_AUTH_SM2_PRIVATE_KEY", defaultSM2PrivateKey), SM2PrivateKey: getenv("ZHANLU_APIKEY_AUTH_SM2_PRIVATE_KEY", defaultSM2PrivateKey),
DefaultModel: getenv("ZHANLU_DEFAULT_MODEL", "GLM-4.7"),
OpenAIAPIKey: os.Getenv("OPENAI_COMPAT_API_KEY"), OpenAIAPIKey: os.Getenv("OPENAI_COMPAT_API_KEY"),
LoginPassword: os.Getenv("ZHANLU_LOGIN_PASSWORD"), LoginPassword: os.Getenv("ZHANLU_LOGIN_PASSWORD"),
PluginVersion: getenv("ZHANLU_PLUGIN_VERSION", "1.4.2"), PluginVersion: getenv("ZHANLU_PLUGIN_VERSION", "1.4.2"),
@@ -53,7 +50,6 @@ func Load() (Config, error) {
StreamIdleTimout: durationEnv("ZHANLU_STREAM_IDLE_TIMEOUT", 300*time.Second), StreamIdleTimout: durationEnv("ZHANLU_STREAM_IDLE_TIMEOUT", 300*time.Second),
Debug: strings.EqualFold(os.Getenv("ZHANLU_DEBUG"), "true"), Debug: strings.EqualFold(os.Getenv("ZHANLU_DEBUG"), "true"),
} }
cfg.Models = splitCSV(getenv("ZHANLU_MODELS", "GLM-4.7,MiniMax-M2.5"))
cfg.Credentials = auth.Credentials{ cfg.Credentials = auth.Credentials{
AccessKey: os.Getenv("ZHANLU_ACCESS_KEY"), AccessKey: os.Getenv("ZHANLU_ACCESS_KEY"),
SecretKey: os.Getenv("ZHANLU_SECRET_KEY"), SecretKey: os.Getenv("ZHANLU_SECRET_KEY"),
@@ -76,18 +72,6 @@ func getenv(key, fallback string) string {
return fallback return fallback
} }
func splitCSV(s string) []string {
parts := strings.Split(s, ",")
out := make([]string, 0, len(parts))
for _, p := range parts {
p = strings.TrimSpace(p)
if p != "" {
out = append(out, p)
}
}
return out
}
func durationEnv(key string, fallback time.Duration) time.Duration { func durationEnv(key string, fallback time.Duration) time.Duration {
v := strings.TrimSpace(os.Getenv(key)) v := strings.TrimSpace(os.Getenv(key))
if v == "" { if v == "" {
+2 -2
View File
@@ -525,7 +525,7 @@ func (s *Server) exchangeSSOCode(w http.ResponseWriter, r *http.Request) {
} }
func (s *Server) models(w http.ResponseWriter, r *http.Request) { func (s *Server) models(w http.ResponseWriter, r *http.Request) {
modelIDs := s.cfg.Models modelIDs := []string{}
if creds, err := s.currentCredentials(); err == nil && creds.HasAPIKey() { if creds, err := s.currentCredentials(); err == nil && creds.HasAPIKey() {
if client, cerr := s.zhanluClient(); cerr == nil { if client, cerr := s.zhanluClient(); cerr == nil {
if fetched, merr := client.Models(r.Context(), creds.APIKey); merr == nil && len(fetched) > 0 { if fetched, merr := client.Models(r.Context(), creds.APIKey); merr == nil && len(fetched) > 0 {
@@ -552,7 +552,7 @@ func (s *Server) chatCompletions(w http.ResponseWriter, r *http.Request) {
return return
} }
if req.Model == "" { if req.Model == "" {
req.Model = s.cfg.DefaultModel req.Model = "zhanlu/auto"
} }
clientWantsStream := req.Stream clientWantsStream := req.Stream
req.Stream = true req.Stream = true
-2
View File
@@ -70,8 +70,6 @@ func setupTestServer(t *testing.T) (*httptest.Server, *httptest.Server, string)
PublicKeyPEM: defaultTestPublicKey, PublicKeyPEM: defaultTestPublicKey,
PhonePublicKeyPEM: defaultTestPublicKey, PhonePublicKeyPEM: defaultTestPublicKey,
SM2PrivateKey: testSM2Key, SM2PrivateKey: testSM2Key,
Models: []string{"GLM-4.7", "MiniMaxAI/MiniMax-M2.5"},
DefaultModel: "GLM-4.7",
PluginVersion: "1.4.2", PluginVersion: "1.4.2",
} }
h := New(cfg) h := New(cfg)