dev: Standardized OpenAI config format and updated documentation issue #1180 (#1195)
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test (18.x) (push) Has been cancelled
test / test (20.x) (push) Has been cancelled
test / test (22.x) (push) Has been cancelled

* Standardized OpenAI config format and updated documentation issue #1180

* Addressed review comments
This commit is contained in:
Anuja Mishra
2025-03-20 22:20:51 +05:30
committed by GitHub
parent 33a7811e8f
commit 50817f601e
3 changed files with 48 additions and 6 deletions
@@ -52,15 +52,36 @@ class OpenAICompletionService extends BaseService {
* @returns {Promise<void>} Resolves when initialization is complete
* @private
*/
//New Updated Code (with backward compatibility)
//issue: #1180
async _init () {
const sk_key =
this.config?.openai?.secret_key ??
this.global_config.openai?.secret_key;
// Check for the new format under `services.openai.apiKey`
let apiKey =
this.config?.services?.openai?.apiKey ??
this.global_config?.services?.openai?.apiKey;
// Fallback to the old format for backward compatibility
if (!apiKey) {
apiKey =
this.config?.openai?.secret_key ??
this.global_config?.openai?.secret_key;
// Log a warning to inform users about the deprecated format
this.log.warn(
'The `openai.secret_key` configuration format is deprecated. ' +
'Please use `services.openai.apiKey` instead.'
);
}
if (!apiKey) {
throw new Error('OpenAI API key is missing in configuration.');
}
this.openai = new this.modules.openai.OpenAI({
apiKey: sk_key
apiKey: apiKey
});
const svc_aiChat = this.services.get('ai-chat');
svc_aiChat.register_provider({
service_name: this.service_name,
@@ -0,0 +1,19 @@
# Configuring AI Services
AI services are configured under the `services` block in the configuration file. Each service requires an `apiKey` to authenticate requests.
## Example Configuration
```json
{
"services": {
"openai": {
"apiKey": "sk-abcdefg..."
},
"deepseek": {
"apiKey": "sk-xyz123..."
},
"other-ai-service": {
"apiKey": "sk-hijklmn..."
}
}
}
@@ -0,0 +1,2 @@
## AI Services Configuration
For details on configuring AI services, see [AI Services Configuration](ai-services-config.md).