Search flow improvements (#3314)

* untoggle if no docs

* update

* nits

* nit

* typing

* nit
This commit is contained in:
pablodanswer 2024-12-03 10:56:27 -08:00 committed by GitHub
parent cd5f2293ad
commit 23dc8b5dad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 14 deletions

View File

@ -70,7 +70,7 @@ import { StarterMessages } from "../../components/assistants/StarterMessage";
import {
AnswerPiecePacket,
DanswerDocument,
FinalContextDocs,
DocumentInfoPacket,
StreamStopInfo,
StreamStopReason,
} from "@/lib/search/interfaces";
@ -109,6 +109,7 @@ import AssistantBanner from "../../components/assistants/AssistantBanner";
import TextView from "@/components/chat_search/TextView";
import AssistantSelector from "@/components/chat_search/AssistantSelector";
import { Modal } from "@/components/Modal";
import { createPostponedAbortSignal } from "next/dist/server/app-render/dynamic-rendering";
const TEMP_USER_MESSAGE_ID = -1;
const TEMP_ASSISTANT_MESSAGE_ID = -2;
@ -921,7 +922,6 @@ export function ChatPage({
setHasPerformedInitialScroll(true);
}, 100);
} else {
console.log("All messages are already rendered, scrolling immediately");
// If all messages are already rendered, scroll immediately
endDivRef.current.scrollIntoView({
behavior: fast ? "auto" : "smooth",
@ -974,6 +974,16 @@ export function ChatPage({
}
};
useEffect(() => {
if (
(!selectedDocuments || selectedDocuments.length === 0) &&
documentSidebarToggled &&
!filtersToggled
) {
setDocumentSidebarToggled(false);
}
}, [selectedDocuments, filtersToggled]);
useEffect(() => {
adjustDocumentSidebarWidth(); // Adjust the width on initial render
window.addEventListener("resize", adjustDocumentSidebarWidth); // Add resize event listener
@ -1252,7 +1262,6 @@ export function ChatPage({
if (!packet) {
continue;
}
if (!initialFetchDetails) {
if (!Object.hasOwn(packet, "user_message_id")) {
console.error(
@ -1326,8 +1335,8 @@ export function ChatPage({
if (Object.hasOwn(packet, "answer_piece")) {
answer += (packet as AnswerPiecePacket).answer_piece;
} else if (Object.hasOwn(packet, "final_context_docs")) {
documents = (packet as FinalContextDocs).final_context_docs;
} else if (Object.hasOwn(packet, "top_documents")) {
documents = (packet as DocumentInfoPacket).top_documents;
retrievalType = RetrievalType.Search;
if (documents && documents.length > 0) {
// point to the latest message (we don't know the messageId yet, which is why

View File

@ -2,7 +2,7 @@ import {
AnswerPiecePacket,
DanswerDocument,
Filters,
FinalContextDocs,
DocumentInfoPacket,
StreamStopInfo,
} from "@/lib/search/interfaces";
import { handleSSEStream } from "@/lib/search/streamingUtils";
@ -103,7 +103,7 @@ export type PacketType =
| ToolCallMetadata
| BackendMessage
| AnswerPiecePacket
| FinalContextDocs
| DocumentInfoPacket
| DocumentsResponse
| FileChatDisplay
| StreamingError

View File

@ -19,10 +19,6 @@ export interface AnswerPiecePacket {
answer_piece: string;
}
export interface FinalContextDocs {
final_context_docs: DanswerDocument[];
}
export enum StreamStopReason {
CONTEXT_LENGTH = "CONTEXT_LENGTH",
CANCELLED = "CANCELLED",

View File

@ -5,9 +5,8 @@ import {
import {
AnswerPiecePacket,
DanswerDocument,
DocumentInfoPacket,
ErrorMessagePacket,
FinalContextDocs,
DocumentInfoPacket,
Quote,
QuotesInfoPacket,
RelevanceChunk,
@ -92,7 +91,7 @@ export const searchRequestStreamed = async ({
| DocumentInfoPacket
| LLMRelevanceFilterPacket
| BackendMessage
| FinalContextDocs
| DocumentInfoPacket
| RelevanceChunk
>(decoder.decode(value, { stream: true }), previousPartialChunk);
if (!completedChunks.length && !partialChunk) {