Skip to content

Conversation

@RedwindA
Copy link
Contributor

@RedwindA RedwindA commented Dec 31, 2025

PR 类型

  • Bug 修复
  • 新功能

PR 是否包含破坏性更新?

PR 描述

MEMORY_CACHE_ENABLED=false 时(不知道为什么有人会搞成false),middleware/distributor.go 的分发流程在选择可用 channel 时会依赖 model.GetChannel 的数据库查询结果。此时如果请求的 model 名称需要通过 setting/ratio_setting/model_ratio.goFormatMatchingModelName 做匹配/归一化,原始查询可能返回空结果,从而导致分发失败。

本 PR 在 model/ability.goGetChannel 中增加兜底逻辑:当首次查询返回空(或失败)时,使用 FormatMatchingModelName(model) 的结果再查询一次;仅当兜底查询成功时才覆盖原结果/错误,避免掩盖真实错误。这样即使关闭内存缓存,也能正确匹配到按 ratio 设置归一化后的模型名并完成分发。

Summary by CodeRabbit

  • Refactor
    • Improved internal ability query logic with enhanced fallback handling for model name normalization to increase robustness when resolving model-related operations.

✏️ Tip: You can customize this high-level summary in your review settings.

When MEMORY_CACHE_ENABLED is false, channel selection can rely on DB queries
via model.GetChannel. If the request model should be normalized by
ratio_setting.FormatMatchingModelName, the initial ability query may return
empty and routing fails.

Add a fallback ability query using the formatted model name, and only
override the original error when the fallback succeeds.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 31, 2025

Walkthrough

A helper function queryAbilities is introduced to encapsulate the channel-ability fetch logic. When GetChannel cannot find abilities for the requested model, it attempts a fallback: normalizing the model name via ratio_setting.FormatMatchingModelName and retrying the query. A dependency on ratio_setting is added to support model name normalization.

Changes

Cohort / File(s) Summary
Core Ability Query Logic
model/ability.go
Extracts channel-ability fetch into internal queryAbilities helper. Adds fallback in GetChannel: on empty/failed query, normalizes model name and retries; clears error if fallback succeeds.
Dependency Management
go.mod
Adds or updates dependency for ratio_setting module to support model name normalization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A query that stumbled, now stands up so tall,
With fallback normalization to catch it before the fall,
The abilities hop through, normalized and bright,
A refactored helper keeps the logic just right! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(model): fallback to ratio-formatted model name' clearly and specifically describes the main change: adding a fallback mechanism that uses ratio-formatted model names in the GetChannel function.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant