From 382316f0c9cc21a660718faf757f47822c7240bc Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sun, 19 Mar 2023 17:08:25 -0500 Subject: [PATCH] fix(gui): remove prompt length error condition (#268) --- gui/src/components/input/PromptInput.tsx | 35 ++++++++++++------------ gui/src/strings/en.ts | 5 +--- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/gui/src/components/input/PromptInput.tsx b/gui/src/components/input/PromptInput.tsx index 5d88b37e..475c6c68 100644 --- a/gui/src/components/input/PromptInput.tsx +++ b/gui/src/components/input/PromptInput.tsx @@ -13,33 +13,32 @@ export interface PromptInputProps extends PromptValue { onChange?: Maybe<(value: PromptValue) => void>; } -export const PROMPT_LIMIT = 77; +export const PROMPT_GROUP = 75; + +function splitPrompt(prompt: string): Array { + return prompt + .split(',') + .flatMap((phrase) => phrase.split(' ')) + .map((word) => word.trim()) + .filter((word) => word.length > 0); +} export function PromptInput(props: PromptInputProps) { const { prompt = '', negativePrompt = '' } = props; - const promptLength = prompt.split(' ').length; - const error = promptLength > PROMPT_LIMIT; + + const tokens = splitPrompt(prompt); + const groups = Math.ceil(tokens.length / PROMPT_GROUP); const { t } = useTranslation(); - - function promptHelper() { - const params = { - current: promptLength, - max: PROMPT_LIMIT, - }; - - if (error) { - return t('input.prompt.error.length', params); - } else { - return t('input.prompt.tokens', params); - } - } + const helper = t('input.prompt.tokens', { + groups, + tokens: tokens.length, + }); return { diff --git a/gui/src/strings/en.ts b/gui/src/strings/en.ts index 6b2bac96..2e7e20e1 100644 --- a/gui/src/strings/en.ts +++ b/gui/src/strings/en.ts @@ -30,10 +30,7 @@ export const I18N_STRINGS_EN = { }, }, prompt: { - tokens: 'Tokens: {{current}}/{{max}}', - error: { - length: 'Too many tokens: {{current}}/{{max}}', - }, + tokens: '{{tokens}} tokens, {{groups}} groups', }, }, loading: {