mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-07 00:24:17 +08:00
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:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user