mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-28 16:15:49 +08:00
refactor: simplify context_management compatibility handling
This commit is contained in:
@@ -2,7 +2,6 @@ package responses
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"github.com/tidwall/sjson"
|
"github.com/tidwall/sjson"
|
||||||
@@ -47,32 +46,12 @@ func ConvertOpenAIResponsesRequestToCodex(modelName string, inputRawJSON []byte,
|
|||||||
//
|
//
|
||||||
// Compatibility strategy:
|
// Compatibility strategy:
|
||||||
// 1) Remove context_management before forwarding to Codex upstream.
|
// 1) Remove context_management before forwarding to Codex upstream.
|
||||||
// 2) Remove truncation as Codex upstream currently rejects it as unsupported.
|
|
||||||
func applyResponsesCompactionCompatibility(rawJSON []byte) []byte {
|
func applyResponsesCompactionCompatibility(rawJSON []byte) []byte {
|
||||||
contextManagement := gjson.GetBytes(rawJSON, "context_management")
|
if !gjson.GetBytes(rawJSON, "context_management").Exists() {
|
||||||
if !contextManagement.Exists() {
|
|
||||||
return rawJSON
|
return rawJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
hasCompactionRule := false
|
|
||||||
switch {
|
|
||||||
case contextManagement.IsArray():
|
|
||||||
for _, item := range contextManagement.Array() {
|
|
||||||
if strings.EqualFold(item.Get("type").String(), "compaction") {
|
|
||||||
hasCompactionRule = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case contextManagement.IsObject():
|
|
||||||
hasCompactionRule = strings.EqualFold(contextManagement.Get("type").String(), "compaction")
|
|
||||||
}
|
|
||||||
|
|
||||||
if hasCompactionRule {
|
|
||||||
// no-op marker: compaction hint detected and consumed for compatibility.
|
|
||||||
}
|
|
||||||
|
|
||||||
rawJSON, _ = sjson.DeleteBytes(rawJSON, "context_management")
|
rawJSON, _ = sjson.DeleteBytes(rawJSON, "context_management")
|
||||||
rawJSON, _ = sjson.DeleteBytes(rawJSON, "truncation")
|
|
||||||
return rawJSON
|
return rawJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user