mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-28 17:55:57 +08:00
refactor: simplify context_management compatibility handling
This commit is contained in:
@@ -2,7 +2,6 @@ package responses
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
@@ -47,32 +46,12 @@ func ConvertOpenAIResponsesRequestToCodex(modelName string, inputRawJSON []byte,
|
||||
//
|
||||
// Compatibility strategy:
|
||||
// 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 {
|
||||
contextManagement := gjson.GetBytes(rawJSON, "context_management")
|
||||
if !contextManagement.Exists() {
|
||||
if !gjson.GetBytes(rawJSON, "context_management").Exists() {
|
||||
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, "truncation")
|
||||
return rawJSON
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user