Skip to content

feat: support user-group-specific for mj and task - #1281

Merged
Calcium-Ion merged 3 commits into
alphafrom
mj_usergroupratio
Jun 22, 2025
Merged

Calcium-Ion merged 3 commits into
alphafrom
mj_usergroupratio

Conversation

@creamlike1024

@creamlike1024 creamlike1024 commented Jun 22, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Enhanced quota calculation to use user-group-specific pricing ratios when available, providing more accurate quota deductions for users.
    • Logging now includes detailed information about which pricing ratio was applied (user-group or general group).
  • Refactor

    • Improved internal logic for determining and logging quota consumption details, resulting in clearer and more informative logs.
    • Unified usage of group identifiers across quota calculations and logging for consistent behavior.
    • Introduced a helper function to streamline per-call pricing and quota computations.

@coderabbitai

coderabbitai Bot commented Jun 22, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes refactor quota calculation and logging across relay services to use a unified helper returning detailed pricing data, including special user-group-to-group ratios. The RelayInfo struct replaces Group with UsingGroup to unify group references. Logging and quota consumption functions now consistently use UsingGroup. A new constant and helper functions support these updates. No control flow or error handling changes were introduced.

Changes

File(s) Change Summary
relay/relay-mj.go, service/log_info_generate.go, relay/helper/price.go Refactored quota calculation and logging to use ModelPriceHelperPerCall returning detailed price data; added GenerateMjOtherInfo for logging; replaced manual ratio and quota calculations.
relay_task.go, service/quota.go, relay/relay-text.go, controller/channel-test.go Changed quota ratio and logging to use UsingGroup instead of Group; updated user-group-to-group ratio usage in quota calculation and logging.
relay/common/relay_info.go, middleware/distributor.go, constant/context_key.go Replaced Group field with UsingGroup in RelayInfo; added ContextKeyUsingGroup constant; updated context key usage accordingly.
setting/ratio_setting/group_ratio.go Renamed parameters in GetGroupGroupRatio to (userGroup, usingGroup) to reflect new naming conventions.
web/vite.config.js Added new proxy configuration for /mj path to local server at port 3000.

Possibly related PRs

  • feat: 分组特殊倍率 #1207: Introduced initial support for user-group-specific ratios in pricing and logging, which this PR extends by refactoring quota logic to use unified helpers.
  • feat: auto分组 #1239: Added support for "auto" group in user group management and group ratio logic, related through shared group handling concepts.

Poem

In the warren of code, a ratio hops,
Now user-group magic, it never stops.
With logging more clever and helpers anew,
The quota math’s fairer for every crew.
🐇✨
Ratios abound, precision in tow—
This rabbit approves, let the quotas flow!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39617bc and fd04098.

📒 Files selected for processing (12)
  • constant/context_key.go (1 hunks)
  • controller/channel-test.go (1 hunks)
  • middleware/distributor.go (1 hunks)
  • relay/common/relay_info.go (2 hunks)
  • relay/helper/price.go (4 hunks)
  • relay/relay-mj.go (7 hunks)
  • relay/relay-text.go (1 hunks)
  • relay/relay_task.go (3 hunks)
  • service/log_info_generate.go (2 hunks)
  • service/quota.go (4 hunks)
  • setting/ratio_setting/group_ratio.go (1 hunks)
  • web/vite.config.js (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • constant/context_key.go
  • relay/common/relay_info.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • relay/relay-mj.go
  • relay/relay_task.go
🔇 Additional comments (10)
web/vite.config.js (1)

69-72: LGTM! Proxy configuration follows established patterns.

The new /mj proxy configuration is consistent with existing proxy entries and properly configured for development. This aligns well with the backend changes for Midjourney functionality.

Ensure that the backend service is properly configured to handle /mj requests at http://localhost:3000. You can verify this by checking if the corresponding route handlers are implemented in the backend service.

#!/bin/bash
# Description: Verify that backend routes for /mj are properly configured
# Expected: Find route handlers or middleware for /mj paths

echo "Searching for /mj route configurations in the backend..."
rg -A 3 -B 1 '"/mj"' --type go
rg -A 3 -B 1 "'/mj'" --type go
rg -A 3 -B 1 'mj.*route' --type go
controller/channel-test.go (1)

174-174: LGTM! Consistent with UsingGroup refactor.

The change from info.Group to info.UsingGroup aligns with the broader refactoring to unify group references throughout the codebase.

middleware/distributor.go (1)

60-60: LGTM! Good practice using named constant.

Replacing the string literal "group" with constant.ContextKeyUsingGroup improves maintainability and ensures consistent key usage across the codebase.

relay/relay-text.go (1)

544-544: LGTM! Consistent with UsingGroup refactor.

The change from relayInfo.Group to relayInfo.UsingGroup is consistent with the refactoring effort to unify group references across the codebase.

setting/ratio_setting/group_ratio.go (1)

76-88: LGTM! Parameter renaming improves clarity.

The function parameter renaming from (group, name string) to (userGroup, usingGroup string) makes the distinction between the user's group and the group being used more explicit, improving code readability and consistency with the broader refactor.

service/log_info_generate.go (2)

6-6: LGTM! New import supports unified pricing helpers.

The addition of the "one-api/relay/helper" import is necessary for the new GenerateMjOtherInfo function.


68-76: LGTM! New function follows established patterns.

The GenerateMjOtherInfo function follows the same pattern as other similar functions in this file, properly extracting pricing and ratio information from the unified PerCallPriceData structure. The conditional inclusion of user_group_ratio when HasSpecialRatio is true demonstrates proper handling of optional data.

service/quota.go (1)

98-98: LGTM! Consistent group reference refactoring.

The systematic replacement of relayInfo.Group with relayInfo.UsingGroup across all quota calculation and logging functions is consistent and maintains the unified group reference pattern throughout the codebase.

Also applies to: 105-105, 109-109, 213-213, 290-290, 388-388

relay/helper/price.go (2)

48-48: LGTM! Consistent group reference updates and enhanced metadata.

The changes to HandleGroupRatio maintain consistency with the broader Group → UsingGroup refactoring. The addition of HasSpecialRatio flag provides valuable metadata about special ratio application.

Also applies to: 52-52, 57-57, 60-60


125-152: Well-structured per-call pricing helper with robust fallback logic.

The new ModelPriceHelperPerCall function provides a clean abstraction for per-call billing scenarios with appropriate fallback mechanisms:

  1. Primary: Configured model price via GetModelPrice(..., true)
  2. Secondary: Default model ratio map
  3. Fallback: Hardcoded 0.1

The function correctly uses UsingGroup for group ratio calculations and maintains consistency with the existing helper pattern.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

@Calcium-Ion Calcium-Ion changed the title Mj usergroupratio feat: support user-group-specific for mj and task Jun 22, 2025
@Calcium-Ion
Calcium-Ion merged commit 63640f6 into alpha Jun 22, 2025
@Calcium-Ion
Calcium-Ion deleted the mj_usergroupratio branch July 12, 2025 04:11
@coderabbitai coderabbitai Bot mentioned this pull request Feb 22, 2026
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
feat: support user-group-specific for mj and task
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
feat: support user-group-specific for mj and task
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
feat: support user-group-specific for mj and task
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