diff --git a/internal/gateway/kimi_schema.go b/internal/gateway/kimi_schema.go index 46eb5390b..a4a25a17a 100644 --- a/internal/gateway/kimi_schema.go +++ b/internal/gateway/kimi_schema.go @@ -196,18 +196,21 @@ func valuesType(vals []gjson.Result) string { // kimiLockedSampling is body without temperature and top_p when the model's // server locks them to one value: since kimi-k2.5 every kimi-kX.Y on both -// Kimi platforms (Moonshot's API and a Kimi Code membership's), and Kimi -// Code's own kimi-for-coding and k3*. A client that sends its own -// defaults — VS Code Copilot's chat sends temperature 0.1 and top_p 1 — is -// refused 400 "invalid temperature: only 1 is allowed for this model" -// before any token is read (a K2.5/K2.6 with thinking off takes only 0.6), -// and the whole request fails. Left out, the server fills in the value the -// model and mode want, so no number is written here. Models that take a -// range — moonshot-v1-*, kimi-k2-0905-preview, kimi-k2-thinking, -// kimi-latest — keep what the user set, as does anyone not served by -// Moonshot. +// Kimi platforms (Moonshot's API and a Kimi Code membership's), Kimi +// Code's own kimi-for-coding and k3*, and the same models on Volcengine +// Ark, whose coding plan serves kimi-kX.Y behind hosts the preset's plans +// and a provider added by hand both reach (#4495: 400 "Volcengine Ark: +// `temperature` only 1 is allowed for this model"). A client that sends +// its own defaults — VS Code Copilot's chat sends temperature 0.1 and +// top_p 1 — is refused 400 "invalid temperature: only 1 is allowed for +// this model" before any token is read (a K2.5/K2.6 with thinking off +// takes only 0.6), and the whole request fails. Left out, the server +// fills in the value the model and mode want, so no number is written +// here. Models that take a range — moonshot-v1-*, kimi-k2-0905-preview, +// kimi-k2-thinking, kimi-latest — keep what the user set, as does anyone +// not served by Moonshot or Ark. func kimiLockedSampling(p provider.Provider, to provider.Protocol, body []byte) []byte { - if !isKimi(p, to) { + if !isKimi(p, to) && !isArk(p) { return body } if !kimiLockedSamplingModel(gjson.GetBytes(body, "model").String()) { diff --git a/internal/gateway/kimi_schema_test.go b/internal/gateway/kimi_schema_test.go index 56cb91864..74c2ba861 100644 --- a/internal/gateway/kimi_schema_test.go +++ b/internal/gateway/kimi_schema_test.go @@ -192,8 +192,14 @@ func TestKimiLockedSampling(t *testing.T) { } moonshot.ID, moonshot.Key = "moonshot", "k" moonshot.Models = []string{"moonshot-v1-8k", "kimi-k2.5", "kimi-k2.6", "kimi-k2-0905-preview", "kimi-k2-thinking", "moonshotai/kimi-k2.6"} + volc, err := provider.FromPreset("volcengine") + if err != nil { + t.Fatal(err) + } + volc.ID, volc.Key, volc.Models = "volc", "k", []string{"kimi-k3.1-pro", "kimi-k2.8-preview", "doubao-seed-2.1-pro"} + arkpay := provider.Provider{ID: "arkpay", Name: "Ark pay", Key: "k", Chat: "https://ark.ap-southeast.volces.com/api/v3", Models: []string{"kimi-k3"}} other := provider.Provider{ID: "other", Name: "Other", Key: "k", Chat: "https://other.test/v1", Models: []string{"m"}} - for _, p := range []provider.Provider{kimi, moonshot, other} { + for _, p := range []provider.Provider{kimi, moonshot, volc, arkpay, other} { if err := provider.Save(p); err != nil { t.Fatal(err) } @@ -314,6 +320,43 @@ func TestKimiLockedSampling(t *testing.T) { t.Errorf("kimi-k2-thinking's temperature was not kept: %s", got.body) } }) + // #4495: Volcengine Ark locks the same models' sampling the same way + // ("Volcengine Ark: `temperature` only 1 is allowed for this model"), + // at its coding plan and — an Ark host being an Ark host — wherever + // else its Kimi models are served. + t.Run("volcengine's coding plan drops the fields", func(t *testing.T) { + got := post(t, "/v1/chat/completions", `{"model":"volc/kimi-k3.1-pro","messages":[{"role":"user","content":"hi"}],"temperature":0.6,"top_p":0.95}`) + if got.host != "ark.cn-beijing.volces.com" { + t.Fatalf("the request went to %s", got.host) + } + if gjson.Get(got.body, "temperature").Exists() || gjson.Get(got.body, "top_p").Exists() { + t.Errorf("Ark was sent the sampling fields: %s", got.body) + } + }) + t.Run("volcengine's anthropic endpoint drops the fields", func(t *testing.T) { + got := post(t, "/v1/messages", `{"model":"volc/kimi-k3.1-pro","messages":[{"role":"user","content":"hi"}],"temperature":0.6,"top_p":0.95,"max_tokens":5}`) + if got.host != "ark.cn-beijing.volces.com" { + t.Fatalf("the request went to %s", got.host) + } + if gjson.Get(got.body, "temperature").Exists() || gjson.Get(got.body, "top_p").Exists() { + t.Errorf("Ark was sent the sampling fields: %s", got.body) + } + }) + t.Run("volcengine keeps the fields for a model its server doesn't lock", func(t *testing.T) { + got := post(t, "/v1/chat/completions", `{"model":"volc/doubao-seed-2.1-pro","messages":[{"role":"user","content":"hi"}],"temperature":0.6,"top_p":0.95}`) + if !strings.Contains(got.body, `"temperature":0.6`) { + t.Errorf("doubao was not sent its temperature: %s", got.body) + } + }) + t.Run("a provider added by hand on an Ark host drops the fields", func(t *testing.T) { + got := post(t, "/v1/chat/completions", `{"model":"arkpay/kimi-k3","messages":[{"role":"user","content":"hi"}],"temperature":0.6,"top_p":0.95}`) + if got.host != "ark.ap-southeast.volces.com" { + t.Fatalf("the request went to %s", got.host) + } + if gjson.Get(got.body, "temperature").Exists() || gjson.Get(got.body, "top_p").Exists() { + t.Errorf("Ark was sent the sampling fields: %s", got.body) + } + }) t.Run("another provider is sent the body as it was", func(t *testing.T) { got := post(t, "/v1/chat/completions", `{"model":"other/m","messages":[{"role":"user","content":"hi"}],"temperature":0.1,"top_p":1}`) if !strings.Contains(got.body, `"temperature":0.1,"top_p":1`) {