From 13015a9033d5fc9ecfb1c78837c7d2e9a0d064de Mon Sep 17 00:00:00 2001 From: Takuya Ono Date: Sun, 7 May 2023 18:16:32 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(config.ts):=20convert=20stri?= =?UTF-8?q?ng=20value=20to=20number=20in=20OPENAI=5FMAX=5FTOKENS=20validat?= =?UTF-8?q?or=20(#162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The OPENAI_MAX_TOKENS validator now converts a string value to a number before validating it. This ensures that the validator works correctly when a string value is passed in. --- src/commands/config.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/commands/config.ts b/src/commands/config.ts index ed8228c..02b6f0a 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -65,6 +65,15 @@ export const configValidators = { }, [CONFIG_KEYS.OPENAI_MAX_TOKENS](value: any) { + // If the value is a string, convert it to a number. + if (typeof value === 'string') { + value = parseInt(value); + validateConfig( + CONFIG_KEYS.OPENAI_MAX_TOKENS, + !isNaN(value), + 'Must be a number' + ); + } validateConfig( CONFIG_KEYS.OPENAI_MAX_TOKENS, typeof value === 'number',