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:
kimlym
2023-04-05 12:26:02 +08:00
committed by GitHub
parent 3364289034
commit 5a9b460033
2 changed files with 18 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import { CONFIG_MODES, getConfig } from './commands/config';
const config = getConfig();
let apiKey = config?.OPENAI_API_KEY;
let basePath = config?.OPENAI_BASE_PATH;
const [command, mode] = process.argv.slice(2);
@@ -32,8 +33,14 @@ class OpenAi {
private openAiApiConfiguration = new OpenAiApiConfiguration({
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 (
messages: Array<ChatCompletionRequestMessage>