mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-06-27 08:21:00 +02:00
Search flow improvements (#3314)
* untoggle if no docs * update * nits * nit * typing * nit
This commit is contained in:
parent
cd5f2293ad
commit
23dc8b5dad
@ -70,7 +70,7 @@ import { StarterMessages } from "../../components/assistants/StarterMessage";
|
|||||||
import {
|
import {
|
||||||
AnswerPiecePacket,
|
AnswerPiecePacket,
|
||||||
DanswerDocument,
|
DanswerDocument,
|
||||||
FinalContextDocs,
|
DocumentInfoPacket,
|
||||||
StreamStopInfo,
|
StreamStopInfo,
|
||||||
StreamStopReason,
|
StreamStopReason,
|
||||||
} from "@/lib/search/interfaces";
|
} from "@/lib/search/interfaces";
|
||||||
@ -109,6 +109,7 @@ import AssistantBanner from "../../components/assistants/AssistantBanner";
|
|||||||
import TextView from "@/components/chat_search/TextView";
|
import TextView from "@/components/chat_search/TextView";
|
||||||
import AssistantSelector from "@/components/chat_search/AssistantSelector";
|
import AssistantSelector from "@/components/chat_search/AssistantSelector";
|
||||||
import { Modal } from "@/components/Modal";
|
import { Modal } from "@/components/Modal";
|
||||||
|
import { createPostponedAbortSignal } from "next/dist/server/app-render/dynamic-rendering";
|
||||||
|
|
||||||
const TEMP_USER_MESSAGE_ID = -1;
|
const TEMP_USER_MESSAGE_ID = -1;
|
||||||
const TEMP_ASSISTANT_MESSAGE_ID = -2;
|
const TEMP_ASSISTANT_MESSAGE_ID = -2;
|
||||||
@ -921,7 +922,6 @@ export function ChatPage({
|
|||||||
setHasPerformedInitialScroll(true);
|
setHasPerformedInitialScroll(true);
|
||||||
}, 100);
|
}, 100);
|
||||||
} else {
|
} else {
|
||||||
console.log("All messages are already rendered, scrolling immediately");
|
|
||||||
// If all messages are already rendered, scroll immediately
|
// If all messages are already rendered, scroll immediately
|
||||||
endDivRef.current.scrollIntoView({
|
endDivRef.current.scrollIntoView({
|
||||||
behavior: fast ? "auto" : "smooth",
|
behavior: fast ? "auto" : "smooth",
|
||||||
@ -974,6 +974,16 @@ export function ChatPage({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
(!selectedDocuments || selectedDocuments.length === 0) &&
|
||||||
|
documentSidebarToggled &&
|
||||||
|
!filtersToggled
|
||||||
|
) {
|
||||||
|
setDocumentSidebarToggled(false);
|
||||||
|
}
|
||||||
|
}, [selectedDocuments, filtersToggled]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
adjustDocumentSidebarWidth(); // Adjust the width on initial render
|
adjustDocumentSidebarWidth(); // Adjust the width on initial render
|
||||||
window.addEventListener("resize", adjustDocumentSidebarWidth); // Add resize event listener
|
window.addEventListener("resize", adjustDocumentSidebarWidth); // Add resize event listener
|
||||||
@ -1252,7 +1262,6 @@ export function ChatPage({
|
|||||||
if (!packet) {
|
if (!packet) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!initialFetchDetails) {
|
if (!initialFetchDetails) {
|
||||||
if (!Object.hasOwn(packet, "user_message_id")) {
|
if (!Object.hasOwn(packet, "user_message_id")) {
|
||||||
console.error(
|
console.error(
|
||||||
@ -1326,8 +1335,8 @@ export function ChatPage({
|
|||||||
|
|
||||||
if (Object.hasOwn(packet, "answer_piece")) {
|
if (Object.hasOwn(packet, "answer_piece")) {
|
||||||
answer += (packet as AnswerPiecePacket).answer_piece;
|
answer += (packet as AnswerPiecePacket).answer_piece;
|
||||||
} else if (Object.hasOwn(packet, "final_context_docs")) {
|
} else if (Object.hasOwn(packet, "top_documents")) {
|
||||||
documents = (packet as FinalContextDocs).final_context_docs;
|
documents = (packet as DocumentInfoPacket).top_documents;
|
||||||
retrievalType = RetrievalType.Search;
|
retrievalType = RetrievalType.Search;
|
||||||
if (documents && documents.length > 0) {
|
if (documents && documents.length > 0) {
|
||||||
// point to the latest message (we don't know the messageId yet, which is why
|
// point to the latest message (we don't know the messageId yet, which is why
|
||||||
|
@ -2,7 +2,7 @@ import {
|
|||||||
AnswerPiecePacket,
|
AnswerPiecePacket,
|
||||||
DanswerDocument,
|
DanswerDocument,
|
||||||
Filters,
|
Filters,
|
||||||
FinalContextDocs,
|
DocumentInfoPacket,
|
||||||
StreamStopInfo,
|
StreamStopInfo,
|
||||||
} from "@/lib/search/interfaces";
|
} from "@/lib/search/interfaces";
|
||||||
import { handleSSEStream } from "@/lib/search/streamingUtils";
|
import { handleSSEStream } from "@/lib/search/streamingUtils";
|
||||||
@ -103,7 +103,7 @@ export type PacketType =
|
|||||||
| ToolCallMetadata
|
| ToolCallMetadata
|
||||||
| BackendMessage
|
| BackendMessage
|
||||||
| AnswerPiecePacket
|
| AnswerPiecePacket
|
||||||
| FinalContextDocs
|
| DocumentInfoPacket
|
||||||
| DocumentsResponse
|
| DocumentsResponse
|
||||||
| FileChatDisplay
|
| FileChatDisplay
|
||||||
| StreamingError
|
| StreamingError
|
||||||
|
@ -19,10 +19,6 @@ export interface AnswerPiecePacket {
|
|||||||
answer_piece: string;
|
answer_piece: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FinalContextDocs {
|
|
||||||
final_context_docs: DanswerDocument[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum StreamStopReason {
|
export enum StreamStopReason {
|
||||||
CONTEXT_LENGTH = "CONTEXT_LENGTH",
|
CONTEXT_LENGTH = "CONTEXT_LENGTH",
|
||||||
CANCELLED = "CANCELLED",
|
CANCELLED = "CANCELLED",
|
||||||
|
@ -5,9 +5,8 @@ import {
|
|||||||
import {
|
import {
|
||||||
AnswerPiecePacket,
|
AnswerPiecePacket,
|
||||||
DanswerDocument,
|
DanswerDocument,
|
||||||
DocumentInfoPacket,
|
|
||||||
ErrorMessagePacket,
|
ErrorMessagePacket,
|
||||||
FinalContextDocs,
|
DocumentInfoPacket,
|
||||||
Quote,
|
Quote,
|
||||||
QuotesInfoPacket,
|
QuotesInfoPacket,
|
||||||
RelevanceChunk,
|
RelevanceChunk,
|
||||||
@ -92,7 +91,7 @@ export const searchRequestStreamed = async ({
|
|||||||
| DocumentInfoPacket
|
| DocumentInfoPacket
|
||||||
| LLMRelevanceFilterPacket
|
| LLMRelevanceFilterPacket
|
||||||
| BackendMessage
|
| BackendMessage
|
||||||
| FinalContextDocs
|
| DocumentInfoPacket
|
||||||
| RelevanceChunk
|
| RelevanceChunk
|
||||||
>(decoder.decode(value, { stream: true }), previousPartialChunk);
|
>(decoder.decode(value, { stream: true }), previousPartialChunk);
|
||||||
if (!completedChunks.length && !partialChunk) {
|
if (!completedChunks.length && !partialChunk) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user