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>;
}
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) {
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 <Stack spacing={2}>
<TextField
error={error}
label={t('parameter.prompt')}
helperText={promptHelper()}
helperText={helper}
variant='outlined'
value={prompt}
onChange={(event) => {

View File

@ -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: {