Skip to content

Commit 09a3196

Browse files
authored
Added the ChatQnA delete feature, and updated the corresponding README (#471)
Signed-off-by: Yue, Wenjiao <wenjiao.yue@intel.com>
1 parent 015a2b1 commit 09a3196

File tree

6 files changed

+136
-35
lines changed

6 files changed

+136
-35
lines changed

ChatQnA/docker/ui/svelte/.env

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
CHAT_BASE_URL = 'http://backend_address:8888/v1/chatqna'
22

3-
UPLOAD_FILE_BASE_URL = 'http://backend_address:6002/v1/dataprep'
3+
UPLOAD_FILE_BASE_URL = 'http://backend_address:6007/v1/dataprep'
44

5-
GET_FILE = 'http://backend_address:6001/v1/dataprep/get_file'
5+
GET_FILE = 'http://backend_address:6008/v1/dataprep/get_file'
6+
7+
DELETE_FILE = 'http://backend_address:6009/v1/dataprep/delete_file'

ChatQnA/docker/ui/svelte/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
Here're some of the project's features:
1212

1313
- 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.
14-
- Upload File: The choice between uploading locally or copying a remote link. Chat according to uploaded knowledge base.
1514
- Clear: Clear the record of the current dialog box without retaining the contents of the dialog box.
1615
- Chat history: Historical chat records can still be retained after refreshing, making it easier for users to view the context.
1716
- 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.
1817
- End to End Time: Shows the time spent on the current conversation.
18+
- Upload File: The choice between uploading locally or copying a remote link. Chat according to uploaded knowledge base.
19+
- Delete File: Delete a certain uploaded file.
1920

2021
## 🛠️ Get it Running
2122

@@ -26,9 +27,14 @@ Here're some of the project's features:
2627
3. Modify the required .env variables.
2728

2829
```
29-
DOC_BASE_URL = ''
30+
CHAT_BASE_URL = ''
3031
3132
UPLOAD_FILE_BASE_URL = ''
33+
34+
GET_FILE = ''
35+
36+
DELETE_FILE = ''
37+
3238
```
3339

3440
4. Execute `npm install` to install the corresponding dependencies.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
Copyright (C) 2024 Intel Corporation
3+
SPDX-License-Identifier: Apache-2.0
4+
-->
5+
6+
<svg
7+
t="1711440930029"
8+
class="icon w-5 h-5"
9+
viewBox="0 0 1024 1024"
10+
version="1.1"
11+
xmlns="http://www.w3.org/2000/svg"
12+
p-id="4255"
13+
><path
14+
d="M668.8 896h-320c-48.64 0-88.32-37.76-92.8-87.68L211.2 403.2c-1.92-17.28 10.88-33.28 28.16-35.2 17.28-1.92 33.28 10.88 35.2 28.16l44.16 405.76c1.28 17.28 14.08 30.08 28.8 30.08h320c14.72 0 27.52-12.8 28.8-29.44l44.16-406.4c1.92-17.28 17.92-30.08 35.2-28.16 17.28 1.92 30.08 17.92 28.16 35.2l-44.16 405.76c-2.56 49.28-42.88 87.04-90.88 87.04zM826.24 321.28H190.72c-17.92 0-32-14.08-32-32s14.08-32 32-32h636.16c17.92 0 32 14.08 32 32s-14.72 32-32.64 32z"
15+
fill="#a6adbb"
16+
p-id="4256"
17+
/><path
18+
d="M424.96 789.12c-16.64 0-30.72-12.8-32-29.44l-27.52-347.52c-1.28-17.92 11.52-33.28 29.44-34.56 17.92-1.28 33.28 11.52 34.56 29.44l27.52 347.52c1.28 17.92-11.52 33.28-29.44 34.56h-2.56zM580.48 789.12h-2.56c-17.92-1.28-30.72-16.64-29.44-34.56L576 407.04c1.28-17.92 16.64-30.72 34.56-29.44 17.92 1.28 30.72 16.64 29.44 34.56l-27.52 347.52c-1.92 16.64-15.36 29.44-32 29.44zM581.76 244.48c-17.92 0-32-14.08-32-32 0-23.68-19.2-43.52-43.52-43.52s-43.52 19.2-43.52 43.52c0 17.92-14.08 32-32 32s-32-14.08-32-32c0-59.52 48-107.52 107.52-107.52s107.52 48 107.52 107.52c0 17.28-14.08 32-32 32z"
19+
fill="#a6adbb"
20+
p-id="4257"
21+
/></svg
22+
>

ChatQnA/docker/ui/svelte/src/lib/network/upload/Network.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ import { env } from "$env/dynamic/public";
1616

1717
const UPLOAD_FILE_BASE_URL = env.UPLOAD_FILE_BASE_URL;
1818
const GET_FILE = env.GET_FILE;
19+
const DELETE_FILE = env.DELETE_FILE;
20+
21+
async function fetchFunc(url, init) {
22+
try {
23+
const response = await fetch(url, init);
24+
if (!response.ok) throw response.status;
25+
26+
return await response.json();
27+
} catch (error) {
28+
console.error("network error: ", error);
29+
30+
return undefined;
31+
}
32+
}
1933

2034
export async function fetchKnowledgeBaseId(file: Blob, fileName: string) {
2135
const url = `${UPLOAD_FILE_BASE_URL}`;
@@ -26,14 +40,7 @@ export async function fetchKnowledgeBaseId(file: Blob, fileName: string) {
2640
body: formData,
2741
};
2842

29-
try {
30-
const response = await fetch(url, init);
31-
if (!response.ok) throw response.status;
32-
return await response.json();
33-
} catch (error) {
34-
console.error("network error: ", error);
35-
return undefined;
36-
}
43+
return fetchFunc(url, init);
3744
}
3845

3946
export async function fetchKnowledgeBaseIdByPaste(pasteUrlList: any) {
@@ -45,33 +52,31 @@ export async function fetchKnowledgeBaseIdByPaste(pasteUrlList: any) {
4552
body: formData,
4653
};
4754

48-
try {
49-
const response = await fetch(url, init);
50-
if (!response.ok) throw response.status;
51-
return await response.json();
52-
} catch (error) {
53-
console.error("network error: ", error);
54-
return undefined;
55-
}
55+
return fetchFunc(url, init);
5656
}
5757

5858
export async function fetchAllFile() {
59+
const url = `${GET_FILE}`;
60+
const init: RequestInit = {
61+
method: "POST",
62+
headers: { "Content-Type": "application/json" },
63+
};
64+
65+
return fetchFunc(url, init);
66+
}
67+
68+
export async function deleteFiles(path) {
69+
const UploadKnowledge_URL = DELETE_FILE;
70+
5971
const data = {
60-
knowledge_base_id: "default",
72+
file_path: path,
6173
};
62-
const url = `${GET_FILE}`;
74+
6375
const init: RequestInit = {
6476
method: "POST",
6577
headers: { "Content-Type": "application/json" },
6678
body: JSON.stringify(data),
6779
};
6880

69-
try {
70-
const response = await fetch(url, init);
71-
if (!response.ok) throw response.status;
72-
return await response.json();
73-
} catch (error) {
74-
console.error("network error: ", error);
75-
return undefined;
76-
}
81+
return fetchFunc(UploadKnowledge_URL, init);
7782
}

ChatQnA/docker/ui/svelte/src/lib/shared/components/doc_management/docCard.svelte

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,34 @@
33
SPDX-License-Identifier: Apache-2.0
44
-->
55

6-
<script>
6+
<script lang="ts">
77
import FolderIcon from "$lib/assets/DocManagement/folderIcon.svelte";
88
import LinkfolderIcon from "$lib/assets/DocManagement/LinkfolderIcon.svelte";
9-
import { Modal } from "flowbite-svelte";
9+
import { Button, Modal } from "flowbite-svelte";
1010
import SvelteTree from "$lib/shared/components/doc_management/treeView/svelte-tree.svelte";
1111
import FileIcon from "$lib/assets/DocManagement/fileIcon.svelte";
1212
import { createEventDispatcher } from "svelte";
13+
import DeleteIcon from "$lib/assets/upload/deleteIcon.svelte";
14+
import { deleteFiles } from "$lib/network/upload/Network";
15+
import { storageFiles } from "$lib/shared/stores/common/Store";
16+
import { getNotificationsContext } from "svelte-notifications";
17+
18+
const { addNotification } = getNotificationsContext();
1319
1420
let dispatch = createEventDispatcher();
1521
let showDirectory = false;
1622
let chooseDir = undefined;
1723
let currentIdx = 0;
24+
let deleteModal = false;
25+
/**
26+
* @type {any}
27+
*/
28+
let currentFile;
29+
/**
30+
* @type {number}
31+
*/
32+
let currentFileIdx;
33+
1834
1935
export let files = [];
2036
@@ -27,7 +43,36 @@
2743
console.log("chooseDir", chooseDir);
2844
}
2945
46+
async function deleteCurrentFolder() {
47+
48+
const res = await deleteFiles(currentFile);
49+
// succeed
50+
if (res.status) {
51+
$storageFiles = $storageFiles.filter((_, index) => index !== currentFileIdx);
52+
files = $storageFiles;
53+
showNotification("Deleted successfully", "success");
54+
55+
} else {
56+
showNotification("Deletion failed", "success");
3057
58+
}
59+
}
60+
61+
function showNotification(text: string, type: string) {
62+
addNotification({
63+
text: text,
64+
position: "top-left",
65+
type: type,
66+
removeAfter: 3000,
67+
});
68+
}
69+
70+
function deleteFileIdx(file, index) {
71+
currentFile = file;
72+
currentFileIdx = index;
73+
deleteModal = true;
74+
75+
}
3176
</script>
3277

