mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-03-26 17:51:54 +01:00
k
This commit is contained in:
parent
28ba01b361
commit
4b0a4a2741
@ -79,6 +79,7 @@ import {
|
||||
SubQueryPiece,
|
||||
SubQuestionPiece,
|
||||
AgentAnswerPiece,
|
||||
RefinedAnswerImprovement,
|
||||
} from "@/lib/search/interfaces";
|
||||
import { buildFilters } from "@/lib/search/utils";
|
||||
import { SettingsContext } from "@/components/settings/SettingsProvider";
|
||||
@ -1248,6 +1249,7 @@ export function ChatPage({
|
||||
let second_level_generating: boolean = false;
|
||||
let finalMessage: BackendMessage | null = null;
|
||||
let toolCall: ToolCallMetadata | null = null;
|
||||
let isImprovement: boolean | undefined = undefined;
|
||||
|
||||
let initialFetchDetails: null | {
|
||||
user_message_id: number;
|
||||
@ -1398,6 +1400,10 @@ export function ChatPage({
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.hasOwn(packet, "refined_answer_improvement")) {
|
||||
isImprovement = (packet as RefinedAnswerImprovement)
|
||||
.refined_answer_improvement;
|
||||
}
|
||||
// Continuously refine the sub_questions based on the packets that we receive
|
||||
if (
|
||||
Object.hasOwn(packet, "stop_reason") &&
|
||||
@ -1567,6 +1573,7 @@ export function ChatPage({
|
||||
},
|
||||
{
|
||||
is_generating: is_generating,
|
||||
isImprovement: isImprovement,
|
||||
messageId: initialFetchDetails.assistant_message_id!,
|
||||
message: error || answer,
|
||||
second_level_message: second_level_answer,
|
||||
@ -2607,6 +2614,7 @@ export function ChatPage({
|
||||
{message.sub_questions &&
|
||||
message.sub_questions.length > 0 ? (
|
||||
<AgenticMessage
|
||||
isImprovement={message.isImprovement}
|
||||
setStreamingAllowed={
|
||||
setStreamingAllowed
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ export interface Message {
|
||||
agentic_docs?: OnyxDocument[] | null;
|
||||
second_level_message?: string;
|
||||
second_level_subquestions?: SubQuestionDetail[] | null;
|
||||
isImprovement?: boolean | null;
|
||||
}
|
||||
|
||||
export interface BackendChatSession {
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
AgentAnswerPiece,
|
||||
SubQuestionPiece,
|
||||
ExtendedToolResponse,
|
||||
RefinedAnswerImprovement,
|
||||
} from "@/lib/search/interfaces";
|
||||
import { handleSSEStream } from "@/lib/search/streamingUtils";
|
||||
import { ChatState, FeedbackType } from "./types";
|
||||
@ -152,7 +153,8 @@ export type PacketType =
|
||||
| SubQueryPiece
|
||||
| AgentAnswerPiece
|
||||
| SubQuestionPiece
|
||||
| ExtendedToolResponse;
|
||||
| ExtendedToolResponse
|
||||
| RefinedAnswerImprovement;
|
||||
|
||||
export async function* sendMessage({
|
||||
regenerate,
|
||||
|
@ -68,10 +68,11 @@ import rehypeKatex from "rehype-katex";
|
||||
import "katex/dist/katex.min.css";
|
||||
import SubQuestionsDisplay from "./SubQuestionsDisplay";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import RefinemenetBadge from "../refinmentBadge";
|
||||
import RefinemenetBadge, { NoNewAnswerMessage } from "../refinmentBadge";
|
||||
import SubQuestionProgress from "./SubQuestionProgress";
|
||||
|
||||
export const AgenticMessage = ({
|
||||
isImprovement,
|
||||
secondLevelAssistantMessage,
|
||||
secondLevelGenerating,
|
||||
isGenerating,
|
||||
@ -111,6 +112,7 @@ export const AgenticMessage = ({
|
||||
streamingAllowed,
|
||||
toggleDocDisplay,
|
||||
}: {
|
||||
isImprovement?: boolean | null;
|
||||
secondLevelSubquestions?: SubQuestionDetail[] | null;
|
||||
agenticDocs?: OnyxDocument[] | null;
|
||||
secondLevelGenerating?: boolean;
|
||||
@ -470,8 +472,7 @@ export const AgenticMessage = ({
|
||||
Answer
|
||||
</div>
|
||||
|
||||
{!secondLevelAssistantMessage &&
|
||||
// !isGenerating &&
|
||||
{isImprovement == null &&
|
||||
subQuestions &&
|
||||
subQuestions.length > 0 ? (
|
||||
<RefinemenetBadge
|
||||
@ -485,8 +486,8 @@ export const AgenticMessage = ({
|
||||
}}
|
||||
isViewingInitialAnswer={isViewingInitialAnswer}
|
||||
/>
|
||||
) : (
|
||||
secondLevelAssistantMessage && (
|
||||
) : secondLevelAssistantMessage ? (
|
||||
isImprovement ? (
|
||||
<Badge
|
||||
// NOTE: This is a hack to make the badge slightly higher
|
||||
className="cursor-pointer mt-[1px]"
|
||||
@ -506,7 +507,11 @@ export const AgenticMessage = ({
|
||||
? "See Refined Answer"
|
||||
: "See Original Answer"}
|
||||
</Badge>
|
||||
) : (
|
||||
<NoNewAnswerMessage />
|
||||
)
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
@ -464,3 +464,39 @@ export default function RefinemenetBadge({
|
||||
// </TooltipProvider>
|
||||
// );
|
||||
// }
|
||||
|
||||
// import React, { useState, useEffect } from "react";
|
||||
|
||||
export const NoNewAnswerMessage = () => {
|
||||
const [opacity, setOpacity] = useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
const fadeOutDuration = 2000; // 2 seconds
|
||||
const intervalDuration = 50; // Update every 50ms for smooth fade
|
||||
const opacityStep = intervalDuration / fadeOutDuration;
|
||||
|
||||
const fadeOutInterval = setInterval(() => {
|
||||
setOpacity((prevOpacity) => {
|
||||
const newOpacity = prevOpacity - opacityStep;
|
||||
return newOpacity > 0 ? newOpacity : 0;
|
||||
});
|
||||
}, intervalDuration);
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
clearInterval(fadeOutInterval);
|
||||
}, fadeOutDuration);
|
||||
|
||||
return () => {
|
||||
clearInterval(fadeOutInterval);
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (opacity === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="text-gray-600 text-sm" style={{ opacity: opacity }}>
|
||||
No new answer found...
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -24,6 +24,10 @@ export interface ProSearchPacket {
|
||||
level_question_nr: number;
|
||||
}
|
||||
|
||||
export interface RefinedAnswerImprovement {
|
||||
refined_answer_improvement: boolean;
|
||||
}
|
||||
|
||||
export interface AgentAnswerPiece {
|
||||
answer_piece: string;
|
||||
level: number;
|
||||
|
Loading…
x
Reference in New Issue
Block a user