From afecae37865962516cde1fc631dae94532552350 Mon Sep 17 00:00:00 2001 From: sarfaraz siddiqui Date: Sun, 31 Mar 2024 03:50:11 +0530 Subject: [PATCH 1/2] added feature #887 --- application/api/answer/routes.py | 4 +++- frontend/src/components/SourceDropdown.tsx | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/application/api/answer/routes.py b/application/api/answer/routes.py index bd1fa21f..b122eac1 100644 --- a/application/api/answer/routes.py +++ b/application/api/answer/routes.py @@ -207,7 +207,9 @@ def stream(): prompt_id = data["prompt_id"] else: prompt_id = 'default' - if 'chunks' in data: + if 'selectedDocs' in data and data['selectedDocs'] is None: + chunks = 0 + elif 'chunks' in data: chunks = int(data["chunks"]) else: chunks = 2 diff --git a/frontend/src/components/SourceDropdown.tsx b/frontend/src/components/SourceDropdown.tsx index 04b95d7c..353d49db 100644 --- a/frontend/src/components/SourceDropdown.tsx +++ b/frontend/src/components/SourceDropdown.tsx @@ -24,6 +24,12 @@ function SourceDropdown({ const embeddingsName = import.meta.env.VITE_EMBEDDINGS_NAME || 'huggingface_sentence-transformers/all-mpnet-base-v2'; + + const handleEmptyDocumentSelect = () => { + dispatch(setSelectedDocs(null)); + setIsDocsListOpen(false); + }; + return (
)} From 02d4f7f2da3bf3974fd54aa0b74045dd8e617dfd Mon Sep 17 00:00:00 2001 From: sarfaraz siddiqui Date: Wed, 3 Apr 2024 18:08:46 +0530 Subject: [PATCH 2/2] functions can accept null --- frontend/src/conversation/conversationApi.ts | 113 ++++++++++--------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/frontend/src/conversation/conversationApi.ts b/frontend/src/conversation/conversationApi.ts index e586366b..e3a82191 100644 --- a/frontend/src/conversation/conversationApi.ts +++ b/frontend/src/conversation/conversationApi.ts @@ -6,7 +6,7 @@ const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com'; export function fetchAnswerApi( question: string, signal: AbortSignal, - selectedDocs: Doc, + selectedDocs: Doc | null, history: Array = [], conversationId: string | null, promptId: string | null, @@ -28,24 +28,26 @@ export function fetchAnswerApi( title: any; } > { - let namePath = selectedDocs.name; - if (selectedDocs.language === namePath) { - namePath = '.project'; - } - let docPath = 'default'; - if (selectedDocs.location === 'local') { - docPath = 'local' + '/' + selectedDocs.name + '/'; - } else if (selectedDocs.location === 'remote') { - docPath = - selectedDocs.language + - '/' + - namePath + - '/' + - selectedDocs.version + - '/' + - selectedDocs.model + - '/'; + + if (selectedDocs) { + let namePath = selectedDocs.name; + if (selectedDocs.language === namePath) { + namePath = '.project'; + } + if (selectedDocs.location === 'local') { + docPath = 'local' + '/' + selectedDocs.name + '/'; + } else if (selectedDocs.location === 'remote') { + docPath = + selectedDocs.language + + '/' + + namePath + + '/' + + selectedDocs.version + + '/' + + selectedDocs.model + + '/'; + } } //in history array remove all keys except prompt and response history = history.map((item) => { @@ -89,31 +91,33 @@ export function fetchAnswerApi( export function fetchAnswerSteaming( question: string, signal: AbortSignal, - selectedDocs: Doc, + selectedDocs: Doc | null, history: Array = [], conversationId: string | null, promptId: string | null, chunks: string, onEvent: (event: MessageEvent) => void, ): Promise { - let namePath = selectedDocs.name; - if (selectedDocs.language === namePath) { - namePath = '.project'; - } - let docPath = 'default'; - if (selectedDocs.location === 'local') { - docPath = 'local' + '/' + selectedDocs.name + '/'; - } else if (selectedDocs.location === 'remote') { - docPath = - selectedDocs.language + - '/' + - namePath + - '/' + - selectedDocs.version + - '/' + - selectedDocs.model + - '/'; + + if (selectedDocs) { + let namePath = selectedDocs.name; + if (selectedDocs.language === namePath) { + namePath = '.project'; + } + if (selectedDocs.location === 'local') { + docPath = 'local' + '/' + selectedDocs.name + '/'; + } else if (selectedDocs.location === 'remote') { + docPath = + selectedDocs.language + + '/' + + namePath + + '/' + + selectedDocs.version + + '/' + + selectedDocs.model + + '/'; + } } history = history.map((item) => { @@ -186,7 +190,7 @@ export function fetchAnswerSteaming( } export function searchEndpoint( question: string, - selectedDocs: Doc, + selectedDocs: Doc | null, conversation_id: string | null, history: Array = [], chunks: string, @@ -196,24 +200,25 @@ export function searchEndpoint( "question": "Summarise", "conversation_id": null, "history": "[]" */ - let namePath = selectedDocs.name; - if (selectedDocs.language === namePath) { - namePath = '.project'; - } - let docPath = 'default'; - if (selectedDocs.location === 'local') { - docPath = 'local' + '/' + selectedDocs.name + '/'; - } else if (selectedDocs.location === 'remote') { - docPath = - selectedDocs.language + - '/' + - namePath + - '/' + - selectedDocs.version + - '/' + - selectedDocs.model + - '/'; + if (selectedDocs) { + let namePath = selectedDocs.name; + if (selectedDocs.language === namePath) { + namePath = '.project'; + } + if (selectedDocs.location === 'local') { + docPath = 'local' + '/' + selectedDocs.name + '/'; + } else if (selectedDocs.location === 'remote') { + docPath = + selectedDocs.language + + '/' + + namePath + + '/' + + selectedDocs.version + + '/' + + selectedDocs.model + + '/'; + } } const body = {