mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-10-08 23:24:27 +00:00
Co-authored-by: 夏姜 <wenfengjiang.jwf@digital-engine.com> Co-authored-by: yhjun1026 <460342015@qq.com> Co-authored-by: aries_ckt <916701291@qq.com> Co-authored-by: wb-lh513319 <wb-lh513319@alibaba-inc.com>
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { ChatContext } from '@/app/chat-context';
|
|
import { ChatHistoryResponse } from '@/types/chat';
|
|
import { useCallback, useContext } from 'react';
|
|
import useChat from './use-chat';
|
|
import { apiInterceptors, getChatHistory } from '@/client/api';
|
|
|
|
const useSummary = () => {
|
|
const { history, setHistory, chatId, model, docId } = useContext(ChatContext);
|
|
const { chat } = useChat({ queryAgentURL: '/knowledge/document/summary' });
|
|
|
|
const summary = useCallback(
|
|
async (curDocId?: number) => {
|
|
const [, res] = await apiInterceptors(getChatHistory(chatId));
|
|
const tempHistory: ChatHistoryResponse = [
|
|
...res!,
|
|
{ role: 'human', context: '', model_name: model, order: 0, time_stamp: 0 },
|
|
{ role: 'view', context: '', model_name: model, order: 0, time_stamp: 0, retry: true },
|
|
];
|
|
const index = tempHistory.length - 1;
|
|
setHistory([...tempHistory]);
|
|
await chat({
|
|
data: {
|
|
doc_id: curDocId || docId,
|
|
model_name: model,
|
|
},
|
|
chatId,
|
|
onMessage: (message) => {
|
|
tempHistory[index].context = message;
|
|
setHistory([...tempHistory]);
|
|
},
|
|
});
|
|
},
|
|
[history, model, docId, chatId],
|
|
);
|
|
return summary;
|
|
};
|
|
|
|
export default useSummary;
|