| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "slices" |
| 5 | "strings" |
| 6 | |
| 7 | "reasonix/internal/provider" |
| 8 | "reasonix/internal/provider/openai" |
| 9 | ) |
| 10 | |
| 11 | // OfficialDeepSeekPinnedVisionModels returns the official vision SKU when it is |
| 12 | // in the enabled model list. Settings can still mark other models for image |
| 13 | // input; this helper is only the stock default. |
| 14 | func OfficialDeepSeekPinnedVisionModels(models []string) []string { |
| 15 | if !slices.ContainsFunc(models, openai.IsOfficialDeepSeekVisionModel) { |
| 16 | return nil |
| 17 | } |
| 18 | return []string{openai.OfficialDeepSeekVisionModel} |
| 19 | } |
| 20 | |
| 21 | func backfillOfficialDeepSeekVisionModel(p *ProviderEntry) { |
| 22 | if p == nil || officialProviderHost(p.BaseURL) != "api.deepseek.com" { |
| 23 | return |
| 24 | } |
| 25 | sku := openai.OfficialDeepSeekVisionModel |
| 26 | models := p.ModelList() |
| 27 | var stock []string |
| 28 | switch strings.TrimSpace(p.Name) { |
| 29 | case "deepseek-pro": |
| 30 | return |
| 31 | case "deepseek-flash": |
| 32 | if officialDeepSeekModelSetEquals(models, []string{"deepseek-v4-flash", sku}) { |
| 33 | stock = []string{"deepseek-v4-flash", sku} |
| 34 | } else if officialDeepSeekModelSetEquals(models, []string{"deepseek-v4-flash"}) && p.VisionModels == nil { |
| 35 | stock = []string{"deepseek-v4-flash", sku} |
| 36 | } |
| 37 | case "deepseek", "deepseek-anthropic", "deepseek-responses": |
| 38 | if officialDeepSeekModelSetEquals(models, []string{"deepseek-v4-flash", "deepseek-v4-pro", sku}) { |
| 39 | stock = []string{"deepseek-v4-flash", "deepseek-v4-pro", sku} |
| 40 | } else if officialDeepSeekModelSetEquals(models, []string{"deepseek-v4-flash", "deepseek-v4-pro"}) && p.VisionModels == nil { |
| 41 | stock = []string{"deepseek-v4-flash", "deepseek-v4-pro", sku} |
| 42 | } |
| 43 | } |
| 44 | if stock == nil { |
| 45 | return |
| 46 | } |
| 47 | if !p.HasModel(sku) { |
| 48 | p.Models = mergeModelLists(models, []string{sku}) |
| 49 | p.Default = firstKnownModel(p.Default, p.Models, "deepseek-v4-flash") |
| 50 | } |
| 51 | if p.VisionModels == nil { |
| 52 | p.VisionModels = OfficialDeepSeekPinnedVisionModels(p.ModelList()) |
| 53 | } |
| 54 | backfillOfficialDeepSeekVisionPrice(p) |
| 55 | } |
| 56 | |
| 57 | func backfillOfficialDeepSeekVisionPrice(p *ProviderEntry) { |
| 58 | sku := openai.OfficialDeepSeekVisionModel |
| 59 | if p == nil || !p.HasModel(sku) { |
| 60 | return |
| 61 | } |
| 62 | if price, ok := pricingForModelKey(p.Prices, sku); ok && price != nil { |
| 63 | return |
| 64 | } |
| 65 | currency := p.ProviderBillingCurrency() |
| 66 | if currency == "" { |
| 67 | currency = "USD" |
| 68 | } |
| 69 | price := deepSeekV4PriceForModel(currency, sku) |
| 70 | if price == nil { |
| 71 | return |
| 72 | } |
| 73 | if p.Prices == nil { |
| 74 | p.Prices = map[string]*provider.Pricing{} |
| 75 | } |
| 76 | p.Prices[sku] = price |
| 77 | } |
| 78 | |
| 79 | func officialDeepSeekModelSetEquals(got, want []string) bool { |
| 80 | if len(got) != len(want) { |
| 81 | return false |
| 82 | } |
| 83 | counts := make(map[string]int, len(want)) |
| 84 | for _, model := range got { |
| 85 | counts[strings.ToLower(strings.TrimSpace(model))]++ |
| 86 | } |
| 87 | for _, model := range want { |
| 88 | key := strings.ToLower(strings.TrimSpace(model)) |
| 89 | if counts[key] == 0 { |
| 90 | return false |
| 91 | } |
| 92 | counts[key]-- |
| 93 | } |
| 94 | return true |
| 95 | } |
| 96 |