diff --git a/package.json b/package.json index 32f81f6..00c4a94 100644 --- a/package.json +++ b/package.json @@ -168,6 +168,11 @@ "default": 0, "description": "Starting point of the column containing the tag description (if any, e.g. AI-generated).\n0 to make it adaptive (default, no alignment), a positive number to fix the starting point.\nNote that if the tag previous values take over the specified starting point, the column will be shifted." }, + "jsdoc-generator.generativeEndpoint": { + "type": "string", + "default": "", + "description": "Set your own OpenAI server endpoint for generative AI.\nIt's required only if you wish to use the automatic generation of descriptions." + }, "jsdoc-generator.generativeApiKey": { "type": "string", "default": "", @@ -176,6 +181,7 @@ "jsdoc-generator.generativeModel": { "type": "string", "enum": [ + "custom", "gpt-5", "gpt-5-mini", "gpt-5-nano", @@ -188,7 +194,12 @@ "gpt-o3-mini" ], "default": "gpt-5", - "description": "Generative AI model to use to generate JSDoc decriptions.\nCurrently, only OpenAI models are supported.\nEnable the model with an API key." + "description": "Generative AI model to use to generate JSDoc descriptions.\nFor more models, please select 'custom'.\nEnable the model with an API key." + }, + "jsdoc-generator.generativeModelCustom": { + "type": "string", + "default": "", + "description": "Custom generative AI model to use to generate JSDoc descriptions. Only Enabled while generativeModel select 'custom'." }, "jsdoc-generator.generativeLanguage": { "type": "string", diff --git a/src/GenerativeAPI.ts b/src/GenerativeAPI.ts index e2bb09d..4a85f27 100644 --- a/src/GenerativeAPI.ts +++ b/src/GenerativeAPI.ts @@ -33,6 +33,17 @@ abstract class GenerativeModel { return getConfig('generativeLanguage', 'English'); } + /** + * AI endpoint. + * + * @protected + * @readonly + * @type {string} + */ + protected get baseURL() { + return getConfig('generativeEndpoint', '://api.openai.com/v1'); + } + /** * Model kind. * @@ -41,7 +52,9 @@ abstract class GenerativeModel { * @type {Model} */ protected get model() { - return getConfig('generativeModel', 'gpt-5'); + const model = getConfig('generativeModel', 'gpt-5'); + if (model === 'custom') { return getConfig('generativeModelCustom', 'gpt-5'); } + return model; } /** @@ -123,7 +136,7 @@ class GenerativeOpenAI extends GenerativeModel { * @override */ protected override init(): OpenAI { - return new OpenAI({apiKey: this.apiKey}); + return new OpenAI({baseURL: this.baseURL, apiKey: this.apiKey}); } /** @@ -432,7 +445,9 @@ class GenerativeAPI { * @type {Model} */ protected get model() { - return getConfig('generativeModel', 'gpt-5'); + const model = getConfig('generativeModel', 'gpt-5'); + if (model === 'custom') { return getConfig('generativeModelCustom', 'gpt-5'); } + return model; } /** diff --git a/src/extension.ts b/src/extension.ts index 004cd99..b166414 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -66,7 +66,7 @@ type NodeType = 'function' | 'class' | 'interface' | 'type' | 'enum' | 'property * * @typedef {Model} */ -type Model = 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'gpt-4o' | 'gpt-4o-mini' | 'gpt-o3' | 'gpt-o3-mini'; +type Model = string; /** * JSDoc custom tag. @@ -198,6 +198,12 @@ interface Configuration { * @type {number} */ tagDescriptionColumnStart: number; + /** + * Generative AI Endpoint. + * + * @type {string} + */ + generativeEndpoint: string; /** * Generative AI API key. * @@ -210,6 +216,12 @@ interface Configuration { * @type {Model} */ generativeModel: Model; + /** + * Generative AI model. + * + * @type {Model} + */ + generativeModelCustom: Model; /** * Language of the generated descriptions. *