Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var imageGenerationIntentBenchmarkResult bool
|
||||
|
||||
func BenchmarkIsImageGenerationIntent(b *testing.B) {
|
||||
largeInput := strings.Repeat("x", 1<<20)
|
||||
benchmarks := []struct {
|
||||
name string
|
||||
body []byte
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "1MiBInputNoImage",
|
||||
body: []byte(`{"model":"gpt-5.5","tools":[],"input":"` + largeInput + `","tool_choice":"auto"}`),
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "1MiBInputLeadingImageTool",
|
||||
body: []byte(`{"model":"gpt-5.5","tools":[{"type":"image_generation"}],"input":"` + largeInput + `"}`),
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "1MiBInputTrailingToolChoice",
|
||||
body: []byte(`{"model":"gpt-5.5","tools":[],"input":"` + largeInput + `","tool_choice":{"type":"image_generation"}}`),
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Invalid1MiBJSON",
|
||||
body: []byte(`{"model":"gpt-5.5","input":"` + largeInput),
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "DuplicateKeysFirstWins",
|
||||
body: []byte(`{"model":"gpt-5.5","model":"gpt-image-2","tools":[],"tools":[{"type":"image_generation"}],"input":"` + largeInput + `","tool_choice":"auto","tool_choice":{"type":"image_generation"}}`),
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, benchmark := range benchmarks {
|
||||
b.Run(benchmark.name, func(b *testing.B) {
|
||||
if got := IsImageGenerationIntent("/v1/responses", "gpt-5.5", benchmark.body); got != benchmark.want {
|
||||
b.Fatalf("IsImageGenerationIntent() = %v, want %v", got, benchmark.want)
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.SetBytes(int64(len(benchmark.body)))
|
||||
b.ResetTimer()
|
||||
var result bool
|
||||
for i := 0; i < b.N; i++ {
|
||||
result = IsImageGenerationIntent("/v1/responses", "gpt-5.5", benchmark.body)
|
||||
}
|
||||
imageGenerationIntentBenchmarkResult = result
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user