rikkahub默认可查询余额,gemini格式获取模型列表修复 - #5899
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdds a ChangesCredits endpoint
Gemini model listing
Dashboard time granularity
Fork image publishing and docs
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
controller/billing.go (1)
134-142: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract shared quota-display conversion logic.
This switch statement is duplicated verbatim in
GetUsage(lines 94-101) andGetSubscription(lines 48-55). A shared helper (e.g.convertQuotaToDisplayAmount(quota int) float64) would prevent the three copies from drifting when a new display type or conversion rule is added.♻️ Proposed refactor
+func convertQuotaToDisplayAmount(quota int) float64 { + amount := float64(quota) + switch operation_setting.GetQuotaDisplayType() { + case operation_setting.QuotaDisplayTypeCNY: + amount = amount / common.QuotaPerUnit * operation_setting.USDExchangeRate + case operation_setting.QuotaDisplayTypeTokens: + // tokens 保持原值 + default: + amount = amount / common.QuotaPerUnit + } + return amount +} + func GetCredits(c *gin.Context) { ... - amount := float64(quota) - switch operation_setting.GetQuotaDisplayType() { - case operation_setting.QuotaDisplayTypeCNY: - amount = amount / common.QuotaPerUnit * operation_setting.USDExchangeRate - case operation_setting.QuotaDisplayTypeTokens: - // tokens 保持原值 - default: - amount = amount / common.QuotaPerUnit - } + amount := convertQuotaToDisplayAmount(quota)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@controller/billing.go` around lines 134 - 142, The quota display conversion switch is duplicated in controller billing logic and should be centralized to avoid drift. Extract the shared amount conversion from GetUsage, GetSubscription, and the current billing flow into a helper such as convertQuotaToDisplayAmount that uses operation_setting.GetQuotaDisplayType, common.QuotaPerUnit, and operation_setting.USDExchangeRate, then have each caller use that helper instead of repeating the switch.controller/billing_test.go (1)
78-115: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider covering
UnlimitedQuotaand the error path.Current tests only exercise the plain token/user quota branches.
GetCreditshas two other billing-relevant behaviors not covered here: theUnlimitedQuotaoverride (amount = 100000000) and the JSON error response when the token/user lookup fails. Since this endpoint reports account balance, these are worth locking in as regression tests.As per path instructions, "Backend tests must protect real behavior, API contracts, billing/accounting invariants, data compatibility, or regression paths."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@controller/billing_test.go` around lines 78 - 115, Add coverage in GetCredits tests for the remaining billing branches: verify that the credits calculation honors the UnlimitedQuota override, and add a negative test for the lookup failure path that returns the JSON error response. Use the existing TestGetCreditsUsesTokenRemainingQuotaWhenTokenStatsEnabled, TestGetCreditsUsesUserQuotaWhenTokenStatsDisabled, and requestCredits helpers to locate the behavior, and assert the expected TotalUsage or error payload for the token/user fetch failures.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/docker-hub-user.yml:
- Around line 4-7: The Docker Hub publish workflow is pushing the wrong image
target for main branch builds. Update the workflow in docker-hub-user to publish
the documented deployment image used by the repo docs and compose examples, and
make sure the build/push job in the workflow points to the same repository/name
as the deployed image rather than yeranshuanghua/shuanghua-api; if this workflow
is intended only as a personal mirror, remove the main branch push trigger and
keep it manual or fork-scoped. Also verify the related build/push steps later in
the workflow stay consistent with this image name.
- Around line 17-18: The checkout step in the docker-hub-user workflow is
leaving GitHub credentials in the workspace, which can get copied into the
Docker build context. Update the existing actions/checkout usage in the checkout
step to disable persisted credentials so no token remains after checkout,
keeping the workspace clean before the Docker build runs.
In `@controller/model.go`:
- Around line 172-189: The Gemini model mapping in buildGeminiModel only
recognizes a narrow set of embedding prefixes, so some embedding variants are
incorrectly marked as chat models. Update the prefix detection logic in
buildGeminiModel to classify all configured embedding model names, including
newer Gemini embedding variants like gemini-embedding-exp-03-07 and other
text-embedding-* forms, so SupportedGenerationMethods is set to
embedContent/batchEmbedContents instead of generateContent/countTokens.
---
Nitpick comments:
In `@controller/billing_test.go`:
- Around line 78-115: Add coverage in GetCredits tests for the remaining billing
branches: verify that the credits calculation honors the UnlimitedQuota
override, and add a negative test for the lookup failure path that returns the
JSON error response. Use the existing
TestGetCreditsUsesTokenRemainingQuotaWhenTokenStatsEnabled,
TestGetCreditsUsesUserQuotaWhenTokenStatsDisabled, and requestCredits helpers to
locate the behavior, and assert the expected TotalUsage or error payload for the
token/user fetch failures.
In `@controller/billing.go`:
- Around line 134-142: The quota display conversion switch is duplicated in
controller billing logic and should be centralized to avoid drift. Extract the
shared amount conversion from GetUsage, GetSubscription, and the current billing
flow into a helper such as convertQuotaToDisplayAmount that uses
operation_setting.GetQuotaDisplayType, common.QuotaPerUnit, and
operation_setting.USDExchangeRate, then have each caller use that helper instead
of repeating the switch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 222952e3-1773-4fdb-9a0e-315abee9f5f2
📒 Files selected for processing (11)
.github/workflows/docker-hub-user.ymlcontroller/billing.gocontroller/billing_test.gocontroller/channel-billing.gocontroller/model.gocontroller/model_list_test.godto/pricing.gomiddleware/auth.gorelay/channel/gemini/relay-gemini.gorouter/dashboard.gorouter/relay-router.go
| push: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Align the pushed Docker image with the documented deployment image.
The repo docs and compose examples consume calciumion/new-api:latest, but this push-on-main workflow only publishes yeranshuanghua/shuanghua-api. Main builds will not update the image users are instructed to deploy; if this is only a personal mirror, make it manual/fork-scoped instead.
Proposed fix if this workflow is meant to publish the documented image
username: yeranshuanghua
password: ${{ secrets.DOCKER_HUB }}
@@
tags: |
- yeranshuanghua/shuanghua-api:latest
- yeranshuanghua/shuanghua-api:${{ github.sha }}
+ calciumion/new-api:latest
+ calciumion/new-api:${{ github.sha }}Also applies to: 29-44
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/docker-hub-user.yml around lines 4 - 7, The Docker Hub
publish workflow is pushing the wrong image target for main branch builds.
Update the workflow in docker-hub-user to publish the documented deployment
image used by the repo docs and compose examples, and make sure the build/push
job in the workflow points to the same repository/name as the deployed image
rather than yeranshuanghua/shuanghua-api; if this workflow is intended only as a
personal mirror, remove the main branch push trigger and keep it manual or
fork-scoped. Also verify the related build/push steps later in the workflow stay
consistent with this image name.
| - name: Check out | ||
| uses: actions/checkout@v4 |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Disable persisted checkout credentials before building the Docker context.
actions/checkout persists the GitHub token by default, and this job does not need git credentials after checkout. Keep the token out of the workspace used for the Docker build.
Proposed fix
- name: Check out
uses: actions/checkout@v4
+ with:
+ persist-credentials: false📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - name: Check out | |
| uses: actions/checkout@v4 | |
| - name: Check out | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false |
🧰 Tools
🪛 zizmor (1.26.1)
[warning] 17-18: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/docker-hub-user.yml around lines 17 - 18, The checkout
step in the docker-hub-user workflow is leaving GitHub credentials in the
workspace, which can get copied into the Docker build context. Update the
existing actions/checkout usage in the checkout step to disable persisted
credentials so no token remains after checkout, keeping the workspace clean
before the Docker build runs.
Source: Linters/SAST tools
Important
📝 变更描述 / Description
gemini获取模型给了模型名称解决了无法正确拉取模型列表的bug,增加了一个地址,是rikkahub默认获取余额的地址,方便rikkahub用户查询余额
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit
GET /v1/creditswith OpenAI-styledata.total_usage, using the correct remaining-quota source.ListModelsto return a more native model payload with supported generation methods./v1/modelshandling and token-key extraction./v1/creditsand GeminiListModelsresponse shape.docker-compose.ymlto use the fork’s Docker image tag.