mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? feat: Search for the answers you want based on the selected knowledge base #2247 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { useTestChunkRetrieval } from '@/hooks/knowledge-hooks';
|
|
import { useSendMessageWithSse } from '@/hooks/logic-hooks';
|
|
import { IAnswer } from '@/interfaces/database/chat';
|
|
import api from '@/utils/api';
|
|
import { isEmpty } from 'lodash';
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
|
|
export const useSendQuestion = (kbIds: string[]) => {
|
|
const { send, answer, done } = useSendMessageWithSse(api.ask);
|
|
const { testChunk, loading } = useTestChunkRetrieval();
|
|
const [sendingLoading, setSendingLoading] = useState(false);
|
|
const [currentAnswer, setCurrentAnswer] = useState({} as IAnswer);
|
|
|
|
const sendQuestion = useCallback(
|
|
(question: string) => {
|
|
setCurrentAnswer({} as IAnswer);
|
|
setSendingLoading(true);
|
|
send({ kb_ids: kbIds, question });
|
|
testChunk({ kb_id: kbIds, highlight: true, question });
|
|
},
|
|
[send, testChunk, kbIds],
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (!isEmpty(answer)) {
|
|
setCurrentAnswer(answer);
|
|
}
|
|
}, [answer]);
|
|
|
|
useEffect(() => {
|
|
if (done) {
|
|
setSendingLoading(false);
|
|
}
|
|
}, [done]);
|
|
|
|
return { sendQuestion, loading, sendingLoading, answer: currentAnswer };
|
|
};
|