Skip to content

Commit

Permalink
Merge pull request #219 from iceljc/features/refine-chat-window
Browse files Browse the repository at this point in the history
Features/refine chat window
  • Loading branch information
iceljc authored Sep 20, 2024
2 parents 0d9c9c5 + cfd2cfe commit a8a6437
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 33 deletions.
16 changes: 16 additions & 0 deletions src/lib/scss/custom/pages/_knowledgebase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@

.load-doc-btn {
font-size: 12px;
display: flex;
justify-content: space-between;

.reset-docs-btn {
color: var(--bs-danger);

i {
font-size: 18px;
border-radius: 3px;

&:hover {
background-color: var(--bs-danger);
color: white;
}
}
}
}

.collection-docs {
Expand Down
1 change: 1 addition & 0 deletions src/lib/services/api-endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const endpoints = {

knowledgeDocumentUploadUrl: `${host}/knowledge/document/{collection}/upload`,
knowledgeDocumentDeleteUrl: `${host}/knowledge/document/{collection}/delete/{fileId}`,
knowledgeDocumentDeleteAllUrl: `${host}/knowledge/document/{collection}/delete`,
knowledgeDocumentPageListUrl: `${host}/knowledge/document/{collection}/page`,

// chathub
Expand Down
14 changes: 14 additions & 0 deletions src/lib/services/knowledge-base-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ export async function deleteKnowledgeDocument(collection, fileId) {
return response.data;
}

/**
* @param {string} collection
* @param {import('$knowledgeTypes').KnowledgeDocRequest} request
* @returns {Promise<boolean>}
*/
export async function deleteAllKnowledgeDocuments(collection, request) {
const url = replaceUrl(endpoints.knowledgeDocumentDeleteAllUrl, {
collection: collection
});

const response = await axios.delete(url, { data: { ...request } });
return response.data;
}


/**
* @param {string} collection
Expand Down
42 changes: 31 additions & 11 deletions src/routes/page/knowledge-base/common/search/advanced-search.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<script>
import { onMount, onDestroy } from 'svelte';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { fly } from 'svelte/transition';
import { Input, Tooltip } from '@sveltestrap/sveltestrap';
import util from "lodash";
const svelteDispatch = createEventDispatcher();
const maxLength = 50;
/** @type {{ key: string, displayName: string }[]} */
export let items;
/** @type {boolean} */
export let disabled = false;
/** @type {boolean} */
let showAdvSearch = false;
/** @type {any[]} */
/** @type {{ key: string, displayName: string, checked: boolean, value: string }[]} */
let innerItems = [];
Expand Down Expand Up @@ -66,6 +68,9 @@
innerItems = innerItems.map((x, index) => {
return index === idx ? { ...found } : x;
});
svelteDispatch('changeitems', {
searchItems: buildSearchItems()
});
}
}
Expand All @@ -80,23 +85,38 @@
innerItems = innerItems.map((x, index) => {
return index === idx ? { ...found } : x;
});
svelteDispatch('changeitems', {
searchItems: buildSearchItems()
});
}
}
function buildSearchItems() {
return innerItems?.filter(x => x.checked && !!util.trim(x.value))?.map(x => {
return {
key: x.key,
value: x.value
}
}) || [];
}
</script>
<div
class="knowledge-adv-search-container"
class="knowledge-adv-search-container mt-5"
in:fly={{ y: -10, duration: 500 }}
out:fly={{ y: -10, duration: 200 }}
>
<div class="knowledge-adv-search-btn text-primary fw-bold">
<Input
type="switch"
disabled={disabled}
checked={showAdvSearch}
on:change={e => toggleAdvSearch(e)}
/>
<div class="line-align-center">
<Input
type="switch"
disabled={disabled}
checked={showAdvSearch}
on:change={e => toggleAdvSearch(e)}
/>
</div>
<div class="line-align-center">
<div>{'Advance Search'}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
/** @type {boolean} */
export let open = false;
/** @type {boolean} */
export let disabled = false;
$: isQuestionAnswerCollection = collectionType === KnowledgeCollectionType.QuestionAnswer;
$: isDocumentCollection = collectionType === KnowledgeCollectionType.Document;
$: {
Expand Down Expand Up @@ -94,6 +97,7 @@
<li data-bs-toggle="tooltip" data-bs-placement="top" title="Edit">
<Button
class="btn btn-sm btn-soft-warning"
disabled={disabled}
on:click={() => editKnowledge()}
>
<i class="bx bxs-edit" />
Expand All @@ -102,6 +106,7 @@
<li data-bs-toggle="tooltip" data-bs-placement="top" title="Delete">
<Button
class="btn btn-sm btn-soft-danger"
disabled={disabled}
on:click={() => deleteKnowledge(item?.id)}
>
<i class="mdi mdi-delete-outline" />
Expand Down
97 changes: 79 additions & 18 deletions src/routes/page/knowledge-base/documents/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
/** @type {string} */
let editModalTitle = "Edit knowledge";
/** @type {import('$commonTypes').KeyValuePair[]} */
let searchItems = [];
/** @type {boolean} */
let showDemo = true;
let isSearching = false;
Expand All @@ -93,6 +96,7 @@
let isOpenEditKnowledge = false;
let isOpenCreateCollection = false;
let textSearch = false;
let disableSearchBtn = false;
/** @type {any} */
let docUploadrCmp;
Expand All @@ -113,7 +117,17 @@
useSearhPair: false
};
$: disabled = isLoading || isLoadingMore;
$: disabled = isLoading || isLoadingMore || isSearching;
$: {
disableSearchBtn = false;
if (isSearching || isLoadingMore) {
disableSearchBtn = true;
} else if (textSearch && searchItems.length > 0) {
disableSearchBtn = false;
} else if (!text || util.trim(text).length === 0) {
disableSearchBtn = true;
}
}
onMount(() => {
initData();
Expand All @@ -138,6 +152,13 @@
showDemo = !showDemo;
}
function toggleTextSearch() {
textSearch = !textSearch;
if (!textSearch) {
searchItems = [];
}
}
function search() {
items = [];
isSearching = true;
Expand Down Expand Up @@ -273,14 +294,24 @@
useSearhPair: false
}) {
return new Promise((resolve, reject) => {
/** @type {import('$commonTypes').KeyValuePair[]} */
let searchPairs = [];
if (params.useSearhPair) {
if (!!text) {
searchPairs = [ ...searchPairs, { key: KnowledgePayloadName.Text, value: text } ];
}
if (textSearch && searchItems.length > 0) {
searchPairs = [ ...searchPairs, ...searchItems ];
}
}
const filter = {
size: pageSize,
start_id: params.startId,
with_vector: enableVector,
included_payloads: includedPayloads,
search_pairs: params.useSearhPair ? [
{ key: KnowledgePayloadName.Text, value: text }
] : []
search_pairs: searchPairs
};
getVectorKnowledgePageList(
Expand Down Expand Up @@ -630,7 +661,7 @@
reset();
const success = e.detail.success;
if (success) {
successText = "Knowledg document has been deleted!";
successText = "Knowledge document has been deleted!";
isComplete = true;
setTimeout(() => {
isComplete = false;
Expand All @@ -643,6 +674,30 @@
}, duration);
}
}
/** @param {any} e */
function onDocsReset(e) {
reset();
const success = e.detail.success;
if (success) {
successText = "Knowledge document has been reset!";
isComplete = true;
setTimeout(() => {
isComplete = false;
}, duration);
} else {
errorText = "Failed to reset knowledge documents."
isError = true;
setTimeout(() => {
isError = false;
}, duration);
}
}
/** @param {any} e */
function onSearchItemsChanged(e) {
searchItems = e.detail.searchItems || [];
}
</script>
<HeadTitle title="{$_('Document Knowledge')}" />
Expand Down Expand Up @@ -767,7 +822,8 @@
<div class="line-align-center input-text search-toggle">
<Input
type="switch"
bind:checked={textSearch}
checked={textSearch}
on:change={e => toggleTextSearch()}
/>
</div>
<div class="line-align-center input-text fw-bold">
Expand All @@ -777,13 +833,24 @@
<div class="line-align-center">
<Button
color="primary"
disabled={!text || util.trim(text).length === 0 || isSearching}
disabled={disableSearchBtn}
on:click={() => search()}
>
{'Search'}
</Button>
</div>
</div>
{#if textSearch}
<AdvancedSearch
on:changeitems={e => onSearchItemsChanged(e)}
disabled={disabled}
items={[
{ key: KnowledgePayloadName.FileName, displayName: "File name" },
{ key: KnowledgePayloadName.FileSource, displayName: "File source" }
]}
/>
{/if}
{#if isSearching}
<div class="knowledge-loader mt-5">
Expand All @@ -795,16 +862,6 @@
</div>
{/if}
</div>
{#if textSearch}
<AdvancedSearch
disabled={disabled}
items={[
{ key: KnowledgePayloadName.FileName, displayName: "File name" },
{ key: KnowledgePayloadName.FileSource, displayName: "File source" }
]}
/>
{/if}
</div>
{/if}
Expand All @@ -815,6 +872,7 @@
bind:this={docUploadrCmp}
on:docuploaded={(e) => onDocUploaded(e)}
on:docdeleted={(e) => onDocDelected(e)}
on:resetdocs={(e) => onDocsReset(e)}
/>
{/if}
Expand Down Expand Up @@ -857,7 +915,10 @@
</div>
<div class="collection-dropdown-container">
<div class="line-align-center collection-dropdown">
<Input type="select" on:change={(e) => changeCollection(e)}>
<Input
type="select"
on:change={(e) => changeCollection(e)}
>
{#each collections as option, idx (idx)}
<option value={option} selected={option === selectedCollection}>{option}</option>
{/each}
Expand Down
Loading

0 comments on commit a8a6437

Please sign in to comment.