Repository navigation
feat[Go] add max_dimension and dimensions for ModelRequest - #16019
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)
📝 WalkthroughWalkthrough
ChangesTenant-scoped model overrides via TenantModel.Extra
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/service/model_service.go (1)
2127-2162:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPersist all requested model types in tenant extra.
ModelRequest.ModelTypesaccepts multiple values, butextra["model_types"]stores only[]string{modelType}aftermodelType := model.ModelTypes[0]. SincemodelInfoWithTenantExtranow treatsextra.model_typesas the resolved metadata override, additional requested capabilities are silently dropped.Proposed fix
for _, model := range request.Models { modelName := strings.TrimSpace(model.ModelName) if len(model.ModelTypes) == 0 { return common.CodeBadRequest, errors.New("model types is required") } - modelType := strings.TrimSpace(model.ModelTypes[0]) + modelTypes := make([]string, 0, len(model.ModelTypes)) + for _, mt := range model.ModelTypes { + mt = strings.TrimSpace(mt) + if mt == "" { + return common.CodeBadRequest, errors.New("model type is required") + } + modelTypes = append(modelTypes, mt) + } + modelType := modelTypes[0] if modelName == "" { return common.CodeBadRequest, errors.New("model name is required") } - if modelType == "" { - return common.CodeBadRequest, errors.New("model type is required") - } duplicateKey := strings.ToLower(modelName) @@ extra := map[string]interface{}{ "max_tokens": model.MaxTokens, - "model_types": []string{modelType}, + "model_types": modelTypes, "max_dimension": model.MaxDimension, "dimensions": model.Dimensions, }🤖 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 `@internal/service/model_service.go` around lines 2127 - 2162, The code currently extracts only the first model type from model.ModelTypes (via modelType := strings.TrimSpace(model.ModelTypes[0])) and stores only that single type in extra["model_types"] as []string{modelType}. To fix this, instead of extracting just modelType from the first element, iterate through all elements in model.ModelTypes, trim each one, validate that none are empty, collect them into a slice, and assign that complete slice to extra["model_types"]. This ensures all requested model types from the request are persisted in the tenant extra metadata, not just the first one.
🤖 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 `@internal/service/model_service.go`:
- Around line 2453-2464: In the getModelConfig function, the error handling for
the modelDAO.GetModelByProviderIDAndInstanceIDAndModelName call is too
permissive. Currently it falls back to factory lookup on any error, which
silently ignores transient database failures and malformed tenant rows. Change
the condition from checking if err != nil to only falling back when err equals
gorm.ErrRecordNotFound, matching the stricter behavior of
GetModelConfigFromProviderInstance. This ensures that transient DB failures
propagate properly and tenant-specific max_tokens overrides are not skipped due
to temporary issues.
- Around line 2157-2162: The `dimensions` field in the `extra` map passed to
`TenantModel.Extra` in the `AddModel` method must be validated before being
written, since it becomes the authoritative allow-list during embedding
validation. Add validation logic to ensure all values in the `dimensions` slice
are positive (greater than zero) and do not exceed `model.MaxDimension`. If any
dimension value fails validation, return an appropriate error to prevent bad
enrollment that could later reject valid dimensions or cause metadata
inconsistencies.
---
Outside diff comments:
In `@internal/service/model_service.go`:
- Around line 2127-2162: The code currently extracts only the first model type
from model.ModelTypes (via modelType := strings.TrimSpace(model.ModelTypes[0]))
and stores only that single type in extra["model_types"] as []string{modelType}.
To fix this, instead of extracting just modelType from the first element,
iterate through all elements in model.ModelTypes, trim each one, validate that
none are empty, collect them into a slice, and assign that complete slice to
extra["model_types"]. This ensures all requested model types from the request
are persisted in the tenant extra metadata, not just the first one.
🪄 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: f7e03246-a91e-4284-8b8a-0ef87c38ff90
📒 Files selected for processing (2)
internal/service/model_service.gointernal/service/model_service_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16019 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…w#16019) ### What problem does this PR solve? As title ### Type of change - [x] New Feature (non-breaking change which adds functionality)
What problem does this PR solve?
As title
Type of change