From ea8f4b407daee55c4079eed6755628e1a0d0d812 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Wed, 14 Aug 2024 23:01:02 -0500 Subject: [PATCH 1/2] minor change --- src/routes/page/knowledge-base/+page.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/page/knowledge-base/+page.svelte b/src/routes/page/knowledge-base/+page.svelte index 788f26c..afc8c1e 100644 --- a/src/routes/page/knowledge-base/+page.svelte +++ b/src/routes/page/knowledge-base/+page.svelte @@ -96,7 +96,8 @@ function getCollections() { return new Promise((resolve, reject) => { getKnowledgeCollections().then(res => { - collections = res || [ KNOWLEDGE_COLLECTION ]; + const retCollections = res || []; + collections = retCollections.length === 0 ? [ KNOWLEDGE_COLLECTION ] : retCollections; selectedCollection = collections[0]; resolve(res); }).catch(err => { From c7863c74c4b07ff555e619d95a5ed1e117b06975 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Wed, 14 Aug 2024 23:02:27 -0500 Subject: [PATCH 2/2] rename default collection --- src/lib/helpers/constants.js | 2 +- src/lib/services/knowledge-base-service.js | 10 +++++----- src/routes/page/knowledge-base/+page.svelte | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/helpers/constants.js b/src/lib/helpers/constants.js index 52dcfbb..eb67512 100644 --- a/src/lib/helpers/constants.js +++ b/src/lib/helpers/constants.js @@ -26,4 +26,4 @@ export const FILE_EDITORS = [ export const LERNER_ID = "01acc3e5-0af7-49e6-ad7a-a760bd12dc40"; export const TRAINING_MODE = "training"; -export const KNOWLEDGE_COLLECTION = "BotSharp"; \ No newline at end of file +export const DEFAULT_KNOWLEDGE_COLLECTION = "BotSharp"; \ No newline at end of file diff --git a/src/lib/services/knowledge-base-service.js b/src/lib/services/knowledge-base-service.js index d5294d3..e51e7d3 100644 --- a/src/lib/services/knowledge-base-service.js +++ b/src/lib/services/knowledge-base-service.js @@ -1,4 +1,4 @@ -import { KNOWLEDGE_COLLECTION } from '$lib/helpers/constants.js'; +import { DEFAULT_KNOWLEDGE_COLLECTION } from '$lib/helpers/constants.js'; import { replaceUrl } from '$lib/helpers/http.js'; import { endpoints } from './api-endpoints.js'; import axios from 'axios'; @@ -19,7 +19,7 @@ export async function getKnowledgeCollections() { */ export async function searchKnowledge(request, collection = null) { const url = replaceUrl(endpoints.knowledgeBaseSearchUrl, { - collection: collection || KNOWLEDGE_COLLECTION + collection: collection || DEFAULT_KNOWLEDGE_COLLECTION }); const response = await axios.post(url, { ...request }); @@ -33,7 +33,7 @@ export async function searchKnowledge(request, collection = null) { */ export async function getKnowledgeData(filter, collection = null) { const url = replaceUrl(endpoints.knowledgeBaseDataListUrl, { - collection: collection || KNOWLEDGE_COLLECTION + collection: collection || DEFAULT_KNOWLEDGE_COLLECTION }); const response = await axios.post(url, { ...filter }); @@ -48,7 +48,7 @@ export async function getKnowledgeData(filter, collection = null) { */ export async function deleteKnowledgeData(id, collection = null) { const url = replaceUrl(endpoints.knowledgeBaseDeleteDataUrl, { - collection: collection || KNOWLEDGE_COLLECTION, + collection: collection || DEFAULT_KNOWLEDGE_COLLECTION, id: id }); @@ -66,7 +66,7 @@ export async function deleteKnowledgeData(id, collection = null) { */ export async function uploadKnowledge(file, collection = null, startPageNum = null, endPageNum = null) { const url = replaceUrl(endpoints.knowledgeBaseUploadUrl, { - collection: collection || KNOWLEDGE_COLLECTION + collection: collection || DEFAULT_KNOWLEDGE_COLLECTION }); const formData = new FormData(); diff --git a/src/routes/page/knowledge-base/+page.svelte b/src/routes/page/knowledge-base/+page.svelte index afc8c1e..f5912ed 100644 --- a/src/routes/page/knowledge-base/+page.svelte +++ b/src/routes/page/knowledge-base/+page.svelte @@ -9,7 +9,7 @@ import Loader from '$lib/common/Loader.svelte'; import LoadingDots from '$lib/common/LoadingDots.svelte'; import LoadingToComplete from '$lib/common/LoadingToComplete.svelte'; - import { KNOWLEDGE_COLLECTION } from '$lib/helpers/constants'; + import { DEFAULT_KNOWLEDGE_COLLECTION } from '$lib/helpers/constants'; import { getKnowledgeCollections, getKnowledgeData, searchKnowledge } from '$lib/services/knowledge-base-service'; import KnowledgeItem from './knowledge-table/knowledge-item.svelte'; @@ -20,7 +20,7 @@ const confidence = 0.5; let show_demo = false; - let selectedCollection = KNOWLEDGE_COLLECTION; + let selectedCollection = DEFAULT_KNOWLEDGE_COLLECTION; let text = ""; let isSearching = false; let searchDone = false; @@ -97,11 +97,11 @@ return new Promise((resolve, reject) => { getKnowledgeCollections().then(res => { const retCollections = res || []; - collections = retCollections.length === 0 ? [ KNOWLEDGE_COLLECTION ] : retCollections; + collections = retCollections.length === 0 ? [ DEFAULT_KNOWLEDGE_COLLECTION ] : retCollections; selectedCollection = collections[0]; resolve(res); }).catch(err => { - collections = [ KNOWLEDGE_COLLECTION ]; + collections = [ DEFAULT_KNOWLEDGE_COLLECTION ]; selectedCollection = collections[0]; reject(err); });