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:
+3
-1
@@ -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,
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user