From 29dd973db95d02f21b866b7da3dbf74d82bc2e9d Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 22 Jan 2024 22:18:12 -0800 Subject: [PATCH] refac: frontend supported file extensions --- src/lib/components/chat/MessageInput.svelte | 18 +++++++++++------- src/lib/constants.ts | 4 +++- src/routes/(app)/documents/+page.svelte | 14 +++++++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index ff82d606..72452b3b 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -8,7 +8,7 @@ import Suggestions from './MessageInput/Suggestions.svelte'; import { uploadDocToVectorDB } from '$lib/apis/rag'; import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte'; - import { SUPPORTED_FILE_TYPE } from '$lib/constants'; + import { SUPPORTED_FILE_TYPE, SUPPORTED_FILE_EXTENSIONS } from '$lib/constants'; import Documents from './MessageInput/Documents.svelte'; import Models from './MessageInput/Models.svelte'; @@ -169,11 +169,13 @@ reader.readAsDataURL(file); } else if ( SUPPORTED_FILE_TYPE.includes(file['type']) || - ['md'].includes(file.name.split('.').at(-1)) + SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) ) { uploadDoc(file); } else { - toast.error(`Unknown File Type '${file['type']}', but accepting and treating as plain text`); + toast.error( + `Unknown File Type '${file['type']}', but accepting and treating as plain text` + ); uploadDoc(file); } } else { @@ -304,12 +306,14 @@ reader.readAsDataURL(file); } else if ( SUPPORTED_FILE_TYPE.includes(file['type']) || - ['md'].includes(file.name.split('.').at(-1)) + SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) ) { uploadDoc(file); filesInputElement.value = ''; } else { - toast.error(`Unknown File Type '${file['type']}', but accepting and treating as plain text`); + toast.error( + `Unknown File Type '${file['type']}', but accepting and treating as plain text` + ); uploadDoc(file); filesInputElement.value = ''; } @@ -466,8 +470,8 @@ placeholder={chatInputPlaceholder !== '' ? chatInputPlaceholder : speechRecognitionListening - ? 'Listening...' - : 'Send a message'} + ? 'Listening...' + : 'Send a message'} bind:value={prompt} on:keypress={(e) => { if (e.keyCode == 13 && !e.shiftKey) { diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 1d54dae1..0cb66a07 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -21,9 +21,11 @@ export const SUPPORTED_FILE_TYPE = [ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/octet-stream', 'application/x-javascript', - 'text/markdown', + 'text/markdown' ]; +export const SUPPORTED_FILE_EXTENSIONS = ['md', 'rst']; + // Source: https://kit.svelte.dev/docs/modules#$env-static-public // This feature, akin to $env/static/private, exclusively incorporates environment variables // that are prefixed with config.kit.env.publicPrefix (usually set to PUBLIC_). diff --git a/src/routes/(app)/documents/+page.svelte b/src/routes/(app)/documents/+page.svelte index 597220b5..f5b8e5ec 100644 --- a/src/routes/(app)/documents/+page.svelte +++ b/src/routes/(app)/documents/+page.svelte @@ -7,7 +7,7 @@ import { documents } from '$lib/stores'; import { createNewDoc, deleteDocByName, getDocs } from '$lib/apis/documents'; - import { SUPPORTED_FILE_TYPE } from '$lib/constants'; + import { SUPPORTED_FILE_TYPE, SUPPORTED_FILE_EXTENSIONS } from '$lib/constants'; import { uploadDocToVectorDB } from '$lib/apis/rag'; import { transformFileName } from '$lib/utils'; @@ -69,11 +69,13 @@ const file = inputFiles[0]; if ( SUPPORTED_FILE_TYPE.includes(file['type']) || - ['md'].includes(file.name.split('.').at(-1)) + SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) ) { uploadDoc(file); } else { - toast.error(`Unknown File Type '${file['type']}', but accepting and treating as plain text`); + toast.error( + `Unknown File Type '${file['type']}', but accepting and treating as plain text` + ); uploadDoc(file); } } else { @@ -150,11 +152,13 @@ const file = inputFiles[0]; if ( SUPPORTED_FILE_TYPE.includes(file['type']) || - ['md'].includes(file.name.split('.').at(-1)) + SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) ) { uploadDoc(file); } else { - toast.error(`Unknown File Type '${file['type']}', but accepting and treating as plain text`); + toast.error( + `Unknown File Type '${file['type']}', but accepting and treating as plain text` + ); uploadDoc(file); }