Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,29 @@
|
|||
package responses
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestConvertOpenAIResponsesRequestToClaudeWithCompatPreservesEmptyReasoning(t *testing.T) {
|
||||
payload := []byte(`{"input":[{"type":"reasoning","summary":[{"type":"summary_text","text":"reason"}],"encrypted_content":""}]}`)
|
||||
|
||||
withoutCompat := ConvertOpenAIResponsesRequestToClaude("deepseek-v4", payload, false)
|
||||
if gjson.GetBytes(withoutCompat, "messages.#").Int() != 0 {
|
||||
t.Fatalf("default translation preserved empty reasoning: %s", withoutCompat)
|
||||
}
|
||||
|
||||
withCompat := ConvertOpenAIResponsesRequestToClaudeWithCompat("deepseek-v4", payload, false)
|
||||
part := gjson.GetBytes(withCompat, "messages.0.content.0")
|
||||
if part.Get("type").String() != "thinking" || part.Get("signature").String() != "" {
|
||||
t.Fatalf("compat translation missing unsigned thinking block: %s", withCompat)
|
||||
}
|
||||
|
||||
opaquePayload := []byte(`{"input":[{"type":"reasoning","summary":[{"type":"summary_text","text":"reason"}],"encrypted_content":"opaque-deepseek-id"}]}`)
|
||||
opaqueCompat := ConvertOpenAIResponsesRequestToClaudeWithCompat("deepseek-v4", opaquePayload, false)
|
||||
opaquePart := gjson.GetBytes(opaqueCompat, "messages.0.content.0")
|
||||
if opaquePart.Get("type").String() != "thinking" || opaquePart.Get("thinking").String() != "reason" || opaquePart.Get("signature").String() != "opaque-deepseek-id" {
|
||||
t.Fatalf("compat translation dropped invalid-signature thinking block: %s", opaqueCompat)
|
||||
}
|
||||
}
|
||||
19
backend/internal/translator/claude/openai/responses/init.go
Normal file
19
backend/internal/translator/claude/openai/responses/init.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package responses
|
||||
|
||||
import (
|
||||
. "github.com/router-for-me/CLIProxyAPI/v7/internal/constant"
|
||||
"github.com/router-for-me/CLIProxyAPI/v7/internal/interfaces"
|
||||
"github.com/router-for-me/CLIProxyAPI/v7/internal/translator/translator"
|
||||
)
|
||||
|
||||
func init() {
|
||||
translator.Register(
|
||||
OpenaiResponse,
|
||||
Claude,
|
||||
ConvertOpenAIResponsesRequestToClaude,
|
||||
interfaces.TranslateResponse{
|
||||
Stream: ConvertClaudeResponseToOpenAIResponses,
|
||||
NonStream: ConvertClaudeResponseToOpenAIResponsesNonStream,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package responses
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestConvertClaudeResponseToOpenAIResponsesNonStreamKeepsZeroUsageDefaults(t *testing.T) {
|
||||
input := []byte(`data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"hello"}}`)
|
||||
|
||||
output := ConvertClaudeResponseToOpenAIResponsesNonStream(context.Background(), "", nil, nil, input, nil)
|
||||
|
||||
for _, path := range []string{"usage.input_tokens", "usage.input_tokens_details.cached_tokens", "usage.output_tokens", "usage.total_tokens"} {
|
||||
value := gjson.GetBytes(output, path)
|
||||
if !value.Exists() || value.Int() != 0 {
|
||||
t.Fatalf("%s = %s, want zero", path, value.Raw)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue