From 69bac2a20e17070fb8734278c3796321b3521f07 Mon Sep 17 00:00:00 2001 From: Jun Siang Cheah Date: Mon, 20 May 2024 18:07:35 +0100 Subject: [PATCH] feat: use the conversation's model instead of the first model for query gen --- src/routes/(app)/+page.svelte | 14 +++++++------- src/routes/(app)/c/[id]/+page.svelte | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index eae7cd05b..728f4510c 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -316,7 +316,7 @@ } if (useWebSearch) { - await runWebSearchForPrompt(parentId, responseMessageId); + await runWebSearchForPrompt(model.id, parentId, responseMessageId); } if (model?.external) { @@ -334,11 +334,11 @@ await chats.set(await getChatList(localStorage.token)); }; - const runWebSearchForPrompt = async (parentId: string, responseId: string) => { + const runWebSearchForPrompt = async (model: string, parentId: string, responseId: string) => { const responseMessage = history.messages[responseId]; responseMessage.progress = $i18n.t('Generating search query'); messages = messages; - const searchQuery = await generateChatSearchQuery(parentId); + const searchQuery = await generateChatSearchQuery(model, parentId); if (!searchQuery) { toast.warning($i18n.t('No search query generated')); responseMessage.progress = undefined; @@ -913,13 +913,13 @@ } }; - const generateChatSearchQuery = async (messageId: string) => { - const model = $models.find((model) => model.id === selectedModels[0]); + const generateChatSearchQuery = async (modelId: string, messageId: string) => { + const model = $models.find((model) => model.id === modelId); const taskModelId = model?.external ?? false - ? $settings?.title?.modelExternal ?? selectedModels[0] - : $settings?.title?.model ?? selectedModels[0]; + ? $settings?.title?.modelExternal ?? modelId + : $settings?.title?.model ?? modelId; const taskModel = $models.find((model) => model.id === taskModelId); const userMessage = history.messages[messageId]; diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index 120c5cc08..8fbd786e4 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -323,7 +323,7 @@ } if (useWebSearch) { - await runWebSearchForPrompt(parentId, responseMessageId); + await runWebSearchForPrompt(model.id, parentId, responseMessageId); } if (model?.external) { @@ -334,17 +334,18 @@ } else { toast.error($i18n.t(`Model {{modelId}} not found`, { modelId })); } - }) + } + ) ); await chats.set(await getChatList(localStorage.token)); }; - const runWebSearchForPrompt = async (parentId: string, responseId: string) => { + const runWebSearchForPrompt = async (model: string, parentId: string, responseId: string) => { const responseMessage = history.messages[responseId]; responseMessage.progress = $i18n.t('Generating search query'); messages = messages; - const searchQuery = await generateChatSearchQuery(parentId); + const searchQuery = await generateChatSearchQuery(model, parentId); if (!searchQuery) { toast.warning($i18n.t('No search query generated')); responseMessage.progress = undefined; @@ -369,7 +370,7 @@ type: 'websearch', upload_status: true, error: '', - urls: searchDocument.filenames, + urls: searchDocument.filenames }); responseMessage.progress = undefined; messages = messages; @@ -919,13 +920,13 @@ } }; - const generateChatSearchQuery = async (messageId: string) => { - const model = $models.find((model) => model.id === selectedModels[0]); + const generateChatSearchQuery = async (modelId: string, messageId: string) => { + const model = $models.find((model) => model.id === modelId); const taskModelId = model?.external ?? false - ? $settings?.title?.modelExternal ?? selectedModels[0] - : $settings?.title?.model ?? selectedModels[0]; + ? $settings?.title?.modelExternal ?? modelId + : $settings?.title?.model ?? modelId; const taskModel = $models.find((model) => model.id === taskModelId); const userMessage = history.messages[messageId];