mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 16:56:22 +02:00
fix podcast generation
This commit is contained in:
parent
678d8fbbcd
commit
55e5b45a42
26 changed files with 477 additions and 223 deletions
|
|
@ -1,16 +1,13 @@
|
|||
"use client";
|
||||
|
||||
import { type ChatHandler, ChatSection as LlamaIndexChatSection } from "@llamaindex/chat-ui";
|
||||
import { useSetAtom } from "jotai";
|
||||
import { useParams } from "next/navigation";
|
||||
import { createContext, useCallback, useEffect, useState } from "react";
|
||||
import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
||||
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
|
||||
import type { ResearchMode } from "@/components/chat";
|
||||
import { useEffect } from "react";
|
||||
import { ChatInputUI } from "@/components/chat/ChatInputGroup";
|
||||
import { ChatMessagesUI } from "@/components/chat/ChatMessages";
|
||||
import { useChatAPI } from "@/hooks/use-chat";
|
||||
import type { Document } from "@/hooks/use-documents";
|
||||
import { usePodcast } from "@/hooks/use-podcast";
|
||||
import { activeChatIdAtom } from "@/stores/chat/active-chat.atom";
|
||||
import { ChatPanelContainer } from "./ChatPanel/ChatPanelContainer";
|
||||
|
||||
interface ChatInterfaceProps {
|
||||
|
|
@ -23,17 +20,6 @@ interface ChatInterfaceProps {
|
|||
onSearchModeChange?: (mode: "DOCUMENTS" | "CHUNKS") => void;
|
||||
}
|
||||
|
||||
interface ChatInterfaceContext {
|
||||
isChatPannelOpen: boolean;
|
||||
setIsChatPannelOpen: (value: boolean) => void;
|
||||
chat_id: string;
|
||||
chatDetails: ChatDetails | null;
|
||||
podcast: PodcastItem | null;
|
||||
setPodcast: (podcast: PodcastItem | null) => void;
|
||||
}
|
||||
|
||||
export const chatInterfaceContext = createContext<ChatInterfaceContext | null>(null);
|
||||
|
||||
export default function ChatInterface({
|
||||
handler,
|
||||
onDocumentSelectionChange,
|
||||
|
|
@ -44,69 +30,29 @@ export default function ChatInterface({
|
|||
onSearchModeChange,
|
||||
}: ChatInterfaceProps) {
|
||||
const { chat_id, search_space_id } = useParams();
|
||||
const [chatDetails, setChatDetails] = useState<ChatDetails | null>(null);
|
||||
const [isChatPannelOpen, setIsChatPannelOpen] = useState(false);
|
||||
const [podcast, setPodcast] = useState<PodcastItem | null>(null);
|
||||
const contextValue = {
|
||||
isChatPannelOpen,
|
||||
setIsChatPannelOpen,
|
||||
chat_id: typeof chat_id === "string" ? chat_id : chat_id ? chat_id[0] : "",
|
||||
podcast,
|
||||
setPodcast,
|
||||
chatDetails,
|
||||
};
|
||||
|
||||
const { getPodcastByChatId } = usePodcast();
|
||||
|
||||
const { fetchChatDetails } = useChatAPI({
|
||||
token: localStorage?.getItem("surfsense_bearer_token"),
|
||||
search_space_id: search_space_id as string,
|
||||
});
|
||||
|
||||
const getPodcast = useCallback(
|
||||
async (id: string) => {
|
||||
const podcast = await getPodcastByChatId(Number(id));
|
||||
setPodcast(podcast);
|
||||
},
|
||||
[getPodcastByChatId]
|
||||
);
|
||||
|
||||
const getChat = useCallback(
|
||||
async (id: string) => {
|
||||
const chat = await fetchChatDetails(id);
|
||||
setChatDetails(chat);
|
||||
},
|
||||
[fetchChatDetails]
|
||||
);
|
||||
const setActiveChatIdState = useSetAtom(activeChatIdAtom);
|
||||
|
||||
useEffect(() => {
|
||||
const id = typeof chat_id === "string" ? chat_id : chat_id ? chat_id[0] : "";
|
||||
if (!id) return;
|
||||
getChat(id);
|
||||
getPodcast(id);
|
||||
setActiveChatIdState(id);
|
||||
}, [chat_id, search_space_id]);
|
||||
|
||||
return (
|
||||
<chatInterfaceContext.Provider value={contextValue}>
|
||||
<LlamaIndexChatSection handler={handler} className="flex h-full">
|
||||
<div className="flex gap-4 flex-1 w-full">
|
||||
<div className="flex grow-1 flex-col">
|
||||
<ChatMessagesUI />
|
||||
<div className="border-t p-4">
|
||||
<ChatInputUI
|
||||
onDocumentSelectionChange={onDocumentSelectionChange}
|
||||
selectedDocuments={selectedDocuments}
|
||||
onConnectorSelectionChange={onConnectorSelectionChange}
|
||||
selectedConnectors={selectedConnectors}
|
||||
searchMode={searchMode}
|
||||
onSearchModeChange={onSearchModeChange}
|
||||
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<ChatPanelContainer />
|
||||
<LlamaIndexChatSection handler={handler} className="flex h-full">
|
||||
<div className="flex grow-1 flex-col">
|
||||
<ChatMessagesUI />
|
||||
<div className="border-t p-4">
|
||||
<ChatInputUI
|
||||
onDocumentSelectionChange={onDocumentSelectionChange}
|
||||
selectedDocuments={selectedDocuments}
|
||||
onConnectorSelectionChange={onConnectorSelectionChange}
|
||||
selectedConnectors={selectedConnectors}
|
||||
searchMode={searchMode}
|
||||
onSearchModeChange={onSearchModeChange}
|
||||
/>
|
||||
</div>
|
||||
</LlamaIndexChatSection>
|
||||
</chatInterfaceContext.Provider>
|
||||
</div>
|
||||
</LlamaIndexChatSection>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue