Skip to content

Commit

Permalink
Merge pull request #192 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 Aug 15, 2024
2 parents 37b94cc + c7863c7 commit 3361ce2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
export const DEFAULT_KNOWLEDGE_COLLECTION = "BotSharp";
10 changes: 5 additions & 5 deletions src/lib/services/knowledge-base-service.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand All @@ -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 });
Expand All @@ -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
});

Expand All @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions src/routes/page/knowledge-base/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -96,11 +96,12 @@
function getCollections() {
return new Promise((resolve, reject) => {
getKnowledgeCollections().then(res => {
collections = res || [ KNOWLEDGE_COLLECTION ];
const retCollections = res || [];
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);
});
Expand Down

0 comments on commit 3361ce2

Please sign in to comment.