mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
fix(kimi): keep stripping the Codex none placeholder for K3.1
The previous Codex catalog advertised only "none" for k3.1-pro, so Codex clients that still hold it send reasoning.effort=none. Preserving none for K3.1 made those requests fail upstream with HTTP 400 (K3.1 cannot disable thinking) instead of running at the default effort as they do today. Keep the existing compatible-upstream rule on the Responses path: strip the none placeholder for K3.1 exactly like every other Kimi model. The new catalog no longer advertises none, so current clients are unaffected.
This commit is contained in:
1 parent
3313acad75
commit
fa375e60e1
2 files changed
+12
-21
No files matched your search
@@ -82,20 +82,11 @@ func shouldPreserveOpenAIResponsesNoneReasoningEffort(account *Account) bool {
|
||||
return baseURL == "" || isOfficialOpenAIModelsBaseURL(baseURL)
|
||||
}
|
||||
|
||||
// K3.1 treats none as an explicit unsupported request, not a catalog
|
||||
// placeholder. Preserve it after resolving aliases so upstream can reject it.
|
||||
func isKimiK31RequestModel(account *Account, model string) bool {
|
||||
if account != nil {
|
||||
model = account.GetMappedModel(model)
|
||||
}
|
||||
return isKimiK31Model(model)
|
||||
}
|
||||
|
||||
// Codex 0.149.0 needs a single advertised effort to directly select a visible
|
||||
// non-reasoning model. Treat that catalog-only "none" value as omission for
|
||||
// compatible upstreams, while preserving official OpenAI request semantics.
|
||||
func filterOpenAIResponsesNoneReasoningEffortForAccount(account *Account, body []byte) ([]byte, error) {
|
||||
if len(body) == 0 || shouldPreserveOpenAIResponsesNoneReasoningEffort(account) || isKimiK31RequestModel(account, gjson.GetBytes(body, "model").String()) {
|
||||
if len(body) == 0 || shouldPreserveOpenAIResponsesNoneReasoningEffort(account) {
|
||||
return body, nil
|
||||
}
|
||||
|
||||
@@ -125,9 +116,6 @@ func deleteOpenAIResponsesNoneReasoningEffortFromObject(account *Account, body m
|
||||
if body == nil || shouldPreserveOpenAIResponsesNoneReasoningEffort(account) {
|
||||
return
|
||||
}
|
||||
if model, _ := body["model"].(string); isKimiK31RequestModel(account, model) {
|
||||
return
|
||||
}
|
||||
if effort, ok := body["reasoning_effort"].(string); ok && strings.EqualFold(strings.TrimSpace(effort), "none") {
|
||||
delete(body, "reasoning_effort")
|
||||
}
|
||||
|
||||
@@ -17,9 +17,10 @@ import (
|
||||
)
|
||||
|
||||
// Exercise the gateway boundaries, not just the effort normalizer: model
|
||||
// mapping must happen before model-specific effort handling. The fixture
|
||||
// accepts none so this test can verify that disabled thinking reaches upstream
|
||||
// unchanged; real K3.1 accounts reject it rather than silently enabling it.
|
||||
// mapping must happen before model-specific effort handling. On the Responses
|
||||
// path none is the Codex catalog placeholder and is stripped for compatible
|
||||
// upstreams, exactly like every other Kimi model, so clients that still hold
|
||||
// the previous none-only catalog keep working with K3.1's default effort.
|
||||
func TestKimiK31MappedReasoningAcrossProtocols(t *testing.T) {
|
||||
for _, model := range []string{"k3.1-pro", "k3.1-pro-highspeed"} {
|
||||
for _, protocol := range []string{"responses", "chat/completions", "messages"} {
|
||||
@@ -66,6 +67,10 @@ func TestKimiK31MappedReasoningAcrossProtocols(t *testing.T) {
|
||||
require.NotNil(t, upstream.lastReq)
|
||||
require.Equal(t, "/v1/responses", upstream.lastReq.URL.Path)
|
||||
require.Equal(t, model, gjson.GetBytes(upstream.lastBody, "model").String())
|
||||
if protocol == "responses" && effort == "none" {
|
||||
require.False(t, gjson.GetBytes(upstream.lastBody, "reasoning.effort").Exists())
|
||||
return
|
||||
}
|
||||
require.Equal(t, effort, gjson.GetBytes(upstream.lastBody, "reasoning.effort").String())
|
||||
})
|
||||
}
|
||||
@@ -73,7 +78,7 @@ func TestKimiK31MappedReasoningAcrossProtocols(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestKimiK31NoneSurvivesBothRequestFilters(t *testing.T) {
|
||||
func TestKimiK31NoneFollowsCompatibleUpstreamFilters(t *testing.T) {
|
||||
for _, model := range []string{"k3.1-pro", "k3.1-pro-highspeed"} {
|
||||
for _, requested := range []string{model, "public-kimi"} {
|
||||
t.Run(model+"/"+requested, func(t *testing.T) {
|
||||
@@ -83,11 +88,9 @@ func TestKimiK31NoneSurvivesBothRequestFilters(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
filtered, err := filterOpenAIResponsesNoneReasoningEffortForAccount(account, payload)
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(payload), string(filtered))
|
||||
require.JSONEq(t, `{"model":"`+requested+`"}`, string(filtered))
|
||||
deleteOpenAIResponsesNoneReasoningEffortFromObject(account, body)
|
||||
filtered, err = json.Marshal(body)
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(payload), string(filtered))
|
||||
require.Equal(t, map[string]any{"model": requested}, body)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user