mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-04-05 04:01:22 +00:00
Fixed: #2274
fix(translator): omit null content fields in Codex OpenAI tool call responses
This commit is contained in:
@@ -60,7 +60,7 @@ func ConvertCodexResponseToOpenAI(_ context.Context, modelName string, originalR
|
|||||||
rawJSON = bytes.TrimSpace(rawJSON[5:])
|
rawJSON = bytes.TrimSpace(rawJSON[5:])
|
||||||
|
|
||||||
// Initialize the OpenAI SSE template.
|
// Initialize the OpenAI SSE template.
|
||||||
template := []byte(`{"id":"","object":"chat.completion.chunk","created":12345,"model":"model","choices":[{"index":0,"delta":{"role":null,"content":null,"reasoning_content":null,"tool_calls":null},"finish_reason":null,"native_finish_reason":null}]}`)
|
template := []byte(`{"id":"","object":"chat.completion.chunk","created":12345,"model":"model","choices":[{"index":0,"delta":{},"finish_reason":null,"native_finish_reason":null}]}`)
|
||||||
|
|
||||||
rootResult := gjson.ParseBytes(rawJSON)
|
rootResult := gjson.ParseBytes(rawJSON)
|
||||||
|
|
||||||
|
|||||||
@@ -45,3 +45,48 @@ func TestConvertCodexResponseToOpenAI_FirstChunkUsesRequestModelName(t *testing.
|
|||||||
t.Fatalf("expected model %q, got %q", modelName, gotModel)
|
t.Fatalf("expected model %q, got %q", modelName, gotModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertCodexResponseToOpenAI_ToolCallChunkOmitsNullContentFields(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
var param any
|
||||||
|
|
||||||
|
out := ConvertCodexResponseToOpenAI(ctx, "gpt-5.4", nil, nil, []byte(`data: {"type":"response.output_item.added","item":{"type":"function_call","call_id":"call_123","name":"websearch"}}`), ¶m)
|
||||||
|
if len(out) != 1 {
|
||||||
|
t.Fatalf("expected 1 chunk, got %d", len(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
if gjson.GetBytes(out[0], "choices.0.delta.content").Exists() {
|
||||||
|
t.Fatalf("expected content to be omitted, got %s", string(out[0]))
|
||||||
|
}
|
||||||
|
if gjson.GetBytes(out[0], "choices.0.delta.reasoning_content").Exists() {
|
||||||
|
t.Fatalf("expected reasoning_content to be omitted, got %s", string(out[0]))
|
||||||
|
}
|
||||||
|
if !gjson.GetBytes(out[0], "choices.0.delta.tool_calls").Exists() {
|
||||||
|
t.Fatalf("expected tool_calls to exist, got %s", string(out[0]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConvertCodexResponseToOpenAI_ToolCallArgumentsDeltaOmitsNullContentFields(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
var param any
|
||||||
|
|
||||||
|
out := ConvertCodexResponseToOpenAI(ctx, "gpt-5.4", nil, nil, []byte(`data: {"type":"response.output_item.added","item":{"type":"function_call","call_id":"call_123","name":"websearch"}}`), ¶m)
|
||||||
|
if len(out) != 1 {
|
||||||
|
t.Fatalf("expected tool call announcement chunk, got %d", len(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
out = ConvertCodexResponseToOpenAI(ctx, "gpt-5.4", nil, nil, []byte(`data: {"type":"response.function_call_arguments.delta","delta":"{\"query\":\"OpenAI\"}"}`), ¶m)
|
||||||
|
if len(out) != 1 {
|
||||||
|
t.Fatalf("expected 1 chunk, got %d", len(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
if gjson.GetBytes(out[0], "choices.0.delta.content").Exists() {
|
||||||
|
t.Fatalf("expected content to be omitted, got %s", string(out[0]))
|
||||||
|
}
|
||||||
|
if gjson.GetBytes(out[0], "choices.0.delta.reasoning_content").Exists() {
|
||||||
|
t.Fatalf("expected reasoning_content to be omitted, got %s", string(out[0]))
|
||||||
|
}
|
||||||
|
if !gjson.GetBytes(out[0], "choices.0.delta.tool_calls.0.function.arguments").Exists() {
|
||||||
|
t.Fatalf("expected tool call arguments delta to exist, got %s", string(out[0]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user