feat(api.ts, config.ts): add support for custom model selection in OpenAi class

feat(config.ts): add model validation in configValidators
This commit is contained in:
di-sukharev
2023-04-28 15:29:32 +08:00
parent f04757f8af
commit 51613c2aea
2 changed files with 13 additions and 1 deletions
+3 -1
View File
@@ -29,6 +29,8 @@ if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) {
process.exit(1); process.exit(1);
} }
const MODEL = config?.model || 'gpt-3.5-turbo';
class OpenAi { class OpenAi {
private openAiApiConfiguration = new OpenAiApiConfiguration({ private openAiApiConfiguration = new OpenAiApiConfiguration({
apiKey: apiKey apiKey: apiKey
@@ -47,7 +49,7 @@ class OpenAi {
): Promise<string | undefined> => { ): Promise<string | undefined> => {
try { try {
const { data } = await this.openAI.createChatCompletion({ const { data } = await this.openAI.createChatCompletion({
model: 'gpt-3.5-turbo', model: MODEL,
messages, messages,
temperature: 0, temperature: 0,
top_p: 0.1, top_p: 0.1,
+10
View File
@@ -13,6 +13,7 @@ export enum CONFIG_KEYS {
OPENAI_BASE_PATH = 'OPENAI_BASE_PATH', OPENAI_BASE_PATH = 'OPENAI_BASE_PATH',
description = 'description', description = 'description',
emoji = 'emoji', emoji = 'emoji',
model = 'model',
language = 'language' language = 'language'
} }
@@ -88,6 +89,15 @@ export const configValidators = {
`${value} is not supported yet` `${value} is not supported yet`
); );
return value; return value;
},
[CONFIG_KEYS.model](value: any) {
validateConfig(
CONFIG_KEYS.OPENAI_BASE_PATH,
value === 'gpt-3.5-turbo' || value === 'gpt-4',
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
} }
}; };