mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-10 21:26:01 +02:00
k
This commit is contained in:
@@ -79,6 +79,7 @@ import {
|
|||||||
SubQueryPiece,
|
SubQueryPiece,
|
||||||
SubQuestionPiece,
|
SubQuestionPiece,
|
||||||
AgentAnswerPiece,
|
AgentAnswerPiece,
|
||||||
|
RefinedAnswerImprovement,
|
||||||
} from "@/lib/search/interfaces";
|
} from "@/lib/search/interfaces";
|
||||||
import { buildFilters } from "@/lib/search/utils";
|
import { buildFilters } from "@/lib/search/utils";
|
||||||
import { SettingsContext } from "@/components/settings/SettingsProvider";
|
import { SettingsContext } from "@/components/settings/SettingsProvider";
|
||||||
@@ -1248,6 +1249,7 @@ export function ChatPage({
|
|||||||
let second_level_generating: boolean = false;
|
let second_level_generating: boolean = false;
|
||||||
let finalMessage: BackendMessage | null = null;
|
let finalMessage: BackendMessage | null = null;
|
||||||
let toolCall: ToolCallMetadata | null = null;
|
let toolCall: ToolCallMetadata | null = null;
|
||||||
|
let isImprovement: boolean | undefined = undefined;
|
||||||
|
|
||||||
let initialFetchDetails: null | {
|
let initialFetchDetails: null | {
|
||||||
user_message_id: number;
|
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
|
// Continuously refine the sub_questions based on the packets that we receive
|
||||||
if (
|
if (
|
||||||
Object.hasOwn(packet, "stop_reason") &&
|
Object.hasOwn(packet, "stop_reason") &&
|
||||||
@@ -1567,6 +1573,7 @@ export function ChatPage({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
is_generating: is_generating,
|
is_generating: is_generating,
|
||||||
|
isImprovement: isImprovement,
|
||||||
messageId: initialFetchDetails.assistant_message_id!,
|
messageId: initialFetchDetails.assistant_message_id!,
|
||||||
message: error || answer,
|
message: error || answer,
|
||||||
second_level_message: second_level_answer,
|
second_level_message: second_level_answer,
|
||||||
@@ -2607,6 +2614,7 @@ export function ChatPage({
|
|||||||
{message.sub_questions &&
|
{message.sub_questions &&
|
||||||
message.sub_questions.length > 0 ? (
|
message.sub_questions.length > 0 ? (
|
||||||
<AgenticMessage
|
<AgenticMessage
|
||||||
|
isImprovement={message.isImprovement}
|
||||||
setStreamingAllowed={
|
setStreamingAllowed={
|
||||||
setStreamingAllowed
|
setStreamingAllowed
|
||||||
}
|
}
|
||||||
|
@@ -109,6 +109,7 @@ export interface Message {
|
|||||||
agentic_docs?: OnyxDocument[] | null;
|
agentic_docs?: OnyxDocument[] | null;
|
||||||
second_level_message?: string;
|
second_level_message?: string;
|
||||||
second_level_subquestions?: SubQuestionDetail[] | null;
|
second_level_subquestions?: SubQuestionDetail[] | null;
|
||||||
|
isImprovement?: boolean | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BackendChatSession {
|
export interface BackendChatSession {
|
||||||
|
@@ -9,6 +9,7 @@ import {
|
|||||||
AgentAnswerPiece,
|
AgentAnswerPiece,
|
||||||
SubQuestionPiece,
|
SubQuestionPiece,
|
||||||
ExtendedToolResponse,
|
ExtendedToolResponse,
|
||||||
|
RefinedAnswerImprovement,
|
||||||
} from "@/lib/search/interfaces";
|
} from "@/lib/search/interfaces";
|
||||||
import { handleSSEStream } from "@/lib/search/streamingUtils";
|
import { handleSSEStream } from "@/lib/search/streamingUtils";
|
||||||
import { ChatState, FeedbackType } from "./types";
|
import { ChatState, FeedbackType } from "./types";
|
||||||
@@ -152,7 +153,8 @@ export type PacketType =
|
|||||||
| SubQueryPiece
|
| SubQueryPiece
|
||||||
| AgentAnswerPiece
|
| AgentAnswerPiece
|
||||||
| SubQuestionPiece
|
| SubQuestionPiece
|
||||||
| ExtendedToolResponse;
|
| ExtendedToolResponse
|
||||||
|
| RefinedAnswerImprovement;
|
||||||
|
|
||||||
export async function* sendMessage({
|
export async function* sendMessage({
|
||||||
regenerate,
|
regenerate,
|
||||||
|
@@ -68,10 +68,11 @@ import rehypeKatex from "rehype-katex";
|
|||||||
import "katex/dist/katex.min.css";
|
import "katex/dist/katex.min.css";
|
||||||
import SubQuestionsDisplay from "./SubQuestionsDisplay";
|
import SubQuestionsDisplay from "./SubQuestionsDisplay";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import RefinemenetBadge from "../refinmentBadge";
|
import RefinemenetBadge, { NoNewAnswerMessage } from "../refinmentBadge";
|
||||||
import SubQuestionProgress from "./SubQuestionProgress";
|
import SubQuestionProgress from "./SubQuestionProgress";
|
||||||
|
|
||||||
export const AgenticMessage = ({
|
export const AgenticMessage = ({
|
||||||
|
isImprovement,
|
||||||
secondLevelAssistantMessage,
|
secondLevelAssistantMessage,
|
||||||
secondLevelGenerating,
|
secondLevelGenerating,
|
||||||
isGenerating,
|
isGenerating,
|
||||||
@@ -111,6 +112,7 @@ export const AgenticMessage = ({
|
|||||||
streamingAllowed,
|
streamingAllowed,
|
||||||
toggleDocDisplay,
|
toggleDocDisplay,
|
||||||
}: {
|
}: {
|
||||||
|
isImprovement?: boolean | null;
|
||||||
secondLevelSubquestions?: SubQuestionDetail[] | null;
|
secondLevelSubquestions?: SubQuestionDetail[] | null;
|
||||||
agenticDocs?: OnyxDocument[] | null;
|
agenticDocs?: OnyxDocument[] | null;
|
||||||
secondLevelGenerating?: boolean;
|
secondLevelGenerating?: boolean;
|
||||||
@@ -470,8 +472,7 @@ export const AgenticMessage = ({
|
|||||||
Answer
|
Answer
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!secondLevelAssistantMessage &&
|
{isImprovement == null &&
|
||||||
// !isGenerating &&
|
|
||||||
subQuestions &&
|
subQuestions &&
|
||||||
subQuestions.length > 0 ? (
|
subQuestions.length > 0 ? (
|
||||||
<RefinemenetBadge
|
<RefinemenetBadge
|
||||||
@@ -485,8 +486,8 @@ export const AgenticMessage = ({
|
|||||||
}}
|
}}
|
||||||
isViewingInitialAnswer={isViewingInitialAnswer}
|
isViewingInitialAnswer={isViewingInitialAnswer}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : secondLevelAssistantMessage ? (
|
||||||
secondLevelAssistantMessage && (
|
isImprovement ? (
|
||||||
<Badge
|
<Badge
|
||||||
// NOTE: This is a hack to make the badge slightly higher
|
// NOTE: This is a hack to make the badge slightly higher
|
||||||
className="cursor-pointer mt-[1px]"
|
className="cursor-pointer mt-[1px]"
|
||||||
@@ -506,7 +507,11 @@ export const AgenticMessage = ({
|
|||||||
? "See Refined Answer"
|
? "See Refined Answer"
|
||||||
: "See Original Answer"}
|
: "See Original Answer"}
|
||||||
</Badge>
|
</Badge>
|
||||||
|
) : (
|
||||||
|
<NoNewAnswerMessage />
|
||||||
)
|
)
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -464,3 +464,39 @@ export default function RefinemenetBadge({
|
|||||||
// </TooltipProvider>
|
// </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;
|
level_question_nr: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RefinedAnswerImprovement {
|
||||||
|
refined_answer_improvement: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AgentAnswerPiece {
|
export interface AgentAnswerPiece {
|
||||||
answer_piece: string;
|
answer_piece: string;
|
||||||
level: number;
|
level: number;
|
||||||
|
Reference in New Issue
Block a user