mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-07 16:08:02 +08:00
fix(openai): preserve numeric precision in Lite payloads
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -263,7 +262,7 @@ func openAIResponsesLiteToolIdentityForError(rawTool any) string {
|
||||
|
||||
func normalizeOpenAIResponsesLiteToolsPayload(body []byte) ([]byte, bool, error) {
|
||||
var requestBody map[string]any
|
||||
if err := json.Unmarshal(body, &requestBody); err != nil {
|
||||
if err := decodeOpenAIJSONUseNumber(body, &requestBody); err != nil {
|
||||
return body, false, fmt.Errorf("decode responses Lite request body: %w", err)
|
||||
}
|
||||
changed, err := normalizeOpenAIResponsesLiteTools(requestBody)
|
||||
@@ -279,7 +278,7 @@ func normalizeOpenAIResponsesLiteToolsPayload(body []byte) ([]byte, bool, error)
|
||||
|
||||
func normalizeOpenAIResponsesLiteParallelToolCallsPayload(body []byte) ([]byte, bool, error) {
|
||||
var requestBody map[string]any
|
||||
if err := json.Unmarshal(body, &requestBody); err != nil {
|
||||
if err := decodeOpenAIJSONUseNumber(body, &requestBody); err != nil {
|
||||
return body, false, fmt.Errorf("decode responses Lite request body: %w", err)
|
||||
}
|
||||
changed, err := ensureOpenAIResponsesLiteParallelToolCalls(requestBody, false)
|
||||
|
||||
@@ -344,6 +344,34 @@ func TestNormalizeOpenAIResponsesLiteToolsPayload_PreservesResponseCreateShape(t
|
||||
require.False(t, gjson.GetBytes(updated, "parallel_tool_calls").Bool())
|
||||
}
|
||||
|
||||
func TestNormalizeOpenAIResponsesLitePayloads_PreserveLargeSequence(t *testing.T) {
|
||||
body := []byte(`{
|
||||
"type":"response.create",
|
||||
"sequence":900719925474099312345,
|
||||
"tools":[{"type":"function","name":"lookup"}],
|
||||
"parallel_tool_calls":true
|
||||
}`)
|
||||
tests := []struct {
|
||||
name string
|
||||
normalize func([]byte) ([]byte, bool, error)
|
||||
}{
|
||||
{name: "OAuth-like tools normalization", normalize: normalizeOpenAIResponsesLiteToolsPayload},
|
||||
{name: "API key parallel normalization", normalize: normalizeOpenAIResponsesLiteParallelToolCallsPayload},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
updated, changed, err := tt.normalize(body)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.True(t, changed)
|
||||
require.Equal(t, "900719925474099312345", gjson.GetBytes(updated, "sequence").Raw)
|
||||
require.True(t, gjson.GetBytes(updated, "parallel_tool_calls").Exists())
|
||||
require.False(t, gjson.GetBytes(updated, "parallel_tool_calls").Bool())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyCodexOAuthTransform_PreservesLiteNamespaceToolChoice(t *testing.T) {
|
||||
reqBody := map[string]any{
|
||||
"model": "gpt-5.6-terra",
|
||||
|
||||
Reference in New Issue
Block a user