mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
9a3ca8e54d
* feat(provider): add Alibaba Coding Plan and regional Qwen endpoints - Add Alibaba Coding Plan provider with OpenAI-compatible endpoint (https://coding-intl.dashscope.aliyuncs.com/v1) - Add Coding Plan Anthropic-compatible endpoint (https://coding-intl.dashscope.aliyuncs.com/apps/anthropic) - Add regional Qwen endpoints (qwen-intl, qwen-us) - Add provider aliases: coding-plan, alibaba-coding, qwen-coding - Normalize provider names for coding-plan variants 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix(provider): add reviewer-requested fixes for Alibaba Coding Plan - Add qwen-international, dashscope-intl, dashscope-us aliases to switch case - Add coding-plan-anthropic case with anthropicmessages.NewProviderWithTimeout - Add alibaba-coding-anthropic -> coding-plan-anthropic normalization - Add qwen-international -> qwen-intl and dashscope-us -> qwen-us normalization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * test(provider): add tests for Alibaba Coding Plan protocol aliases - Add tests for qwen-international, dashscope-intl, dashscope-us aliases - Add tests for coding-plan-anthropic and alibaba-coding-anthropic - Add getDefaultAPIBase tests for all new aliases - Add normalization tests for new provider aliases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package providers
|
|
|
|
import "strings"
|
|
|
|
// ModelRef represents a parsed model reference with provider and model name.
|
|
type ModelRef struct {
|
|
Provider string
|
|
Model string
|
|
}
|
|
|
|
// ParseModelRef parses "anthropic/claude-opus" into {Provider: "anthropic", Model: "claude-opus"}.
|
|
// If no slash present, uses defaultProvider.
|
|
// Returns nil for empty input.
|
|
func ParseModelRef(raw string, defaultProvider string) *ModelRef {
|
|
raw = strings.TrimSpace(raw)
|
|
if raw == "" {
|
|
return nil
|
|
}
|
|
|
|
if idx := strings.Index(raw, "/"); idx > 0 {
|
|
provider := NormalizeProvider(raw[:idx])
|
|
model := strings.TrimSpace(raw[idx+1:])
|
|
if model == "" {
|
|
return nil
|
|
}
|
|
return &ModelRef{Provider: provider, Model: model}
|
|
}
|
|
|
|
return &ModelRef{
|
|
Provider: NormalizeProvider(defaultProvider),
|
|
Model: raw,
|
|
}
|
|
}
|
|
|
|
// NormalizeProvider normalizes provider identifiers to canonical form.
|
|
func NormalizeProvider(provider string) string {
|
|
p := strings.ToLower(strings.TrimSpace(provider))
|
|
|
|
switch p {
|
|
case "z.ai", "z-ai":
|
|
return "zai"
|
|
case "opencode-zen":
|
|
return "opencode"
|
|
case "qwen":
|
|
return "qwen-portal"
|
|
case "kimi-code":
|
|
return "kimi-coding"
|
|
case "gpt":
|
|
return "openai"
|
|
case "claude":
|
|
return "anthropic"
|
|
case "glm":
|
|
return "zhipu"
|
|
case "google":
|
|
return "gemini"
|
|
case "alibaba-coding", "qwen-coding":
|
|
return "coding-plan"
|
|
case "alibaba-coding-anthropic":
|
|
return "coding-plan-anthropic"
|
|
case "qwen-international", "dashscope-intl":
|
|
return "qwen-intl"
|
|
case "dashscope-us":
|
|
return "qwen-us"
|
|
}
|
|
|
|
return p
|
|
}
|
|
|
|
// ModelKey returns a canonical "provider/model" key for deduplication.
|
|
func ModelKey(provider, model string) string {
|
|
return NormalizeProvider(provider) + "/" + strings.ToLower(strings.TrimSpace(model))
|
|
}
|