feat: Fetch mind map in search page #2247 (#2292)

### What problem does this PR solve?
feat: Fetch mind map in search page #2247

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-09-06 19:56:17 +08:00
committed by GitHub
parent 1aba978de2
commit e85fea31a8
17 changed files with 111 additions and 133 deletions

View File

@@ -1,3 +1,4 @@
import { useFetchMindMap, useFetchRelatedQuestions } from '@/hooks/chat-hooks';
import { useTestChunkRetrieval } from '@/hooks/knowledge-hooks';
import { useSendMessageWithSse } from '@/hooks/logic-hooks';
import { IAnswer } from '@/interfaces/database/chat';
@@ -10,6 +11,13 @@ export const useSendQuestion = (kbIds: string[]) => {
const { testChunk, loading } = useTestChunkRetrieval();
const [sendingLoading, setSendingLoading] = useState(false);
const [currentAnswer, setCurrentAnswer] = useState({} as IAnswer);
const { fetchRelatedQuestions, data: relatedQuestions } =
useFetchRelatedQuestions();
const {
fetchMindMap,
data: mindMap,
loading: mindMapLoading,
} = useFetchMindMap();
const sendQuestion = useCallback(
(question: string) => {
@@ -17,8 +25,13 @@ export const useSendQuestion = (kbIds: string[]) => {
setSendingLoading(true);
send({ kb_ids: kbIds, question });
testChunk({ kb_id: kbIds, highlight: true, question });
fetchMindMap({
question,
kb_ids: kbIds,
});
fetchRelatedQuestions(question);
},
[send, testChunk, kbIds],
[send, testChunk, kbIds, fetchRelatedQuestions, fetchMindMap],
);
useEffect(() => {
@@ -33,5 +46,13 @@ export const useSendQuestion = (kbIds: string[]) => {
}
}, [done]);
return { sendQuestion, loading, sendingLoading, answer: currentAnswer };
return {
sendQuestion,
loading,
sendingLoading,
answer: currentAnswer,
relatedQuestions: relatedQuestions?.slice(0, 5) ?? [],
mindMap,
mindMapLoading,
};
};