Repository navigation
feat: init default vendor - #1564
Conversation
WalkthroughThe PR adds a default vendor mapping mechanism and shifts vendor list construction to use a map. A new file initializes model-to-vendor mappings based on name patterns and abilities, creating vendors as needed. Existing pricing code now invokes this initializer and builds the frontend vendor list from the resulting vendorMap. Changes
Sequence Diagram(s)sequenceDiagram
participant Pricing as pricing.go
participant Mapper as initDefaultVendorMapping
participant DB as DB/Vendor.Insert
participant Meta as metaMap
participant VMap as vendorMap
Pricing->>Mapper: initDefaultVendorMapping(metaMap, vendorMap, enableAbilities)
loop for each ability.model
Mapper->>Mapper: match model name via defaultVendorRules
alt vendor match found
Mapper->>VMap: getOrCreateVendor(vendorName)
alt vendor exists
VMap-->>Mapper: vendorID
else create new
Mapper->>DB: Vendor.Insert()
DB-->>Mapper: new vendor ID or error
Mapper->>VMap: add vendor entry (on success)
end
Mapper->>Meta: add Model with VendorID, Status=1, NameRuleExact
else no match
Mapper-->>Mapper: vendorID = 0 (skip/neutral)
end
end
Mapper-->>Pricing: updated metaMap and vendorMap
Pricing->>VMap: iterate vendorMap to build vendorsList
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
model/pricing_default.go (1)
69-89: Vendor creation logic is correct with minor considerations.The function properly checks for existing vendors and persists new ones. Consider adding error logging when
Insert()fails for debugging purposes, and note that concurrent access could potentially create race conditions.Add error logging for better debugging:
if err := newVendor.Insert(); err != nil { + // Log the error for debugging purposes + common.SysError(fmt.Sprintf("Failed to create vendor %s: %v", vendorName, err)) return 0 }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
model/pricing.go(1 hunks)model/pricing_default.go(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
model/pricing_default.go (3)
model/model_meta.go (2)
Model(37-57)NameRuleExact(26-26)model/vendor_meta.go (1)
Vendor(15-24)model/ability.go (1)
AbilityWithChannel(25-28)
🔇 Additional comments (4)
model/pricing.go (2)
158-159: LGTM! Logical placement of default vendor mapping.The call to
initDefaultVendorMappingis well-positioned after loading existing vendors but before building the frontend vendor list, allowing proper augmentation of both maps.
162-163: Vendor list construction correctly updated for default mapping.The changes properly include vendors added by the default mapping mechanism. Note that iteration order is now non-deterministic due to map iteration, which differs from the previous deterministic DB ordering.
model/pricing_default.go (2)
8-38: Comprehensive vendor mapping rules with good coverage.The default vendor rules cover major AI providers effectively. Consider that some patterns like "yi" might be ambiguous - ensure testing covers edge cases where model names might match unintended patterns.
41-66: Sound logic for default model-vendor mapping.The function correctly handles existing models and creates temporary Model entries for unmapped models. Note that these mappings are temporary (not persisted to database) and recreated on each pricing update, which is appropriate for a default mapping mechanism.
…vendor feat: init default vendor
…vendor feat: init default vendor
…vendor feat: init default vendor
根据模型名称初始化默认供应商
懒人福音


使用前:
使用后:
Summary by CodeRabbit
New Features
Refactor