3.4 KiB
Admin Models Auto Model Fix
Summary
Fixed two issues with the admin models page related to the auto model setting for hobby/free plan users:
- Added missing UI: Created the UI elements for setting the auto model for hobby/free plan users
- Fixed model selection logic: Ensured that paid plan users can select their own models without the auto model setting interfering
Changes Made
1. Frontend - admin.html
File: /home/engine/project/chat/public/admin.html
Added a new card section for configuring the auto model for hobby/free plan users:
- Form:
auto-model-form - Select dropdown:
auto-model-select - Status display:
auto-model-status
The UI explains that this setting only affects hobby/free plan users, while paid plan users can select their own models.
2. Backend - server.js
File: /home/engine/project/chat/server.js
Modified the resolvePlanModel() function to fix the model selection logic:
Previous Behavior:
- For paid plans, if configured models existed, it would always return the first configured model, ignoring user selections
New Behavior:
-
For hobby/free plan users:
- Uses the admin-configured
freePlanModelsetting when no specific model is requested - Still allows them to explicitly request specific models if they have a valid tier
- Uses the admin-configured
-
For paid plan users:
- Always respects the user's model selection
- If user requests a model (even without a tier), uses it
- Only falls back to first configured model if user doesn't request anything or requests 'auto'
Test Results
Created comprehensive tests (test_model_resolution.js) that verify:
✓ Hobby users get the auto model when no specific request
✓ Hobby users get the auto model when requesting 'auto'
✓ Hobby users can explicitly request other models
✓ Paid users always get their requested model
✓ Paid users can request models without tiers
✓ Paid users get first configured model when no request
✓ Paid users get first configured model when requesting 'auto'
All 8 test cases pass.
Technical Details
Model Resolution Flow
- Explicit model with tier (not 'auto'): Return requested model immediately
- Hobby/Free plan:
- Check admin's
freePlanModelsetting - Fall back to first configured model
- Fall back to default model
- Check admin's
- Paid plan:
- If specific model requested (not 'auto'), use it
- Otherwise use first configured model
- Fall back to default model
API Integration
The feature integrates with existing API endpoints:
- GET
/api/admin/plan-settings- Retrieves current settings includingfreePlanModel - POST
/api/admin/plan-settings- Saves thefreePlanModelsetting
JavaScript Integration
The admin.js file already had all the necessary handlers:
populateAutoModelOptions()- Populates the dropdown with available models- Form submission handler at lines 1515-1532
- Proper element references at lines 38-40
User Impact
For Admins
- New UI section in Admin Panel → Build models page
- Can configure which model hobby/free users automatically use
- Clear indication that paid users can choose their own models
For Hobby/Free Plan Users
- Automatically assigned the admin-configured model
- Can still explicitly select other models if available
For Paid Plan Users
- Full control over model selection
- Their choices are always respected
- Auto model setting does not affect them