Repository navigation
feat: vertex budget control in model name - #1271
Conversation
WalkthroughThe update refines the logic in the Changes
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
relay/channel/vertex/adaptor.go (1)
86-86: Use consistent comment language throughout the codebase.The comment is written in Chinese while the rest of the codebase uses English comments. Consider using English for consistency.
- // 新增逻辑:处理 -thinking-<budget> 格式 + // Handle -thinking-<budget> format for budget control
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
relay/channel/vertex/adaptor.go(1 hunks)
🔇 Additional comments (1)
relay/channel/vertex/adaptor.go (1)
87-94: Logic implementation looks correct for budget control feature.The new logic successfully implements the budget control feature by:
- Detecting the "-thinking-" pattern using
strings.Contains- Extracting the base model name by splitting and taking the first part
- Maintaining backward compatibility with existing "-thinking" and "-nothinking" suffix handling
This approach correctly handles the new naming convention while preserving existing functionality.
| if strings.Contains(info.UpstreamModelName, "-thinking-") { | ||
| parts := strings.Split(info.UpstreamModelName, "-thinking-") | ||
| info.UpstreamModelName = parts[0] | ||
| } else if strings.HasSuffix(info.UpstreamModelName, "-thinking") { // 旧的适配 | ||
| info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-thinking") | ||
| } else if strings.HasSuffix(info.OriginModelName, "-nothinking") { | ||
| } else if strings.HasSuffix(info.UpstreamModelName, "-nothinking") { | ||
| info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-nothinking") | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Consider edge case handling for model names starting with "-thinking-".
The logic correctly handles the new "-thinking-" pattern, but there's a potential edge case: if a model name starts with "-thinking-" (e.g., "-thinking-100"), parts[0] would be an empty string, which could cause issues downstream.
Consider adding validation to ensure the extracted model name is not empty:
if strings.Contains(info.UpstreamModelName, "-thinking-") {
parts := strings.Split(info.UpstreamModelName, "-thinking-")
- info.UpstreamModelName = parts[0]
+ if parts[0] != "" {
+ info.UpstreamModelName = parts[0]
+ }
} else if strings.HasSuffix(info.UpstreamModelName, "-thinking") {
info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-thinking")
} else if strings.HasSuffix(info.UpstreamModelName, "-nothinking") {
info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-nothinking")
}Alternatively, you could use a more robust approach by checking if the substring "-thinking-" is not at the beginning:
- if strings.Contains(info.UpstreamModelName, "-thinking-") {
+ if strings.Contains(info.UpstreamModelName, "-thinking-") && !strings.HasPrefix(info.UpstreamModelName, "-thinking-") {
parts := strings.Split(info.UpstreamModelName, "-thinking-")
info.UpstreamModelName = parts[0]📝 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.
| if strings.Contains(info.UpstreamModelName, "-thinking-") { | |
| parts := strings.Split(info.UpstreamModelName, "-thinking-") | |
| info.UpstreamModelName = parts[0] | |
| } else if strings.HasSuffix(info.UpstreamModelName, "-thinking") { // 旧的适配 | |
| info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-thinking") | |
| } else if strings.HasSuffix(info.OriginModelName, "-nothinking") { | |
| } else if strings.HasSuffix(info.UpstreamModelName, "-nothinking") { | |
| info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-nothinking") | |
| } | |
| if strings.Contains(info.UpstreamModelName, "-thinking-") { | |
| parts := strings.Split(info.UpstreamModelName, "-thinking-") | |
| if parts[0] != "" { | |
| info.UpstreamModelName = parts[0] | |
| } | |
| } else if strings.HasSuffix(info.UpstreamModelName, "-thinking") { // 旧的适配 | |
| info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-thinking") | |
| } else if strings.HasSuffix(info.UpstreamModelName, "-nothinking") { | |
| info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-nothinking") | |
| } |
🤖 Prompt for AI Agents
In relay/channel/vertex/adaptor.go around lines 87 to 94, the current code
splits the model name on "-thinking-" and assigns the first part to
info.UpstreamModelName, but if the model name starts with "-thinking-", this
results in an empty string which can cause issues. To fix this, add a check
after splitting to ensure parts[0] is not empty before assigning it; if it is
empty, handle this case appropriately, such as skipping the assignment or
logging an error. Alternatively, modify the condition to only split if
"-thinking-" is found and is not at the start of the string.
…ontrol feat: vertex budget control in model name
…ontrol feat: vertex budget control in model name
…ontrol feat: vertex budget control in model name
Summary by CodeRabbit