11import * as vscode from 'vscode' ;
22import { createOpenAIApi } from './openai-utils' ;
3+ import { createGeminiAPIClient } from './gemini-utils' ;
34
45/**
56 * Configuration keys used in the AI commit extension.
@@ -19,7 +20,12 @@ export enum ConfigKeys {
1920 AZURE_API_VERSION = 'AZURE_API_VERSION' ,
2021 AI_COMMIT_LANGUAGE = 'AI_COMMIT_LANGUAGE' ,
2122 SYSTEM_PROMPT = 'AI_COMMIT_SYSTEM_PROMPT' ,
22- OPENAI_TEMPERATURE = 'OPENAI_TEMPERATURE'
23+ OPENAI_TEMPERATURE = 'OPENAI_TEMPERATURE' ,
24+
25+ GEMINI_API_KEY = 'GEMINI_API_KEY' ,
26+ GEMINI_MODEL = 'GEMINI_MODEL' ,
27+ GEMINI_TEMPERATURE = 'GEMINI_TEMPERATURE' ,
28+ AI_PROVIDER = 'AI_PROVIDER' ,
2329}
2430
2531/**
@@ -39,7 +45,7 @@ export class ConfigurationManager {
3945
4046 if ( event . affectsConfiguration ( 'ai-commit.OPENAI_BASE_URL' ) ||
4147 event . affectsConfiguration ( 'ai-commit.OPENAI_API_KEY' ) ) {
42- this . updateModelList ( ) ;
48+ this . updateOpenAIModelList ( ) ;
4349 }
4450 }
4551 } ) ;
@@ -67,13 +73,13 @@ export class ConfigurationManager {
6773 /**
6874 * Updates the list of available OpenAI models.
6975 */
70- private async updateModelList ( ) {
76+ private async updateOpenAIModelList ( ) {
7177 try {
7278 const openai = createOpenAIApi ( ) ;
7379 const models = await openai . models . list ( ) ;
7480
7581 // Save available models to extension state
76- await this . context . globalState . update ( 'availableModels ' , models . data . map ( model => model . id ) ) ;
82+ await this . context . globalState . update ( 'availableOpenAIModels ' , models . data . map ( model => model . id ) ) ;
7783
7884 // Get the current selected model
7985 const config = vscode . workspace . getConfiguration ( 'ai-commit' ) ;
@@ -91,12 +97,60 @@ export class ConfigurationManager {
9197
9298 /**
9399 * Retrieves the list of available OpenAI models.
94- * @returns {Promise<string[]> } The list of available models.
100+ * @returns {Promise<string[]> } The list of available OpenAI models.
95101 */
96- public async getAvailableModels ( ) : Promise < string [ ] > {
97- if ( ! this . context . globalState . get < string [ ] > ( 'availableModels ' ) ) {
98- await this . updateModelList ( ) ;
102+ public async getAvailableOpenAIModels ( ) : Promise < string [ ] > {
103+ if ( ! this . context . globalState . get < string [ ] > ( 'availableOpenAIModels ' ) ) {
104+ await this . updateOpenAIModelList ( ) ;
99105 }
100- return this . context . globalState . get < string [ ] > ( 'availableModels ' , [ ] ) ;
106+ return this . context . globalState . get < string [ ] > ( 'availableOpenAIModels ' , [ ] ) ;
101107 }
108+
109+ /**
110+ * @deprecated
111+ * This function is deprecated because Gemini API does not currently support listing models via API.
112+ * We have to wait for this feature to be updated to the gemini library at some point, or find another way.
113+ *
114+ * Updates the list of available Gemini models.
115+ */
116+ /*
117+ private async updateGeminiModelList() {
118+ try {
119+ const geminiAPI = createGeminiAPIClient();
120+ const modelListResponse = await geminiAPI.listModels(); // Gemini API does not currently have a function to get a list of models
121+ const availableModels = modelListResponse.models.map(model => model.name);
122+
123+ // Save available Gemini models to extension global state
124+ await this.context.globalState.update('availableGeminiModels', availableModels);
125+
126+ // Get the currently selected Gemini model
127+ const config = vscode.workspace.getConfiguration('ai-commit');
128+ const currentModel = config.get<string>('GEMINI_MODEL');
129+
130+ // If the current selected Gemini model is not in the available list, set it to a default value
131+ if (currentModel && !availableModels.includes(currentModel)) {
132+ await config.update('GEMINI_MODEL', 'gemini-2.0-flash-001', vscode.ConfigurationTarget.Global);
133+ }
134+
135+ } catch (error) {
136+ console.error('Failed to fetch Gemini models:', error);
137+ }
138+ }
139+ */
140+
141+ /**
142+ * @deprecated
143+ * This function is deprecated because Gemini API does not currently support listing models via API.
144+ *
145+ * Retrieves the list of available Gemini models.
146+ * @returns {Promise<string[]> } The list of available Gemini models.
147+ */
148+ /*
149+ public async getAvailableGeminiModels(): Promise<string[]> {
150+ if (!this.context.globalState.get<string[]>('availableGeminiModels')) {
151+ await this.updateGeminiModelList();
152+ }
153+ return this.context.globalState.get<string[]>('availableGeminiModels', []);
154+ }
155+ */
102156}
0 commit comments