From 3baeda7edc598314e6605e58419086433f62336a Mon Sep 17 00:00:00 2001 From: Jun Siang Cheah Date: Sun, 12 May 2024 15:21:03 +0800 Subject: [PATCH] feat: add in-message progress indicator for web search --- src/lib/apis/rag/index.ts | 13 +--- .../chat/Messages/ResponseMessage.svelte | 56 +++++++++++++++ src/routes/(app)/+page.svelte | 72 +++++++++++-------- src/routes/(app)/c/[id]/+page.svelte | 69 ++++++++++-------- 4 files changed, 138 insertions(+), 72 deletions(-) diff --git a/src/lib/apis/rag/index.ts b/src/lib/apis/rag/index.ts index d47b45c29..b434b8a95 100644 --- a/src/lib/apis/rag/index.ts +++ b/src/lib/apis/rag/index.ts @@ -519,9 +519,7 @@ export const runWebSearch = async ( query: string, collection_name?: string ): Promise => { - let error = null; - - const res = await fetch(`${RAG_API_BASE_URL}/websearch`, { + return await fetch(`${RAG_API_BASE_URL}/websearch`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -529,7 +527,7 @@ export const runWebSearch = async ( }, body: JSON.stringify({ query, - collection_name + collection_name: collection_name ?? '' }) }) .then(async (res) => { @@ -538,15 +536,8 @@ export const runWebSearch = async ( }) .catch((err) => { console.log(err); - error = err.detail; return undefined; }); - - if (error) { - throw error; - } - - return res; }; export interface SearchDocument { diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 2b8ef4077..0ebd9c623 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -369,6 +369,62 @@ class="prose chat-{message.role} w-full max-w-full dark:prose-invert prose-headings:my-0 prose-p:m-0 prose-p:-mb-6 prose-pre:my-0 prose-table:my-0 prose-blockquote:my-0 prose-img:my-0 prose-ul:-my-4 prose-ol:-my-4 prose-li:-my-3 prose-ul:-mb-6 prose-ol:-mb-8 prose-ol:p-0 prose-li:-mb-4 whitespace-pre-line" >
+ {#if message.progress} +
+
+ +
+
+ {/if} + {#if edit === true}