Repository navigation
feat: unify provider id or name routing - #16336
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 (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughProvider and instance endpoints now accept ID-or-name path parameters. Service methods resolve providers and instances by ID first, then name, and tenant provider lookup gained a provider-ID helper. ChangesProvider and instance identifier resolution
Sequence Diagram(s)sequenceDiagram
participant ChatRoute as "provider_api.chat_to_model"
participant ChatService as "provider_api_service.chat_to_model"
participant ProviderLookup as "TenantModelProviderService.get_by_tenant_id_and_provider_id"
participant TenantModelProvider
ChatRoute->>ChatService: provider_id_or_name, instance_id_or_name
ChatService->>ProviderLookup: lookup tenant_id and provider_id
ProviderLookup->>TenantModelProvider: get_or_none(tenant_id, id)
TenantModelProvider-->>ProviderLookup: provider row or null
ProviderLookup-->>ChatService: resolved provider
ChatService->>ChatService: resolve instance_id_or_name and build composite_name
ChatService-->>ChatRoute: chat response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/apps/restful_apis/provider_api.py (1)
515-566: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winReject wrong body types before dispatching to the service layer.
These handlers only check that keys exist. If a client sends
"instances": "abc"or"model_name": "gpt-4", "model_type": "chat", the downstream service code will iterate characters and attempt bogus deletes/updates instead of returning a 400. Please switch these request bodies to Pydantic models so the new ID-or-name routes validate shape and type up front. As per coding guidelines,api/apps/restful_apis/**/*.py: Use Pydantic request validation in RESTful APIs.Also applies to: 633-685
🤖 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 `@api/apps/restful_apis/provider_api.py` around lines 515 - 566, The request handlers are only checking for required keys and can accept wrong body types, so invalid payloads slip through to the service layer. Update drop_provider_instances and the other ID-or-name handler in provider_api to use Pydantic request models instead of raw request.get_json() dict checks, so fields like instances/model_name/model_type are validated for shape and type before calling provider_api_service. Keep the existing error handling, but let the model validation return 400s for malformed bodies.Source: Coding guidelines
🧹 Nitpick comments (1)
api/apps/services/provider_api_service.py (1)
190-194: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftExtract and log the ID-or-name resolution path once.
This PR copies the same provider/instance resolution branch across most service methods, but none of the new paths record whether resolution hit by ID, fell back to name, or failed. Centralizing that logic would reduce drift and give you one place to add the logging this new flow needs. As per coding guidelines,
**/*.py: Add logging for new flows.Also applies to: 217-220, 262-266, 313-317, 364-368, 409-423, 572-586, 608-629, 701-726, 735-748, 773-786, 835-850, 904-918
🤖 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 `@api/apps/services/provider_api_service.py` around lines 190 - 194, Centralize the repeated provider_id_or_name resolution in ProviderApiService so the ID-or-name path is extracted once and logged consistently. Move the shared lookup logic used around provider_obj/provider_name/fac_list into a single helper in ProviderApiService, and have each caller use it so you can log whether get_by_id resolved by ID, fell back to the raw name, or failed. Add logging in that helper for the new flow and update the affected service methods to call it instead of duplicating the branch.Source: Coding guidelines
🤖 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 `@api/apps/services/provider_api_service.py`:
- Around line 173-179: The provider cleanup flow in provider_api_service is
returning early in the instance-removal path, which prevents deleting the
TenantModelProviderService record when a provider has no remaining instances.
Update the logic around get_all_by_provider_id in the delete-provider flow so it
still calls TenantModelProviderService.delete_by_tenant_id_and_provider_name
even when instance_objs is empty, while only skipping
delete_models_by_instance_ids and delete_instances_by_provider_ids when there
are no instance IDs to remove.
---
Outside diff comments:
In `@api/apps/restful_apis/provider_api.py`:
- Around line 515-566: The request handlers are only checking for required keys
and can accept wrong body types, so invalid payloads slip through to the service
layer. Update drop_provider_instances and the other ID-or-name handler in
provider_api to use Pydantic request models instead of raw request.get_json()
dict checks, so fields like instances/model_name/model_type are validated for
shape and type before calling provider_api_service. Keep the existing error
handling, but let the model validation return 400s for malformed bodies.
---
Nitpick comments:
In `@api/apps/services/provider_api_service.py`:
- Around line 190-194: Centralize the repeated provider_id_or_name resolution in
ProviderApiService so the ID-or-name path is extracted once and logged
consistently. Move the shared lookup logic used around
provider_obj/provider_name/fac_list into a single helper in ProviderApiService,
and have each caller use it so you can log whether get_by_id resolved by ID,
fell back to the raw name, or failed. Add logging in that helper for the new
flow and update the affected service methods to call it instead of duplicating
the branch.
🪄 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: d4a65f4d-489e-4342-8ef1-cd1bd3f52c72
📒 Files selected for processing (3)
api/apps/restful_apis/provider_api.pyapi/apps/services/provider_api_service.pyapi/db/services/tenant_model_provider_service.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16336 +/- ##
=======================================
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:
|
What problem does this PR solve?
Unifies provider and instance-related provider API routes to accept either an ID or a name.
Type of change