mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-21 14:12:42 +02:00
ensure consistency of answers + update llm relevance prompting (#2045)
This commit is contained in:
@@ -14,6 +14,7 @@ import { useContext, useEffect, useState } from "react";
|
||||
import { Tooltip } from "../tooltip/Tooltip";
|
||||
import KeyboardSymbol from "@/lib/browserUtilities";
|
||||
import { SettingsContext } from "../settings/SettingsProvider";
|
||||
import { DISABLE_LLM_DOC_RELEVANCE } from "@/lib/constants";
|
||||
|
||||
const getSelectedDocumentIds = (
|
||||
documents: SearchDanswerDocument[],
|
||||
@@ -140,6 +141,7 @@ export const SearchResultsDisplay = ({
|
||||
showAll ||
|
||||
(searchResponse &&
|
||||
searchResponse.additional_relevance &&
|
||||
searchResponse.additional_relevance[doc.document_id] &&
|
||||
searchResponse.additional_relevance[doc.document_id].relevant) ||
|
||||
doc.is_relevant
|
||||
);
|
||||
@@ -175,46 +177,48 @@ export const SearchResultsDisplay = ({
|
||||
<div className="mt-4">
|
||||
<div className="font-bold flex justify-between text-emphasis border-b mb-3 pb-1 border-border text-lg">
|
||||
<p>Results</p>
|
||||
{(contentEnriched || searchResponse.additional_relevance) && (
|
||||
<Tooltip delayDuration={1000} content={`${commandSymbol}O`}>
|
||||
<button
|
||||
onClick={() => {
|
||||
performSweep();
|
||||
if (agenticResults) {
|
||||
setShowAll((showAll) => !showAll);
|
||||
}
|
||||
}}
|
||||
className={`flex items-center justify-center animate-fade-in-up rounded-lg p-1 text-xs transition-all duration-300 w-20 h-8 ${
|
||||
!sweep
|
||||
? "bg-green-500 text-text-800"
|
||||
: "bg-rose-700 text-text-100"
|
||||
}`}
|
||||
style={{
|
||||
transform: sweep ? "rotateZ(180deg)" : "rotateZ(0deg)",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={`flex items-center ${sweep ? "rotate-180" : ""}`}
|
||||
{!DISABLE_LLM_DOC_RELEVANCE &&
|
||||
(contentEnriched || searchResponse.additional_relevance) && (
|
||||
<Tooltip delayDuration={1000} content={`${commandSymbol}O`}>
|
||||
<button
|
||||
onClick={() => {
|
||||
performSweep();
|
||||
if (agenticResults) {
|
||||
setShowAll((showAll) => !showAll);
|
||||
}
|
||||
}}
|
||||
className={`flex items-center justify-center animate-fade-in-up rounded-lg p-1 text-xs transition-all duration-300 w-20 h-8 ${
|
||||
!sweep
|
||||
? "bg-green-500 text-text-800"
|
||||
: "bg-rose-700 text-text-100"
|
||||
}`}
|
||||
style={{
|
||||
transform: sweep ? "rotateZ(180deg)" : "rotateZ(0deg)",
|
||||
}}
|
||||
>
|
||||
<span></span>
|
||||
{!sweep
|
||||
? agenticResults
|
||||
? "Show All"
|
||||
: "Focus"
|
||||
: agenticResults
|
||||
? "Focus"
|
||||
: "Show All"}
|
||||
<span className="ml-1">
|
||||
{!sweep ? (
|
||||
<BroomIcon className="h-4 w-4" />
|
||||
) : (
|
||||
<UndoIcon className="h-4 w-4" />
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
<div
|
||||
className={`flex items-center ${sweep ? "rotate-180" : ""}`}
|
||||
>
|
||||
<span></span>
|
||||
{!sweep
|
||||
? agenticResults
|
||||
? "Show All"
|
||||
: "Focus"
|
||||
: agenticResults
|
||||
? "Focus"
|
||||
: "Show All"}
|
||||
|
||||
<span className="ml-1">
|
||||
{!sweep ? (
|
||||
<BroomIcon className="h-4 w-4" />
|
||||
) : (
|
||||
<UndoIcon className="h-4 w-4" />
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{agenticResults &&
|
||||
|
@@ -170,11 +170,12 @@ export const SearchSection = ({
|
||||
if (existingSearchIdRaw == null) {
|
||||
return;
|
||||
}
|
||||
function extractFirstUserMessage(
|
||||
chatSession: SearchSession
|
||||
function extractFirstMessageByType(
|
||||
chatSession: SearchSession,
|
||||
messageType: "user" | "assistant"
|
||||
): string | null {
|
||||
const userMessage = chatSession?.messages.find(
|
||||
(msg) => msg.message_type === "user"
|
||||
(msg) => msg.message_type === messageType
|
||||
);
|
||||
return userMessage ? userMessage.message : null;
|
||||
}
|
||||
@@ -184,14 +185,18 @@ export const SearchSection = ({
|
||||
`/api/query/search-session/${existingSearchessionId}`
|
||||
);
|
||||
const searchSession = (await response.json()) as SearchSession;
|
||||
const message = extractFirstUserMessage(searchSession);
|
||||
const userMessage = extractFirstMessageByType(searchSession, "user");
|
||||
const assistantMessage = extractFirstMessageByType(
|
||||
searchSession,
|
||||
"assistant"
|
||||
);
|
||||
|
||||
if (message) {
|
||||
setQuery(message);
|
||||
if (userMessage) {
|
||||
setQuery(userMessage);
|
||||
const danswerDocs: SearchResponse = {
|
||||
documents: searchSession.documents,
|
||||
suggestedSearchType: null,
|
||||
answer: null,
|
||||
answer: assistantMessage || "Search response not found",
|
||||
quotes: null,
|
||||
selectedDocIndices: null,
|
||||
error: null,
|
||||
|
Reference in New Issue
Block a user