3378
<Modal
@@ -39,10 +84,23 @@
3984
>
4085
<hr class="my-8 h-px border-0 bg-gray-200 dark:bg-gray-700" />
4186
<SvelteTree data={chooseDir.children} {currentIdx} />
87+
</Modal>
4288

89+
<Modal bind:open={deleteModal} size="xs" autoclose>
90+
<div class="text-center">
91+
<h3 class="mb-5 text-lg font-normal text-gray-500">Confirm file deletion?</h3>
92+
<Button
93+
color="red"
94+
class="mr-2"
95+
on:click={() => { deleteCurrentFolder() }}>Yes, I'm sure</Button
96+
>
97+
<Button color="alternative"
98+
on:click={() => { deleteModal = false; }}
99+
>No, cancel</Button>
100+
</div>
43101
</Modal>
44102

45-
<div class="grid grid-cols-2 gap-5 max-h-[35rem] overflow-auto">
103+
<div class="grid max-h-[35rem] grid-cols-2 gap-5 overflow-auto mt-6">
46104
{#each files as file, index}
47105
<div
48106
class="group relative flex w-full flex-col items-center justify-center p-2 px-12 text-center hover:bg-[#d9eeff] focus:bg-[#d9eeff]"
@@ -79,6 +137,14 @@
79137
</p>
80138
</button>
81139
{/if}
140+
141+
<!-- svelte-ignore a11y-click-events-have-key-events -->
142+
<div
143+
class="absolute right-0 top-0 hidden group-hover:block"
144+
on:click={() => { deleteFileIdx(file.id, index) }}
145+
>
146+
<DeleteIcon />
147+
</div>
82148
</div>
83149
{/each}
84150
</div>

ChatQnA/docker/ui/svelte/src/lib/shared/components/upload/uploadFile.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@
168168
</TabItem>
169169
</Tabs>
170170
{#if uploading}
171-
<div class="flex flex-col items-center justify-center">
171+
<div class="flex flex-col items-center justify-center my-6">
172172
<LoadingButton />
173173
</div>
174174
{/if}
175175

176176
{#if files.length > 0}
177177
<DocCard {files} />
178178
{:else}
179-
<div class="flex flex-col items-center justify-center">
179+
<div class="flex flex-col items-center justify-center mt-6">
180180
<NoFile />
181181
<p class=" text-sm opacity-70">No files uploaded</p>
182182
</div>

0 commit comments

Comments
 (0)