From 1ef93425dc29a684f6a1413c0c4fc7a6a5dd3434 Mon Sep 17 00:00:00 2001 From: shatfield4 Date: Wed, 19 Jun 2024 17:54:33 -0700 Subject: [PATCH 1/2] log query refusals to workspace chats but hide in ui --- server/models/workspaceChats.js | 2 ++ server/utils/chats/index.js | 42 ++++++++++++++++++++++++++++----- server/utils/chats/stream.js | 39 +++++++++++++++++++++++++----- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/server/models/workspaceChats.js b/server/models/workspaceChats.js index bda40064d5b..951245204fe 100644 --- a/server/models/workspaceChats.js +++ b/server/models/workspaceChats.js @@ -7,6 +7,7 @@ const WorkspaceChats = { response = {}, user = null, threadId = null, + include = true, }) { try { const chat = await prisma.workspace_chats.create({ @@ -16,6 +17,7 @@ const WorkspaceChats = { response: JSON.stringify(response), user_id: user?.id || null, thread_id: threadId, + include, }, }); return { chat, message: null }; diff --git a/server/utils/chats/index.js b/server/utils/chats/index.js index b6258c2e336..abb20cdb259 100644 --- a/server/utils/chats/index.js +++ b/server/utils/chats/index.js @@ -77,15 +77,30 @@ async function chatWithWorkspace( // User is trying to query-mode chat a workspace that has no data in it - so // we should exit early as no information can be found under these conditions. if ((!hasVectorizedSpace || embeddingsCount === 0) && chatMode === "query") { + const textResponse = + workspace?.queryRefusalResponse ?? + "There is no relevant information in this workspace to answer your query."; + + await WorkspaceChats.new({ + include: false, + workspaceId: workspace.id, + prompt: message, + response: { + text: textResponse, + sources: [], + type: chatMode, + }, + threadId: thread?.id || null, + user, + }); + return { id: uuid, type: "textResponse", sources: [], close: true, error: null, - textResponse: - workspace?.queryRefusalResponse ?? - "There is no relevant information in this workspace to answer your query.", + textResponse, }; } @@ -172,15 +187,30 @@ async function chatWithWorkspace( // If in query mode and no context chunks are found from search, backfill, or pins - do not // let the LLM try to hallucinate a response or use general knowledge and exit early if (chatMode === "query" && contextTexts.length === 0) { + const textResponse = + workspace?.queryRefusalResponse ?? + "There is no relevant information in this workspace to answer your query."; + + await WorkspaceChats.new({ + include: false, + workspaceId: workspace.id, + prompt: message, + response: { + text: textResponse, + sources: [], + type: chatMode, + }, + threadId: thread?.id || null, + user, + }); + return { id: uuid, type: "textResponse", sources: [], close: true, error: null, - textResponse: - workspace?.queryRefusalResponse ?? - "There is no relevant information in this workspace to answer your query.", + textResponse, }; } diff --git a/server/utils/chats/stream.js b/server/utils/chats/stream.js index ced9a971094..83c2da88bdd 100644 --- a/server/utils/chats/stream.js +++ b/server/utils/chats/stream.js @@ -75,16 +75,29 @@ async function streamChatWithWorkspace( // User is trying to query-mode chat a workspace that has no data in it - so // we should exit early as no information can be found under these conditions. if ((!hasVectorizedSpace || embeddingsCount === 0) && chatMode === "query") { + const textResponse = + workspace?.queryRefusalResponse ?? + "There is no relevant information in this workspace to answer your query."; writeResponseChunk(response, { id: uuid, type: "textResponse", - textResponse: - workspace?.queryRefusalResponse ?? - "There is no relevant information in this workspace to answer your query.", + textResponse, sources: [], close: true, error: null, }); + await WorkspaceChats.new({ + include: false, + workspaceId: workspace.id, + prompt: message, + response: { + text: textResponse, + sources, + type: chatMode, + }, + threadId: thread?.id || null, + user, + }); return; } @@ -177,16 +190,30 @@ async function streamChatWithWorkspace( // If in query mode and no context chunks are found from search, backfill, or pins - do not // let the LLM try to hallucinate a response or use general knowledge and exit early if (chatMode === "query" && contextTexts.length === 0) { + const textResponse = + workspace?.queryRefusalResponse ?? + "There is no relevant information in this workspace to answer your query."; writeResponseChunk(response, { id: uuid, type: "textResponse", - textResponse: - workspace?.queryRefusalResponse ?? - "There is no relevant information in this workspace to answer your query.", + textResponse, sources: [], close: true, error: null, }); + + await WorkspaceChats.new({ + include: false, + workspaceId: workspace.id, + prompt: message, + response: { + text: textResponse, + sources, + type: chatMode, + }, + threadId: thread?.id || null, + user, + }); return; } From aaf16b42402d13b76aee6b92c0af49edeb243646 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Thu, 20 Jun 2024 15:43:51 -0700 Subject: [PATCH 2/2] linting --- server/utils/chats/index.js | 4 ++-- server/utils/chats/stream.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/utils/chats/index.js b/server/utils/chats/index.js index abb20cdb259..f3e0baae224 100644 --- a/server/utils/chats/index.js +++ b/server/utils/chats/index.js @@ -82,7 +82,6 @@ async function chatWithWorkspace( "There is no relevant information in this workspace to answer your query."; await WorkspaceChats.new({ - include: false, workspaceId: workspace.id, prompt: message, response: { @@ -91,6 +90,7 @@ async function chatWithWorkspace( type: chatMode, }, threadId: thread?.id || null, + include: false, user, }); @@ -192,7 +192,6 @@ async function chatWithWorkspace( "There is no relevant information in this workspace to answer your query."; await WorkspaceChats.new({ - include: false, workspaceId: workspace.id, prompt: message, response: { @@ -201,6 +200,7 @@ async function chatWithWorkspace( type: chatMode, }, threadId: thread?.id || null, + include: false, user, }); diff --git a/server/utils/chats/stream.js b/server/utils/chats/stream.js index 83c2da88bdd..770e6cb6b82 100644 --- a/server/utils/chats/stream.js +++ b/server/utils/chats/stream.js @@ -87,15 +87,15 @@ async function streamChatWithWorkspace( error: null, }); await WorkspaceChats.new({ - include: false, workspaceId: workspace.id, prompt: message, response: { text: textResponse, - sources, + sources: [], type: chatMode, }, threadId: thread?.id || null, + include: false, user, }); return; @@ -203,15 +203,15 @@ async function streamChatWithWorkspace( }); await WorkspaceChats.new({ - include: false, workspaceId: workspace.id, prompt: message, response: { text: textResponse, - sources, + sources: [], type: chatMode, }, threadId: thread?.id || null, + include: false, user, }); return;