mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-19 02:17:46 +00:00
fix(middleware): ensure prompt budget trimming loop executes
The trimming loop condition `for keep >= minKeep` was never true because `keep` started at 20 while `minKeep` defaults to 25. Added clamp to ensure `keep >= minKeep` at initialization, fixing prompt budget enforcement. Affected functions: - trimOpenAIChatCompletions - trimOpenAIResponses - trimOpenAIChatCompletionsWithMemory - trimOpenAIResponsesWithMemory - trimClaudeMessagesWithMemory Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
This commit is contained in:
@@ -168,6 +168,9 @@ func trimOpenAIChatCompletions(body []byte, maxBytes int, mustKeepTools bool) []
|
||||
perTextLimit := 20_000
|
||||
dropTools := false
|
||||
minKeep := agenticMinKeepMessages()
|
||||
if keep < minKeep {
|
||||
keep = minKeep
|
||||
}
|
||||
for keep >= minKeep {
|
||||
outBody := body
|
||||
if dropTools && !mustKeepTools {
|
||||
@@ -244,6 +247,9 @@ func trimOpenAIResponses(body []byte, maxBytes int, mustKeepTools bool) []byte {
|
||||
perTextLimit := 20_000
|
||||
dropTools := false
|
||||
minKeep := agenticMinKeepMessages()
|
||||
if keep < minKeep {
|
||||
keep = minKeep
|
||||
}
|
||||
for keep >= minKeep {
|
||||
outBody := body
|
||||
if dropTools && !mustKeepTools {
|
||||
@@ -383,6 +389,9 @@ func trimOpenAIChatCompletionsWithMemory(body []byte, maxBytes int, mustKeepTool
|
||||
keep := 20
|
||||
perTextLimit := 20_000
|
||||
dropTools := false
|
||||
if keep < minKeep {
|
||||
keep = minKeep
|
||||
}
|
||||
for keep >= minKeep {
|
||||
outBody := body
|
||||
if dropTools && !mustKeepTools {
|
||||
@@ -533,6 +542,9 @@ func trimOpenAIResponsesWithMemory(body []byte, maxBytes int, mustKeepTools bool
|
||||
keep := 30
|
||||
perTextLimit := 20_000
|
||||
dropTools := false
|
||||
if keep < minKeep {
|
||||
keep = minKeep
|
||||
}
|
||||
for keep >= minKeep {
|
||||
outBody := body
|
||||
if dropTools && !mustKeepTools {
|
||||
@@ -724,6 +736,9 @@ func trimClaudeMessagesWithMemory(body []byte, maxBytes int, mustKeepTools bool)
|
||||
keep := 20
|
||||
perTextLimit := 20_000
|
||||
dropTools := false
|
||||
if keep < minKeep {
|
||||
keep = minKeep
|
||||
}
|
||||
for keep >= minKeep {
|
||||
outBody := body
|
||||
if dropTools && !mustKeepTools {
|
||||
|
||||
Reference in New Issue
Block a user