{$i18n.t('Default Prompt Suggestions')}
{ const files = e.target.files; if (!files || files.length === 0) { return; } let reader = new FileReader(); reader.onload = async (event) => { try { let suggestions = JSON.parse(event.target.result); if ( !Array.isArray(suggestions) || suggestions.some( (s) => !s || typeof s.content !== 'string' || (s.title != null && typeof s.title !== 'string' && (!Array.isArray(s.title) || s.title.some((part) => typeof part !== 'string'))) ) ) throw new Error('Invalid prompt suggestions'); suggestions = suggestions.map((s) => { if (typeof s.title === 'string') { s.title = [s.title, '']; } else if (!Array.isArray(s.title)) { s.title = ['', '']; } return s; }); updateSuggestions([...promptSuggestions, ...suggestions]); } catch (error) { toast.error($i18n.t('Invalid JSON file')); return; } }; reader.readAsText(files[0]); e.target.value = ''; // Reset the input value }} /> {#if promptSuggestions.length} {/if}
{#if _promptSuggestions.length > 0}
{#each _promptSuggestions as prompt, promptIdx}
{ prompt.title[0] = e.currentTarget.value; updateSuggestions(_promptSuggestions); }} /> { prompt.title[1] = e.currentTarget.value; updateSuggestions(_promptSuggestions); }} />
{/each}
{:else}
{$i18n.t('No suggestion prompts')}
{/if}