Skip to content

Commit

Permalink
fix(gui): remove prompt length error condition (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 19, 2023
1 parent 8acc15f commit 382316f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
35 changes: 17 additions & 18 deletions gui/src/components/input/PromptInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 { t } = useTranslation();
const tokens = splitPrompt(prompt);
const groups = Math.ceil(tokens.length / PROMPT_GROUP);

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 { t } = useTranslation();
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) => {
Expand Down
5 changes: 1 addition & 4 deletions gui/src/strings/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 382316f

Please sign in to comment.