1
0
Fork 0

fix(gui): remove prompt length error condition (#268)

This commit is contained in:
Sean Sube 2023-03-19 17:08:25 -05:00
parent 8acc15f52e
commit 382316f0c9
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 18 additions and 22 deletions

View File

@ -13,33 +13,32 @@ export interface PromptInputProps extends PromptValue {
onChange?: Maybe<(value: PromptValue) => void>; onChange?: Maybe<(value: PromptValue) => void>;
} }
export const PROMPT_LIMIT = 77; export const PROMPT_GROUP = 75;
function splitPrompt(prompt: string): Array<string> {
return prompt
.split(',')
.flatMap((phrase) => phrase.split(' '))
.map((word) => word.trim())
.filter((word) => word.length > 0);
}
export function PromptInput(props: PromptInputProps) { export function PromptInput(props: PromptInputProps) {
const { prompt = '', negativePrompt = '' } = props; 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(); const { t } = useTranslation();
const helper = t('input.prompt.tokens', {
function promptHelper() { groups,
const params = { tokens: tokens.length,
current: promptLength, });
max: PROMPT_LIMIT,
};
if (error) {
return t('input.prompt.error.length', params);
} else {
return t('input.prompt.tokens', params);
}
}
return <Stack spacing={2}> return <Stack spacing={2}>
<TextField <TextField
error={error}
label={t('parameter.prompt')} label={t('parameter.prompt')}
helperText={promptHelper()} helperText={helper}
variant='outlined' variant='outlined'
value={prompt} value={prompt}
onChange={(event) => { onChange={(event) => {

View File

@ -30,10 +30,7 @@ export const I18N_STRINGS_EN = {
}, },
}, },
prompt: { prompt: {
tokens: 'Tokens: {{current}}/{{max}}', tokens: '{{tokens}} tokens, {{groups}} groups',
error: {
length: 'Too many tokens: {{current}}/{{max}}',
},
}, },
}, },
loading: { loading: {