fix(relay): preserve presence/frequency penalty in Responses conversion (#6654)

This commit is contained in:
Uzuki Shion
2026-08-11 13:40:13 +08:00
committed by GitHub
parent 9c97e78ace
commit 253a74dd1b
8 changed files with 172 additions and 1 deletions
+2
View File
@@ -104,6 +104,8 @@ func (a *Adaptor) ConvertOpenAIResponsesRequest(c *gin.Context, info *relaycommo
// rm max_output_tokens
request.MaxOutputTokens = nil
request.Temperature = nil
request.FrequencyPenalty = nil
request.PresencePenalty = nil
return request, nil
}
+30
View File
@@ -1,11 +1,14 @@
package codex
import (
"encoding/json"
"testing"
"github.com/QuantumNous/new-api/constant"
relaycommon "github.com/QuantumNous/new-api/relay/common"
relayconstant "github.com/QuantumNous/new-api/relay/constant"
"github.com/QuantumNous/new-api/relaykit/dto"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -24,3 +27,30 @@ func TestGetRequestURLAlphaSearch(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "https://chatgpt.com/backend-api/codex/alpha/search", url)
}
// The Codex backend rejects these fields, so the adaptor clears them rather
// than forwarding what the client sent.
func TestConvertOpenAIResponsesRequestDropsPenalties(t *testing.T) {
adaptor := &Adaptor{}
info := &relaycommon.RelayInfo{
ChannelMeta: &relaycommon.ChannelMeta{ChannelType: constant.ChannelTypeCodex},
RelayMode: relayconstant.RelayModeResponses,
}
converted, err := adaptor.ConvertOpenAIResponsesRequest(nil, info, dto.OpenAIResponsesRequest{
Model: "gpt-5-codex",
Input: json.RawMessage(`"hello"`),
MaxOutputTokens: lo.ToPtr(uint(128)),
Temperature: lo.ToPtr(1.0),
FrequencyPenalty: json.RawMessage(`1.5`),
PresencePenalty: json.RawMessage(`1.5`),
})
require.NoError(t, err)
request, ok := converted.(dto.OpenAIResponsesRequest)
require.True(t, ok)
assert.Nil(t, request.MaxOutputTokens)
assert.Nil(t, request.Temperature)
assert.Nil(t, request.FrequencyPenalty)
assert.Nil(t, request.PresencePenalty)
}