feat: Search for the answers you want based on the selected knowledge base #2247 (#2287)

### 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)
This commit is contained in:
balibabu
2024-09-06 15:42:55 +08:00
committed by GitHub
parent b5a2711c05
commit 925dd2aa85
8 changed files with 46 additions and 103 deletions

View File

@ -297,69 +297,6 @@ export const useSpeechWithSse = (url: string = api.tts) => {
return { read };
};
export const useFetchAudioWithSse = (url: string = api.tts) => {
// const [answer, setAnswer] = useState<IAnswer>({} as IAnswer);
const [done, setDone] = useState(true);
const read = useCallback(
async (
body: any,
): Promise<{ response: Response; data: ResponseType } | undefined> => {
try {
setDone(false);
const response = await fetch(url, {
method: 'POST',
headers: {
[Authorization]: getAuthorization(),
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
const res = response.clone().json();
const reader = response?.body?.getReader();
while (true) {
const x = await reader?.read();
if (x) {
const { done, value } = x;
try {
// const val = JSON.parse(value || '');
const val = value;
// const d = val?.data;
// if (typeof d !== 'boolean') {
// console.info('data:', d);
// setAnswer({
// ...d,
// conversationId: body?.conversation_id,
// });
// }
} catch (e) {
console.warn(e);
}
if (done) {
console.info('done');
break;
}
}
}
console.info('done?');
setDone(true);
// setAnswer({} as IAnswer);
return { data: await res, response };
} catch (e) {
setDone(true);
// setAnswer({} as IAnswer);
console.warn(e);
}
},
[url],
);
return { read, done, setDone };
};
//#region chat hooks
export const useScrollToBottom = (messages?: unknown) => {