mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-14 02:20:12 +01:00
[FEAT] Persist query mode refusal responses as chat history (#1727)
* log query refusals to workspace chats but hide in ui * linting --------- Co-authored-by: timothycarambat <rambat1010@gmail.com>
This commit is contained in:
parent
1d675d09fb
commit
c2523a9593
@ -7,6 +7,7 @@ const WorkspaceChats = {
|
|||||||
response = {},
|
response = {},
|
||||||
user = null,
|
user = null,
|
||||||
threadId = null,
|
threadId = null,
|
||||||
|
include = true,
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
const chat = await prisma.workspace_chats.create({
|
const chat = await prisma.workspace_chats.create({
|
||||||
@ -16,6 +17,7 @@ const WorkspaceChats = {
|
|||||||
response: JSON.stringify(response),
|
response: JSON.stringify(response),
|
||||||
user_id: user?.id || null,
|
user_id: user?.id || null,
|
||||||
thread_id: threadId,
|
thread_id: threadId,
|
||||||
|
include,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return { chat, message: null };
|
return { chat, message: null };
|
||||||
|
@ -77,15 +77,30 @@ async function chatWithWorkspace(
|
|||||||
// User is trying to query-mode chat a workspace that has no data in it - so
|
// 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.
|
// we should exit early as no information can be found under these conditions.
|
||||||
if ((!hasVectorizedSpace || embeddingsCount === 0) && chatMode === "query") {
|
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({
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
prompt: message,
|
||||||
|
response: {
|
||||||
|
text: textResponse,
|
||||||
|
sources: [],
|
||||||
|
type: chatMode,
|
||||||
|
},
|
||||||
|
threadId: thread?.id || null,
|
||||||
|
include: false,
|
||||||
|
user,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: uuid,
|
id: uuid,
|
||||||
type: "textResponse",
|
type: "textResponse",
|
||||||
sources: [],
|
sources: [],
|
||||||
close: true,
|
close: true,
|
||||||
error: null,
|
error: null,
|
||||||
textResponse:
|
textResponse,
|
||||||
workspace?.queryRefusalResponse ??
|
|
||||||
"There is no relevant information in this workspace to answer your query.",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,15 +187,30 @@ async function chatWithWorkspace(
|
|||||||
// If in query mode and no context chunks are found from search, backfill, or pins - do not
|
// 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
|
// let the LLM try to hallucinate a response or use general knowledge and exit early
|
||||||
if (chatMode === "query" && contextTexts.length === 0) {
|
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({
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
prompt: message,
|
||||||
|
response: {
|
||||||
|
text: textResponse,
|
||||||
|
sources: [],
|
||||||
|
type: chatMode,
|
||||||
|
},
|
||||||
|
threadId: thread?.id || null,
|
||||||
|
include: false,
|
||||||
|
user,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: uuid,
|
id: uuid,
|
||||||
type: "textResponse",
|
type: "textResponse",
|
||||||
sources: [],
|
sources: [],
|
||||||
close: true,
|
close: true,
|
||||||
error: null,
|
error: null,
|
||||||
textResponse:
|
textResponse,
|
||||||
workspace?.queryRefusalResponse ??
|
|
||||||
"There is no relevant information in this workspace to answer your query.",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,16 +75,29 @@ async function streamChatWithWorkspace(
|
|||||||
// User is trying to query-mode chat a workspace that has no data in it - so
|
// 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.
|
// we should exit early as no information can be found under these conditions.
|
||||||
if ((!hasVectorizedSpace || embeddingsCount === 0) && chatMode === "query") {
|
if ((!hasVectorizedSpace || embeddingsCount === 0) && chatMode === "query") {
|
||||||
|
const textResponse =
|
||||||
|
workspace?.queryRefusalResponse ??
|
||||||
|
"There is no relevant information in this workspace to answer your query.";
|
||||||
writeResponseChunk(response, {
|
writeResponseChunk(response, {
|
||||||
id: uuid,
|
id: uuid,
|
||||||
type: "textResponse",
|
type: "textResponse",
|
||||||
textResponse:
|
textResponse,
|
||||||
workspace?.queryRefusalResponse ??
|
|
||||||
"There is no relevant information in this workspace to answer your query.",
|
|
||||||
sources: [],
|
sources: [],
|
||||||
close: true,
|
close: true,
|
||||||
error: null,
|
error: null,
|
||||||
});
|
});
|
||||||
|
await WorkspaceChats.new({
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
prompt: message,
|
||||||
|
response: {
|
||||||
|
text: textResponse,
|
||||||
|
sources: [],
|
||||||
|
type: chatMode,
|
||||||
|
},
|
||||||
|
threadId: thread?.id || null,
|
||||||
|
include: false,
|
||||||
|
user,
|
||||||
|
});
|
||||||
return;
|
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
|
// 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
|
// let the LLM try to hallucinate a response or use general knowledge and exit early
|
||||||
if (chatMode === "query" && contextTexts.length === 0) {
|
if (chatMode === "query" && contextTexts.length === 0) {
|
||||||
|
const textResponse =
|
||||||
|
workspace?.queryRefusalResponse ??
|
||||||
|
"There is no relevant information in this workspace to answer your query.";
|
||||||
writeResponseChunk(response, {
|
writeResponseChunk(response, {
|
||||||
id: uuid,
|
id: uuid,
|
||||||
type: "textResponse",
|
type: "textResponse",
|
||||||
textResponse:
|
textResponse,
|
||||||
workspace?.queryRefusalResponse ??
|
|
||||||
"There is no relevant information in this workspace to answer your query.",
|
|
||||||
sources: [],
|
sources: [],
|
||||||
close: true,
|
close: true,
|
||||||
error: null,
|
error: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await WorkspaceChats.new({
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
prompt: message,
|
||||||
|
response: {
|
||||||
|
text: textResponse,
|
||||||
|
sources: [],
|
||||||
|
type: chatMode,
|
||||||
|
},
|
||||||
|
threadId: thread?.id || null,
|
||||||
|
include: false,
|
||||||
|
user,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user