2
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
- import { lm } from 'vscode' ;
5
+ import { commands , LanguageModelChatInformation , lm } from 'vscode' ;
6
6
import { IAuthenticationService } from '../../../platform/authentication/common/authentication' ;
7
7
import { ConfigKey , IConfigurationService } from '../../../platform/configuration/common/configurationService' ;
8
8
import { ICAPIClientService } from '../../../platform/endpoint/common/capiClient' ;
@@ -11,7 +11,7 @@ import { ILogService } from '../../../platform/log/common/logService';
11
11
import { IFetcherService } from '../../../platform/networking/common/fetcherService' ;
12
12
import { Disposable } from '../../../util/vs/base/common/lifecycle' ;
13
13
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation' ;
14
- import { BYOKKnownModels , isBYOKEnabled } from '../../byok/common/byokProvider' ;
14
+ import { BYOKKnownModels , BYOKModelProvider , isBYOKEnabled } from '../../byok/common/byokProvider' ;
15
15
import { IExtensionContribution } from '../../common/contributions' ;
16
16
import { AnthropicLMProvider } from './anthropicProvider' ;
17
17
import { AzureBYOKModelProvider } from './azureProvider' ;
@@ -25,6 +25,7 @@ import { OpenRouterLMProvider } from './openRouterProvider';
25
25
export class BYOKContrib extends Disposable implements IExtensionContribution {
26
26
public readonly id : string = 'byok-contribution' ;
27
27
private readonly _byokStorageService : IBYOKStorageService ;
28
+ private readonly _providers : Map < string , BYOKModelProvider < LanguageModelChatInformation > > = new Map ( ) ;
28
29
29
30
constructor (
30
31
@IFetcherService private readonly _fetcherService : IFetcherService ,
@@ -36,6 +37,12 @@ export class BYOKContrib extends Disposable implements IExtensionContribution {
36
37
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
37
38
) {
38
39
super ( ) ;
40
+ this . _register ( commands . registerCommand ( 'github.copilot.chat.manageBYOK' , async ( vendor : string ) => {
41
+ const provider = this . _providers . get ( vendor ) ;
42
+ if ( provider ) {
43
+ await provider . updateAPIKey ( ) ;
44
+ }
45
+ } ) ) ;
39
46
this . _byokStorageService = new BYOKStorageService ( extensionContext ) ;
40
47
this . _authChange ( authService , this . _instantiationService ) ;
41
48
@@ -48,13 +55,17 @@ export class BYOKContrib extends Disposable implements IExtensionContribution {
48
55
if ( authService . copilotToken && isBYOKEnabled ( authService . copilotToken , this . _capiClientService ) ) {
49
56
// Update known models list from CDN so all providers have the same list
50
57
const knownModels = await this . fetchKnownModelList ( this . _fetcherService ) ;
51
- this . _store . add ( lm . registerChatModelProvider ( OllamaLMProvider . providerName . toLowerCase ( ) , this . _instantiationService . createInstance ( OllamaLMProvider , this . _configurationService . getConfig ( ConfigKey . OllamaEndpoint ) , this . _byokStorageService ) ) ) ;
52
- this . _store . add ( lm . registerChatModelProvider ( AnthropicLMProvider . providerName . toLowerCase ( ) , this . _instantiationService . createInstance ( AnthropicLMProvider , knownModels [ AnthropicLMProvider . providerName ] , this . _byokStorageService ) ) ) ;
53
- this . _store . add ( lm . registerChatModelProvider ( GroqBYOKLMProvider . providerName . toLowerCase ( ) , this . _instantiationService . createInstance ( GroqBYOKLMProvider , knownModels [ GroqBYOKLMProvider . providerName ] , this . _byokStorageService ) ) ) ;
54
- this . _store . add ( lm . registerChatModelProvider ( GeminiBYOKLMProvider . providerName . toLowerCase ( ) , this . _instantiationService . createInstance ( GeminiBYOKLMProvider , knownModels [ GeminiBYOKLMProvider . providerName ] , this . _byokStorageService ) ) ) ;
55
- this . _store . add ( lm . registerChatModelProvider ( OAIBYOKLMProvider . providerName . toLowerCase ( ) , this . _instantiationService . createInstance ( OAIBYOKLMProvider , knownModels [ OAIBYOKLMProvider . providerName ] , this . _byokStorageService ) ) ) ;
56
- this . _store . add ( lm . registerChatModelProvider ( OpenRouterLMProvider . providerName . toLowerCase ( ) , this . _instantiationService . createInstance ( OpenRouterLMProvider , this . _byokStorageService ) ) ) ;
57
- this . _store . add ( lm . registerChatModelProvider ( 'azure' , this . _instantiationService . createInstance ( AzureBYOKModelProvider , this . _byokStorageService ) ) ) ;
58
+ this . _providers . set ( OllamaLMProvider . providerName . toLowerCase ( ) , instantiationService . createInstance ( OllamaLMProvider , this . _configurationService . getConfig ( ConfigKey . OllamaEndpoint ) , this . _byokStorageService ) ) ;
59
+ this . _providers . set ( AnthropicLMProvider . providerName . toLowerCase ( ) , instantiationService . createInstance ( AnthropicLMProvider , knownModels [ AnthropicLMProvider . providerName ] , this . _byokStorageService ) ) ;
60
+ this . _providers . set ( GroqBYOKLMProvider . providerName . toLowerCase ( ) , instantiationService . createInstance ( GroqBYOKLMProvider , knownModels [ GroqBYOKLMProvider . providerName ] , this . _byokStorageService ) ) ;
61
+ this . _providers . set ( GeminiBYOKLMProvider . providerName . toLowerCase ( ) , instantiationService . createInstance ( GeminiBYOKLMProvider , knownModels [ GeminiBYOKLMProvider . providerName ] , this . _byokStorageService ) ) ;
62
+ this . _providers . set ( OAIBYOKLMProvider . providerName . toLowerCase ( ) , instantiationService . createInstance ( OAIBYOKLMProvider , knownModels [ OAIBYOKLMProvider . providerName ] , this . _byokStorageService ) ) ;
63
+ this . _providers . set ( OpenRouterLMProvider . providerName . toLowerCase ( ) , instantiationService . createInstance ( OpenRouterLMProvider , this . _byokStorageService ) ) ;
64
+ this . _providers . set ( AzureBYOKModelProvider . providerName . toLowerCase ( ) , instantiationService . createInstance ( AzureBYOKModelProvider , this . _byokStorageService ) ) ;
65
+
66
+ for ( const [ providerName , provider ] of this . _providers ) {
67
+ this . _store . add ( lm . registerChatModelProvider ( providerName , provider ) ) ;
68
+ }
58
69
}
59
70
}
60
71
private async fetchKnownModelList ( fetcherService : IFetcherService ) : Promise < Record < string , BYOKKnownModels > > {
0 commit comments