pricing_default.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package model
  2. import (
  3. "strings"
  4. )
  5. // 简化的供应商映射规则
  6. var defaultVendorRules = map[string]string{
  7. "gpt": "OpenAI",
  8. "dall-e": "OpenAI",
  9. "whisper": "OpenAI",
  10. "o1": "OpenAI",
  11. "o3": "OpenAI",
  12. "claude": "Anthropic",
  13. "gemini": "Google",
  14. "moonshot": "Moonshot",
  15. "kimi": "Moonshot",
  16. "chatglm": "智谱",
  17. "glm-": "智谱",
  18. "qwen": "阿里巴巴",
  19. "deepseek": "DeepSeek",
  20. "abab": "MiniMax",
  21. "ernie": "百度",
  22. "spark": "讯飞",
  23. "hunyuan": "腾讯",
  24. "command": "Cohere",
  25. "@cf/": "Cloudflare",
  26. "360": "360",
  27. "yi": "零一万物",
  28. "jina": "Jina",
  29. "mistral": "Mistral",
  30. "grok": "xAI",
  31. "llama": "Meta",
  32. "doubao": "字节跳动",
  33. "kling": "快手",
  34. "jimeng": "即梦",
  35. "vidu": "Vidu",
  36. }
  37. // initDefaultVendorMapping 简化的默认供应商映射
  38. func initDefaultVendorMapping(metaMap map[string]*Model, vendorMap map[int]*Vendor, enableAbilities []AbilityWithChannel) {
  39. for _, ability := range enableAbilities {
  40. modelName := ability.Model
  41. if _, exists := metaMap[modelName]; exists {
  42. continue
  43. }
  44. // 匹配供应商
  45. vendorID := 0
  46. modelLower := strings.ToLower(modelName)
  47. for pattern, vendorName := range defaultVendorRules {
  48. if strings.Contains(modelLower, pattern) {
  49. vendorID = getOrCreateVendor(vendorName, vendorMap)
  50. break
  51. }
  52. }
  53. // 创建模型元数据
  54. metaMap[modelName] = &Model{
  55. ModelName: modelName,
  56. VendorID: vendorID,
  57. Status: 1,
  58. NameRule: NameRuleExact,
  59. }
  60. }
  61. }
  62. // 查找或创建供应商
  63. func getOrCreateVendor(vendorName string, vendorMap map[int]*Vendor) int {
  64. // 查找现有供应商
  65. for id, vendor := range vendorMap {
  66. if vendor.Name == vendorName {
  67. return id
  68. }
  69. }
  70. // 创建新供应商
  71. newVendor := &Vendor{
  72. Name: vendorName,
  73. Status: 1,
  74. }
  75. if err := newVendor.Insert(); err != nil {
  76. return 0
  77. }
  78. vendorMap[newVendor.Id] = newVendor
  79. return newVendor.Id
  80. }