Files
eosphoros-ai--db-gpt/web/hooks/use-summary.ts
T
wehub-resource-sync d13100ebf3
Update draft releases / main (push) Has been cancelled
Build and push docs image / build-image (push) Has been cancelled
Build Web Application / build-web (macos-latest) (push) Has been cancelled
Build Web Application / build-web (ubuntu-latest) (push) Has been cancelled
Python Code Quality Checks / build (push) Has been cancelled
Test Python / test-python (macos-latest, 3.10) (push) Has been cancelled
Test Python / test-python (macos-latest, 3.11) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.10) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.11) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:27:08 +08:00

39 lines
1.2 KiB
TypeScript

import { ChatContext } from '@/app/chat-context';
import { apiInterceptors, getChatHistory } from '@/client/api';
import { ChatHistoryResponse } from '@/types/chat';
import { useCallback, useContext } from 'react';
import useChat from './use-chat';
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;