fix(executor): ensure top_p is removed in normalizeClaudeSamplingForUpstream

- Updated `normalizeClaudeSamplingForUpstream` to delete `top_p` from payloads.
- Adjusted test to validate the removal of both `temperature` and `top_p`.

Closes: #4383
This commit is contained in:
Luis Pater
2026-07-17 16:43:26 +08:00
parent 2366f67376
commit 4231ad6e2a
2 changed files with 4 additions and 3 deletions

View File

@@ -887,6 +887,7 @@ func disableThinkingIfToolChoiceForced(body []byte) []byte {
// normalizeClaudeSamplingForUpstream keeps Anthropic message requests valid.
func normalizeClaudeSamplingForUpstream(body []byte) []byte {
body, _ = sjson.DeleteBytes(body, "temperature")
body, _ = sjson.DeleteBytes(body, "top_p")
thinkingType := strings.ToLower(strings.TrimSpace(gjson.GetBytes(body, "thinking.type").String()))
switch thinkingType {

View File

@@ -2745,15 +2745,15 @@ func TestNormalizeClaudeSamplingForUpstream_RemovesTopPAndTopKForThinking(t *tes
}
}
func TestNormalizeClaudeSamplingForUpstream_NoThinkingRemovesOnlyTemperature(t *testing.T) {
func TestNormalizeClaudeSamplingForUpstream_NoThinkingRemovesTemperatureAndTopP(t *testing.T) {
payload := []byte(`{"temperature":0,"top_p":0.9,"top_k":40,"messages":[{"role":"user","content":"hi"}]}`)
out := normalizeClaudeSamplingForUpstream(payload)
if gjson.GetBytes(out, "temperature").Exists() {
t.Fatalf("temperature should be removed")
}
if got := gjson.GetBytes(out, "top_p").Float(); got != 0.9 {
t.Fatalf("top_p = %v, want 0.9", got)
if gjson.GetBytes(out, "top_p").Exists() {
t.Fatalf("top_p should be removed")
}
if got := gjson.GetBytes(out, "top_k").Int(); got != 40 {
t.Fatalf("top_k = %v, want 40", got)