Skip to content

feat: init default vendor - #1564

Merged
creamlike1024 merged 1 commit into
QuantumNous:alphafrom
feitianbubu:pr/init-default-vendor
Aug 29, 2025
Merged

creamlike1024 merged 1 commit into
QuantumNous:alphafrom
feitianbubu:pr/init-default-vendor

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Aug 11, 2025 •

Copy link
Copy Markdown
Member

根据模型名称初始化默认供应商

懒人福音
使用前:
2025 08 11_傅兴敏 c1ddb77495d04d1697a62243e645a543
使用后:
2025 08 11_傅兴敏 6e6f3d2f55d2597bbc90e309d4082368

Summary by CodeRabbit

  • New Features

    • Automatically associates models with vendors based on model names, creating missing vendors when needed.
    • Vendor list now reflects these auto-mapped vendors, improving coverage without manual setup.
  • Refactor

    • Vendor list is built from an updated source, which may change the display order compared to previous versions.

@coderabbitai

coderabbitai Bot commented Aug 11, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The 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

Cohort / File(s) Summary
Default vendor mapping feature
model/pricing_default.go
Adds defaultVendorRules; introduces initDefaultVendorMapping to auto-map models to vendors based on substrings from enabled abilities; implements getOrCreateVendor to find/create vendors (persisting via Insert) and update vendorMap/metaMap.
Vendor list construction update
model/pricing.go
After building vendorMap, calls initDefaultVendorMapping(metaMap, vendorMap, enableAbilities). Replaces vendors slice-based frontend list construction with iteration over vendorMap, affecting source and ordering of vendorsList.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

I twitch my ears at vendor maps anew,
Names hop to homes as patterns cue.
A nibble of rules, a dash of Insert,
Models find burrows—no need to assert.
From slices to maps we bound and blend,
Carrot-checked lists, neatly to the end. 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d6d580 and 3768fc3.

📒 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 initDefaultVendorMapping is 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.

@creamlike1024
creamlike1024 merged commit c05dc07 into QuantumNous:alpha Aug 29, 2025
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants