feat(api.ts): add support for OPENAI_BASE_PATH configuration variable (#80)
feat(config.ts): add OPENAI_BASE_PATH configuration key and validator function Co-authored-by: yiminglu <yiming.lu@mioying.com>
This commit is contained in:
+8
-1
@@ -12,6 +12,7 @@ import { CONFIG_MODES, getConfig } from './commands/config';
|
|||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
|
|
||||||
let apiKey = config?.OPENAI_API_KEY;
|
let apiKey = config?.OPENAI_API_KEY;
|
||||||
|
let basePath = config?.OPENAI_BASE_PATH;
|
||||||
|
|
||||||
const [command, mode] = process.argv.slice(2);
|
const [command, mode] = process.argv.slice(2);
|
||||||
|
|
||||||
@@ -32,8 +33,14 @@ class OpenAi {
|
|||||||
private openAiApiConfiguration = new OpenAiApiConfiguration({
|
private openAiApiConfiguration = new OpenAiApiConfiguration({
|
||||||
apiKey: apiKey
|
apiKey: apiKey
|
||||||
});
|
});
|
||||||
|
private openAI!: OpenAIApi;
|
||||||
|
|
||||||
private openAI = new OpenAIApi(this.openAiApiConfiguration);
|
constructor() {
|
||||||
|
if (basePath) {
|
||||||
|
this.openAiApiConfiguration.basePath = basePath;
|
||||||
|
}
|
||||||
|
this.openAI = new OpenAIApi(this.openAiApiConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
public generateCommitMessage = async (
|
public generateCommitMessage = async (
|
||||||
messages: Array<ChatCompletionRequestMessage>
|
messages: Array<ChatCompletionRequestMessage>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { getI18nLocal } from '../i18n';
|
|||||||
|
|
||||||
export enum CONFIG_KEYS {
|
export enum CONFIG_KEYS {
|
||||||
OPENAI_API_KEY = 'OPENAI_API_KEY',
|
OPENAI_API_KEY = 'OPENAI_API_KEY',
|
||||||
|
OPENAI_BASE_PATH = 'OPENAI_BASE_PATH',
|
||||||
description = 'description',
|
description = 'description',
|
||||||
emoji = 'emoji',
|
emoji = 'emoji',
|
||||||
language = 'language'
|
language = 'language'
|
||||||
@@ -78,6 +79,15 @@ export const configValidators = {
|
|||||||
`${value} is not supported yet`
|
`${value} is not supported yet`
|
||||||
);
|
);
|
||||||
return getI18nLocal(value);
|
return getI18nLocal(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
[CONFIG_KEYS.OPENAI_BASE_PATH](value: any) {
|
||||||
|
validateConfig(
|
||||||
|
CONFIG_KEYS.OPENAI_BASE_PATH,
|
||||||
|
typeof value == 'string',
|
||||||
|
`${value} is not supported yet`
|
||||||
|
);
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user