From 09a3196324b6b9094852c9a990d2a9346f779cda Mon Sep 17 00:00:00 2001 From: WenjiaoYue Date: Wed, 31 Jul 2024 09:33:09 +0800 Subject: [PATCH] Added the ChatQnA delete feature, and updated the corresponding README (#471) Signed-off-by: Yue, Wenjiao --- ChatQnA/docker/ui/svelte/.env | 6 +- ChatQnA/docker/ui/svelte/README.md | 10 ++- .../src/lib/assets/upload/deleteIcon.svelte | 22 ++++++ .../svelte/src/lib/network/upload/Network.ts | 57 ++++++++------- .../components/doc_management/docCard.svelte | 72 ++++++++++++++++++- .../components/upload/uploadFile.svelte | 4 +- 6 files changed, 136 insertions(+), 35 deletions(-) create mode 100644 ChatQnA/docker/ui/svelte/src/lib/assets/upload/deleteIcon.svelte diff --git a/ChatQnA/docker/ui/svelte/.env b/ChatQnA/docker/ui/svelte/.env index 48800b591..1f1eb0acc 100644 --- a/ChatQnA/docker/ui/svelte/.env +++ b/ChatQnA/docker/ui/svelte/.env @@ -1,5 +1,7 @@ CHAT_BASE_URL = 'http://backend_address:8888/v1/chatqna' -UPLOAD_FILE_BASE_URL = 'http://backend_address:6002/v1/dataprep' +UPLOAD_FILE_BASE_URL = 'http://backend_address:6007/v1/dataprep' -GET_FILE = 'http://backend_address:6001/v1/dataprep/get_file' \ No newline at end of file +GET_FILE = 'http://backend_address:6008/v1/dataprep/get_file' + +DELETE_FILE = 'http://backend_address:6009/v1/dataprep/delete_file' diff --git a/ChatQnA/docker/ui/svelte/README.md b/ChatQnA/docker/ui/svelte/README.md index 177807fa0..ec6a31432 100644 --- a/ChatQnA/docker/ui/svelte/README.md +++ b/ChatQnA/docker/ui/svelte/README.md @@ -11,11 +11,12 @@ Here're some of the project's features: - Start a Text Chat:Initiate a text chat with the ability to input written conversations, where the dialogue content can also be customized based on uploaded files. -- Upload File: The choice between uploading locally or copying a remote link. Chat according to uploaded knowledge base. - Clear: Clear the record of the current dialog box without retaining the contents of the dialog box. - Chat history: Historical chat records can still be retained after refreshing, making it easier for users to view the context. - Scroll to Bottom / Top: The chat automatically slides to the bottom. Users can also click the top icon to slide to the top of the chat record. - End to End Time: Shows the time spent on the current conversation. +- Upload File: The choice between uploading locally or copying a remote link. Chat according to uploaded knowledge base. +- Delete File: Delete a certain uploaded file. ## 🛠️ Get it Running @@ -26,9 +27,14 @@ Here're some of the project's features: 3. Modify the required .env variables. ``` - DOC_BASE_URL = '' + CHAT_BASE_URL = '' UPLOAD_FILE_BASE_URL = '' + + GET_FILE = '' + + DELETE_FILE = '' + ``` 4. Execute `npm install` to install the corresponding dependencies. diff --git a/ChatQnA/docker/ui/svelte/src/lib/assets/upload/deleteIcon.svelte b/ChatQnA/docker/ui/svelte/src/lib/assets/upload/deleteIcon.svelte new file mode 100644 index 000000000..2ca57ed8a --- /dev/null +++ b/ChatQnA/docker/ui/svelte/src/lib/assets/upload/deleteIcon.svelte @@ -0,0 +1,22 @@ + + + diff --git a/ChatQnA/docker/ui/svelte/src/lib/network/upload/Network.ts b/ChatQnA/docker/ui/svelte/src/lib/network/upload/Network.ts index a49a33174..a9c76462a 100644 --- a/ChatQnA/docker/ui/svelte/src/lib/network/upload/Network.ts +++ b/ChatQnA/docker/ui/svelte/src/lib/network/upload/Network.ts @@ -16,6 +16,20 @@ import { env } from "$env/dynamic/public"; const UPLOAD_FILE_BASE_URL = env.UPLOAD_FILE_BASE_URL; const GET_FILE = env.GET_FILE; +const DELETE_FILE = env.DELETE_FILE; + +async function fetchFunc(url, init) { + try { + const response = await fetch(url, init); + if (!response.ok) throw response.status; + + return await response.json(); + } catch (error) { + console.error("network error: ", error); + + return undefined; + } +} export async function fetchKnowledgeBaseId(file: Blob, fileName: string) { const url = `${UPLOAD_FILE_BASE_URL}`; @@ -26,14 +40,7 @@ export async function fetchKnowledgeBaseId(file: Blob, fileName: string) { body: formData, }; - try { - const response = await fetch(url, init); - if (!response.ok) throw response.status; - return await response.json(); - } catch (error) { - console.error("network error: ", error); - return undefined; - } + return fetchFunc(url, init); } export async function fetchKnowledgeBaseIdByPaste(pasteUrlList: any) { @@ -45,33 +52,31 @@ export async function fetchKnowledgeBaseIdByPaste(pasteUrlList: any) { body: formData, }; - try { - const response = await fetch(url, init); - if (!response.ok) throw response.status; - return await response.json(); - } catch (error) { - console.error("network error: ", error); - return undefined; - } + return fetchFunc(url, init); } export async function fetchAllFile() { + const url = `${GET_FILE}`; + const init: RequestInit = { + method: "POST", + headers: { "Content-Type": "application/json" }, + }; + + return fetchFunc(url, init); +} + +export async function deleteFiles(path) { + const UploadKnowledge_URL = DELETE_FILE; + const data = { - knowledge_base_id: "default", + file_path: path, }; - const url = `${GET_FILE}`; + const init: RequestInit = { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), }; - try { - const response = await fetch(url, init); - if (!response.ok) throw response.status; - return await response.json(); - } catch (error) { - console.error("network error: ", error); - return undefined; - } + return fetchFunc(UploadKnowledge_URL, init); } diff --git a/ChatQnA/docker/ui/svelte/src/lib/shared/components/doc_management/docCard.svelte b/ChatQnA/docker/ui/svelte/src/lib/shared/components/doc_management/docCard.svelte index ffd69d30b..451ee8e3c 100644 --- a/ChatQnA/docker/ui/svelte/src/lib/shared/components/doc_management/docCard.svelte +++ b/ChatQnA/docker/ui/svelte/src/lib/shared/components/doc_management/docCard.svelte @@ -3,18 +3,34 @@ SPDX-License-Identifier: Apache-2.0 --> -
+
+ +
+

Confirm file deletion?

+ + +
-
+
{#each files as file, index}
{/if} + + +
{/each}
diff --git a/ChatQnA/docker/ui/svelte/src/lib/shared/components/upload/uploadFile.svelte b/ChatQnA/docker/ui/svelte/src/lib/shared/components/upload/uploadFile.svelte index cf49fccde..541e11559 100644 --- a/ChatQnA/docker/ui/svelte/src/lib/shared/components/upload/uploadFile.svelte +++ b/ChatQnA/docker/ui/svelte/src/lib/shared/components/upload/uploadFile.svelte @@ -168,7 +168,7 @@ {#if uploading} -
+
{/if} @@ -176,7 +176,7 @@ {#if files.length > 0} {:else} -
+

No files uploaded