Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 21, 2025

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:

  • Define providers once with shared configuration (name, base URL, API key)
  • Add multiple models per provider without duplicating authentication details
  • Manage everything through an intuitive UI in a dedicated "Custom Providers" tab
  • Maintain full backward compatibility with existing custom model setups

Key Features

Provider Management UI

  • New "Custom Providers" tab in popup settings
  • Add, edit, delete, and toggle providers
  • Per-provider model management with display names
  • Provider models automatically appear in the main API Mode dropdown

Example Configuration

// OpenRouter provider with multiple models
{
  id: 'openrouter_main',
  name: 'OpenRouter',
  baseUrl: 'https://openrouter.ai/api/v1/chat/completions',
  apiKey: 'sk-or-v1-abc123...',
  models: [
    { name: 'anthropic/claude-3-opus', displayName: 'Claude 3 Opus', active: true },
    { name: 'openai/gpt-4', displayName: 'GPT-4 via OpenRouter', active: true },
    { name: 'google/gemini-pro', displayName: 'Gemini Pro', active: false }
  ]
}

Technical Implementation

  • Extended configuration schema with customProviders array
  • Enhanced API service to resolve provider configurations
  • Updated model selection system to include provider models
  • Automatic migration from legacy custom model configurations
  • Session support for provider-based model selection

Backward Compatibility

  • Existing customApiKey/customModelApiUrl configurations continue to work
  • Automatic migration creates a "Legacy Custom Model" provider for existing setups
  • Users can gradually adopt the new system without disruption

Benefits

  • Reduced Configuration Overhead: Set API key once per provider instead of per model
  • Better Organization: Group related models under named providers
  • Improved Scalability: Easy to add multiple models from the same API endpoint
  • Enhanced User Experience: Intuitive provider and model management interface

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.

Copy link
Contributor Author

Copilot AI commented Aug 21, 2025

@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>
@Copilot Copilot AI changed the title [WIP] Allow provider-level management for custom models to simplify setup Add provider-level management for custom models to simplify setup Aug 21, 2025
Copilot finished work on behalf of PeterDaveHello August 21, 2025 18:47
@Copilot Copilot AI requested a review from PeterDaveHello August 21, 2025 18:47
@PeterDaveHello PeterDaveHello requested a review from Copilot August 21, 2025 18:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: '',
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
baseUrl: '',
id: null,
name: null,
baseUrl: null,

Copilot uses AI. Check for mistakes.

}, [config.customProviders])

const generateProviderId = (name) => {
return name.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now()
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return name.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now()
const generateProviderId = () => {
return crypto.randomUUID()

Copilot uses AI. Check for mistakes.

}, [config.customProviders])

const generateProviderId = (name) => {
return name.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now()
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
return name.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now()
return name.toLowerCase().replace(/[^a-z0-9_-]/g, '_') + '_' + Date.now()

Copilot uses AI. Check for mistakes.


// Create a provider from the legacy configuration
const legacyProvider = {
id: 'legacy_custom_' + Date.now(),
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow provider-level management for custom models to simplify setup
2 participants