Add provider-level management for custom models to simplify setup#877
Add provider-level management for custom models to simplify setup#877
Conversation
|
@PeterDaveHello 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
Co-authored-by: PeterDaveHello <3691490+PeterDaveHello@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a provider-level management system for OpenAI-compatible custom models, allowing users to configure multiple models under a single provider with shared API keys and base URLs. This simplifies setup for users who want to manage multiple models from the same provider (e.g., OpenRouter, LocalAI).
- New CustomProviders component with full CRUD operations for provider and model management
- Enhanced API service to support both provider-based and legacy custom model configurations
- Automatic migration from legacy custom model setups to the new provider system
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/model-name-convert.mjs | Extends API mode generation to include provider models with proper metadata |
| src/services/init-session.mjs | Adds provider-related session parameters for model identification |
| src/services/apis/custom-api.mjs | Implements new provider-based API generation with legacy fallback |
| src/popup/sections/GeneralPart.jsx | Updates dependencies to trigger re-renders when custom providers change |
| src/popup/sections/CustomProviders.jsx | New comprehensive UI component for provider and model management |
| src/popup/Popup.jsx | Integrates new Custom Providers tab into the popup interface |
| src/config/index.mjs | Adds provider configuration schema, helper functions, and automatic migration |
| src/background/index.mjs | Updates API execution logic to handle provider-based model selection |
| src/_locales/en/main.json | Adds localization strings for the new provider management interface |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| { | ||
| id: '', | ||
| name: '', | ||
| baseUrl: '', |
There was a problem hiding this comment.
The default configuration contains empty strings for required fields like id, name, and baseUrl. This could lead to issues when the default is accidentally used. Consider using more descriptive placeholder values or null values that would fail fast if used incorrectly.
| baseUrl: '', | |
| id: null, | |
| name: null, | |
| baseUrl: null, |
| }, [config.customProviders]) | ||
|
|
||
| const generateProviderId = (name) => { | ||
| return name.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now() |
There was a problem hiding this comment.
The ID generation function could create duplicate IDs if two providers with the same name are created within the same millisecond. Consider using a more robust ID generation method like crypto.randomUUID() or including additional entropy.
| return name.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now() | |
| const generateProviderId = () => { | |
| return crypto.randomUUID() |
| }, [config.customProviders]) | ||
|
|
||
| const generateProviderId = (name) => { | ||
| return name.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now() |
There was a problem hiding this comment.
[nitpick] The regex pattern [^a-z0-9] will replace valid characters like hyphens with underscores, potentially making IDs less readable. Consider a more permissive pattern like [^a-z0-9_-] to preserve common ID-friendly characters.
| return name.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now() | |
| return name.toLowerCase().replace(/[^a-z0-9_-]/g, '_') + '_' + Date.now() |
|
|
||
| // Create a provider from the legacy configuration | ||
| const legacyProvider = { | ||
| id: 'legacy_custom_' + Date.now(), |
There was a problem hiding this comment.
The migration function uses Date.now() for ID generation, which could create duplicate IDs if migration runs multiple times in quick succession. Consider using a more robust ID generation or checking for existing IDs.
This PR introduces provider-level management for OpenAI-compatible custom models, allowing users to configure multiple models under a single provider with shared API keys and base URLs.
Problem
Previously, each custom model required individual configuration of API key, URL, and model name, making it cumbersome to set up multiple models from the same provider (e.g., multiple models from OpenRouter or a local AI server).
Solution
Added a new Custom Providers system that allows users to:
Key Features
Provider Management UI
Example Configuration
Technical Implementation
customProvidersarrayBackward Compatibility
customApiKey/customModelApiUrlconfigurations continue to workBenefits
This addresses the core issue of configuration duplication while providing a scalable foundation for managing multiple custom model providers.
Fixes #874.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.