Revert deduplication

This commit is contained in:
Kunal Karmakar
2026-04-22 05:41:32 +00:00
parent 4ae11406d2
commit 7616470137
4 changed files with 33 additions and 34 deletions
-31
View File
@@ -660,37 +660,6 @@ func TestAsFloat(t *testing.T) {
}
}
// --- ExtractProtocol tests ---
func TestExtractProtocol(t *testing.T) {
tests := []struct {
name string
model string
wantProtocol string
wantModelID string
}{
{"openai with prefix", "openai/gpt-4o", "openai", "gpt-4o"},
{"anthropic with prefix", "anthropic/claude-sonnet-4.6", "anthropic", "claude-sonnet-4.6"},
{"no prefix defaults to openai", "gpt-4o", "openai", "gpt-4o"},
{"groq with prefix", "groq/llama-3.1-70b", "groq", "llama-3.1-70b"},
{"empty string", "", "openai", ""},
{"with whitespace", " openai/gpt-4 ", "openai", "gpt-4"},
{"multiple slashes", "nvidia/meta/llama-3.1-8b", "nvidia", "meta/llama-3.1-8b"},
{"azure with prefix", "azure/my-gpt5-deployment", "azure", "my-gpt5-deployment"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
protocol, modelID := ExtractProtocol(tt.model)
if protocol != tt.wantProtocol {
t.Errorf("ExtractProtocol(%q) protocol = %q, want %q", tt.model, protocol, tt.wantProtocol)
}
if modelID != tt.wantModelID {
t.Errorf("ExtractProtocol(%q) modelID = %q, want %q", tt.model, modelID, tt.wantModelID)
}
})
}
}
// --- ParseDataAudioURL tests ---
func TestParseDataAudioURL(t *testing.T) {
+21 -2
View File
@@ -15,7 +15,6 @@ import (
anthropicmessages "github.com/sipeed/picoclaw/pkg/providers/anthropic_messages"
"github.com/sipeed/picoclaw/pkg/providers/azure"
"github.com/sipeed/picoclaw/pkg/providers/bedrock"
"github.com/sipeed/picoclaw/pkg/providers/common"
)
type protocolMeta struct {
@@ -103,7 +102,27 @@ func createCodexAuthProvider() (LLMProvider, error) {
// - Provider "openai", Model "openai/gpt-4o" -> ("openai", "openai/gpt-4o")
// - Model "gpt-4o" -> ("openai", "gpt-4o")
func ExtractProtocol(cfg *config.ModelConfig) (protocol, modelID string) {
return common.ExtractProtocol(model)
if cfg == nil {
return "", ""
}
model := strings.TrimSpace(cfg.Model)
if provider := strings.TrimSpace(cfg.Provider); provider != "" {
return NormalizeProvider(provider), model
}
if model == "" {
return "", ""
}
protocol, rest, found := strings.Cut(model, "/")
if !found {
return "openai", model
}
protocol = strings.TrimSpace(protocol)
if protocol == "" {
return "", strings.TrimSpace(rest)
}
return NormalizeProvider(protocol), strings.TrimSpace(rest)
}
// ResolveAPIBase returns the configured API base, or the protocol default when
+11
View File
@@ -1,5 +1,7 @@
package httpapi
import "strings"
func extractPartThoughtSignature(thoughtSignature string, thoughtSignatureSnake string) string {
if thoughtSignature != "" {
return thoughtSignature
@@ -69,3 +71,12 @@ func sanitizeSchemaForGemini(schema map[string]any) map[string]any {
return result
}
func extractProtocol(model string) (protocol, modelID string) {
model = strings.TrimSpace(model)
protocol, modelID, found := strings.Cut(model, "/")
if !found {
return "openai", model
}
return protocol, modelID
}
+1 -1
View File
@@ -303,7 +303,7 @@ func normalizeGeminiModel(model string) string {
model = strings.TrimSpace(model)
model = strings.TrimPrefix(model, "models/")
if strings.Contains(model, "/") {
_, modelID := common.ExtractProtocol(model)
_, modelID := extractProtocol(model)
if modelID != "" {
return modelID
}