Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

hooks.ts 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. import { MessageType } from '@/constants/chat';
  2. import { fileIconMap } from '@/constants/common';
  3. import {
  4. useFetchConversation,
  5. useFetchConversationList,
  6. useFetchDialog,
  7. useFetchDialogList,
  8. useRemoveConversation,
  9. useRemoveDialog,
  10. useSelectConversationList,
  11. useSelectDialogList,
  12. useSetDialog,
  13. useUpdateConversation,
  14. } from '@/hooks/chat-hooks';
  15. import {
  16. useSetModalState,
  17. useShowDeleteConfirm,
  18. useTranslate,
  19. } from '@/hooks/common-hooks';
  20. import { useSendMessageWithSse } from '@/hooks/logic-hooks';
  21. import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
  22. import {
  23. IAnswer,
  24. IConversation,
  25. IDialog,
  26. Message,
  27. } from '@/interfaces/database/chat';
  28. import { IChunk } from '@/interfaces/database/knowledge';
  29. import { getFileExtension } from '@/utils';
  30. import omit from 'lodash/omit';
  31. import trim from 'lodash/trim';
  32. import {
  33. ChangeEventHandler,
  34. useCallback,
  35. useEffect,
  36. useMemo,
  37. useRef,
  38. useState,
  39. } from 'react';
  40. import { useDispatch, useSearchParams, useSelector } from 'umi';
  41. import { v4 as uuid } from 'uuid';
  42. import { ChatSearchParams } from './constants';
  43. import {
  44. IClientConversation,
  45. IMessage,
  46. VariableTableDataType,
  47. } from './interface';
  48. import { ChatModelState } from './model';
  49. import { isConversationIdExist } from './utils';
  50. export const useSelectCurrentDialog = () => {
  51. const currentDialog: IDialog = useSelector(
  52. (state: any) => state.chatModel.currentDialog,
  53. );
  54. return currentDialog;
  55. };
  56. export const useFetchDialogOnMount = (
  57. dialogId: string,
  58. visible: boolean,
  59. ): IDialog => {
  60. const currentDialog: IDialog = useSelectCurrentDialog();
  61. const fetchDialog = useFetchDialog();
  62. useEffect(() => {
  63. if (dialogId && visible) {
  64. fetchDialog(dialogId);
  65. }
  66. }, [dialogId, fetchDialog, visible]);
  67. return currentDialog;
  68. };
  69. export const useSetCurrentDialog = () => {
  70. const dispatch = useDispatch();
  71. const currentDialog: IDialog = useSelector(
  72. (state: any) => state.chatModel.currentDialog,
  73. );
  74. const setCurrentDialog = useCallback(
  75. (dialogId: string) => {
  76. dispatch({
  77. type: 'chatModel/setCurrentDialog',
  78. payload: { id: dialogId },
  79. });
  80. },
  81. [dispatch],
  82. );
  83. return { currentDialog, setCurrentDialog };
  84. };
  85. export const useResetCurrentDialog = () => {
  86. const dispatch = useDispatch();
  87. const resetCurrentDialog = useCallback(() => {
  88. dispatch({
  89. type: 'chatModel/setCurrentDialog',
  90. payload: {},
  91. });
  92. }, [dispatch]);
  93. return { resetCurrentDialog };
  94. };
  95. export const useSelectPromptConfigParameters = (): VariableTableDataType[] => {
  96. const currentDialog: IDialog = useSelector(
  97. (state: any) => state.chatModel.currentDialog,
  98. );
  99. const finalParameters: VariableTableDataType[] = useMemo(() => {
  100. const parameters = currentDialog?.prompt_config?.parameters ?? [];
  101. if (!currentDialog.id) {
  102. // The newly created chat has a default parameter
  103. return [{ key: uuid(), variable: 'knowledge', optional: false }];
  104. }
  105. return parameters.map((x) => ({
  106. key: uuid(),
  107. variable: x.key,
  108. optional: x.optional,
  109. }));
  110. }, [currentDialog]);
  111. return finalParameters;
  112. };
  113. export const useDeleteDialog = () => {
  114. const showDeleteConfirm = useShowDeleteConfirm();
  115. const removeDocument = useRemoveDialog();
  116. const onRemoveDialog = (dialogIds: Array<string>) => {
  117. showDeleteConfirm({ onOk: () => removeDocument(dialogIds) });
  118. };
  119. return { onRemoveDialog };
  120. };
  121. export const useGetChatSearchParams = () => {
  122. const [currentQueryParameters] = useSearchParams();
  123. return {
  124. dialogId: currentQueryParameters.get(ChatSearchParams.DialogId) || '',
  125. conversationId:
  126. currentQueryParameters.get(ChatSearchParams.ConversationId) || '',
  127. };
  128. };
  129. export const useSetCurrentConversation = () => {
  130. const dispatch = useDispatch();
  131. const setCurrentConversation = useCallback(
  132. (currentConversation: IClientConversation) => {
  133. dispatch({
  134. type: 'chatModel/setCurrentConversation',
  135. payload: currentConversation,
  136. });
  137. },
  138. [dispatch],
  139. );
  140. return setCurrentConversation;
  141. };
  142. export const useClickDialogCard = () => {
  143. const [currentQueryParameters, setSearchParams] = useSearchParams();
  144. const newQueryParameters: URLSearchParams = useMemo(() => {
  145. return new URLSearchParams();
  146. }, []);
  147. const handleClickDialog = useCallback(
  148. (dialogId: string) => {
  149. newQueryParameters.set(ChatSearchParams.DialogId, dialogId);
  150. // newQueryParameters.set(
  151. // ChatSearchParams.ConversationId,
  152. // EmptyConversationId,
  153. // );
  154. setSearchParams(newQueryParameters);
  155. },
  156. [newQueryParameters, setSearchParams],
  157. );
  158. return { handleClickDialog };
  159. };
  160. export const useSelectFirstDialogOnMount = () => {
  161. const fetchDialogList = useFetchDialogList();
  162. const dialogList = useSelectDialogList();
  163. const { handleClickDialog } = useClickDialogCard();
  164. const fetchList = useCallback(async () => {
  165. const data = await fetchDialogList();
  166. if (data.retcode === 0 && data.data.length > 0) {
  167. handleClickDialog(data.data[0].id);
  168. }
  169. }, [fetchDialogList, handleClickDialog]);
  170. useEffect(() => {
  171. fetchList();
  172. }, [fetchList]);
  173. return dialogList;
  174. };
  175. export const useHandleItemHover = () => {
  176. const [activated, setActivated] = useState<string>('');
  177. const handleItemEnter = (id: string) => {
  178. setActivated(id);
  179. };
  180. const handleItemLeave = () => {
  181. setActivated('');
  182. };
  183. return {
  184. activated,
  185. handleItemEnter,
  186. handleItemLeave,
  187. };
  188. };
  189. export const useEditDialog = () => {
  190. const [dialog, setDialog] = useState<IDialog>({} as IDialog);
  191. const fetchDialog = useFetchDialog();
  192. const submitDialog = useSetDialog();
  193. const loading = useOneNamespaceEffectsLoading('chatModel', ['setDialog']);
  194. const {
  195. visible: dialogEditVisible,
  196. hideModal: hideDialogEditModal,
  197. showModal: showDialogEditModal,
  198. } = useSetModalState();
  199. const hideModal = useCallback(() => {
  200. setDialog({} as IDialog);
  201. hideDialogEditModal();
  202. }, [hideDialogEditModal]);
  203. const onDialogEditOk = useCallback(
  204. async (dialog: IDialog) => {
  205. const ret = await submitDialog(dialog);
  206. if (ret === 0) {
  207. hideModal();
  208. }
  209. },
  210. [submitDialog, hideModal],
  211. );
  212. const handleShowDialogEditModal = useCallback(
  213. async (dialogId?: string) => {
  214. if (dialogId) {
  215. const ret = await fetchDialog(dialogId, false);
  216. if (ret.retcode === 0) {
  217. setDialog(ret.data);
  218. }
  219. }
  220. showDialogEditModal();
  221. },
  222. [showDialogEditModal, fetchDialog],
  223. );
  224. const clearDialog = useCallback(() => {
  225. setDialog({} as IDialog);
  226. }, []);
  227. return {
  228. dialogSettingLoading: loading,
  229. initialDialog: dialog,
  230. onDialogEditOk,
  231. dialogEditVisible,
  232. hideDialogEditModal: hideModal,
  233. showDialogEditModal: handleShowDialogEditModal,
  234. clearDialog,
  235. };
  236. };
  237. //#region conversation
  238. export const useFetchConversationListOnMount = () => {
  239. const conversationList = useSelectConversationList();
  240. const { dialogId } = useGetChatSearchParams();
  241. const fetchConversationList = useFetchConversationList();
  242. useEffect(() => {
  243. fetchConversationList(dialogId);
  244. }, [fetchConversationList, dialogId]);
  245. return conversationList;
  246. };
  247. export const useSelectDerivedConversationList = () => {
  248. const [list, setList] = useState<Array<IConversation>>([]);
  249. let chatModel: ChatModelState = useSelector((state: any) => state.chatModel);
  250. const { conversationList, currentDialog } = chatModel;
  251. const { dialogId } = useGetChatSearchParams();
  252. const prologue = currentDialog?.prompt_config?.prologue ?? '';
  253. const { t } = useTranslate('chat');
  254. const addTemporaryConversation = useCallback(() => {
  255. setList((pre) => {
  256. if (dialogId) {
  257. const nextList = [
  258. {
  259. id: '',
  260. name: t('newConversation'),
  261. dialog_id: dialogId,
  262. message: [
  263. {
  264. content: prologue,
  265. role: MessageType.Assistant,
  266. },
  267. ],
  268. } as IConversation,
  269. ...conversationList,
  270. ];
  271. return nextList;
  272. }
  273. return pre;
  274. });
  275. }, [conversationList, dialogId, prologue, t]);
  276. useEffect(() => {
  277. addTemporaryConversation();
  278. }, [addTemporaryConversation]);
  279. return { list, addTemporaryConversation };
  280. };
  281. export const useClickConversationCard = () => {
  282. const [currentQueryParameters, setSearchParams] = useSearchParams();
  283. const newQueryParameters: URLSearchParams = useMemo(
  284. () => new URLSearchParams(currentQueryParameters.toString()),
  285. [currentQueryParameters],
  286. );
  287. const handleClickConversation = useCallback(
  288. (conversationId: string) => {
  289. newQueryParameters.set(ChatSearchParams.ConversationId, conversationId);
  290. setSearchParams(newQueryParameters);
  291. },
  292. [newQueryParameters, setSearchParams],
  293. );
  294. return { handleClickConversation };
  295. };
  296. export const useSetConversation = () => {
  297. const { dialogId } = useGetChatSearchParams();
  298. const updateConversation = useUpdateConversation();
  299. const setConversation = useCallback(
  300. (message: string) => {
  301. return updateConversation({
  302. dialog_id: dialogId,
  303. name: message,
  304. message: [
  305. {
  306. role: MessageType.Assistant,
  307. content: message,
  308. },
  309. ],
  310. });
  311. },
  312. [updateConversation, dialogId],
  313. );
  314. return { setConversation };
  315. };
  316. export const useSelectCurrentConversation = () => {
  317. const [currentConversation, setCurrentConversation] =
  318. useState<IClientConversation>({} as IClientConversation);
  319. const conversation: IClientConversation = useSelector(
  320. (state: any) => state.chatModel.currentConversation,
  321. );
  322. const dialog = useSelectCurrentDialog();
  323. const { conversationId, dialogId } = useGetChatSearchParams();
  324. const addNewestConversation = useCallback(
  325. (message: Partial<Message>, answer: string = '') => {
  326. setCurrentConversation((pre) => {
  327. return {
  328. ...pre,
  329. message: [
  330. ...pre.message,
  331. {
  332. role: MessageType.User,
  333. content: message.content,
  334. doc_ids: message.doc_ids,
  335. id: uuid(),
  336. } as IMessage,
  337. {
  338. role: MessageType.Assistant,
  339. content: answer,
  340. id: uuid(),
  341. reference: {},
  342. } as IMessage,
  343. ],
  344. };
  345. });
  346. },
  347. [],
  348. );
  349. const addNewestAnswer = useCallback((answer: IAnswer) => {
  350. setCurrentConversation((pre) => {
  351. const latestMessage = pre.message?.at(-1);
  352. if (latestMessage) {
  353. return {
  354. ...pre,
  355. message: [
  356. ...pre.message.slice(0, -1),
  357. {
  358. ...latestMessage,
  359. content: answer.answer,
  360. reference: answer.reference,
  361. } as IMessage,
  362. ],
  363. };
  364. }
  365. return pre;
  366. });
  367. }, []);
  368. const removeLatestMessage = useCallback(() => {
  369. setCurrentConversation((pre) => {
  370. const nextMessages = pre.message?.slice(0, -2) ?? [];
  371. return {
  372. ...pre,
  373. message: nextMessages,
  374. };
  375. });
  376. }, []);
  377. const addPrologue = useCallback(() => {
  378. if (dialogId !== '' && conversationId === '') {
  379. const prologue = dialog.prompt_config?.prologue;
  380. const nextMessage = {
  381. role: MessageType.Assistant,
  382. content: prologue,
  383. id: uuid(),
  384. } as IMessage;
  385. setCurrentConversation({
  386. id: '',
  387. dialog_id: dialogId,
  388. reference: [],
  389. message: [nextMessage],
  390. } as any);
  391. }
  392. }, [conversationId, dialog, dialogId]);
  393. useEffect(() => {
  394. addPrologue();
  395. }, [addPrologue]);
  396. useEffect(() => {
  397. if (conversationId) {
  398. setCurrentConversation(conversation);
  399. }
  400. }, [conversation, conversationId]);
  401. return {
  402. currentConversation,
  403. addNewestConversation,
  404. removeLatestMessage,
  405. addNewestAnswer,
  406. };
  407. };
  408. export const useScrollToBottom = (currentConversation: IClientConversation) => {
  409. const ref = useRef<HTMLDivElement>(null);
  410. const scrollToBottom = useCallback(() => {
  411. if (currentConversation.id) {
  412. ref.current?.scrollIntoView({ behavior: 'instant' });
  413. }
  414. }, [currentConversation]);
  415. useEffect(() => {
  416. scrollToBottom();
  417. }, [scrollToBottom]);
  418. return ref;
  419. };
  420. export const useFetchConversationOnMount = () => {
  421. const { conversationId } = useGetChatSearchParams();
  422. const fetchConversation = useFetchConversation();
  423. const {
  424. currentConversation,
  425. addNewestConversation,
  426. removeLatestMessage,
  427. addNewestAnswer,
  428. } = useSelectCurrentConversation();
  429. const ref = useScrollToBottom(currentConversation);
  430. const fetchConversationOnMount = useCallback(() => {
  431. if (isConversationIdExist(conversationId)) {
  432. fetchConversation(conversationId);
  433. }
  434. }, [fetchConversation, conversationId]);
  435. useEffect(() => {
  436. fetchConversationOnMount();
  437. }, [fetchConversationOnMount]);
  438. return {
  439. currentConversation,
  440. addNewestConversation,
  441. ref,
  442. removeLatestMessage,
  443. addNewestAnswer,
  444. conversationId,
  445. };
  446. };
  447. export const useHandleMessageInputChange = () => {
  448. const [value, setValue] = useState('');
  449. const handleInputChange: ChangeEventHandler<HTMLInputElement> = (e) => {
  450. const value = e.target.value;
  451. const nextValue = value.replaceAll('\\n', '\n').replaceAll('\\t', '\t');
  452. setValue(nextValue);
  453. };
  454. return {
  455. handleInputChange,
  456. value,
  457. setValue,
  458. };
  459. };
  460. export const useSendMessage = (
  461. conversation: IClientConversation,
  462. addNewestConversation: (message: Partial<Message>, answer?: string) => void,
  463. removeLatestMessage: () => void,
  464. addNewestAnswer: (answer: IAnswer) => void,
  465. ) => {
  466. const { setConversation } = useSetConversation();
  467. const { conversationId } = useGetChatSearchParams();
  468. const { handleInputChange, value, setValue } = useHandleMessageInputChange();
  469. const { handleClickConversation } = useClickConversationCard();
  470. const { send, answer, done, setDone } = useSendMessageWithSse();
  471. const sendMessage = useCallback(
  472. async (message: string, documentIds: string[], id?: string) => {
  473. const res = await send({
  474. conversation_id: id ?? conversationId,
  475. messages: [
  476. ...(conversation?.message ?? []).map((x: IMessage) => omit(x, 'id')),
  477. {
  478. role: MessageType.User,
  479. content: message,
  480. doc_ids: documentIds,
  481. },
  482. ],
  483. });
  484. if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
  485. // cancel loading
  486. setValue(message);
  487. console.info('removeLatestMessage111');
  488. removeLatestMessage();
  489. } else {
  490. if (id) {
  491. console.info('111');
  492. // new conversation
  493. handleClickConversation(id);
  494. } else {
  495. console.info('222');
  496. // fetchConversation(conversationId);
  497. }
  498. }
  499. },
  500. [
  501. conversation?.message,
  502. conversationId,
  503. handleClickConversation,
  504. removeLatestMessage,
  505. setValue,
  506. send,
  507. ],
  508. );
  509. const handleSendMessage = useCallback(
  510. async (message: string, documentIds: string[]) => {
  511. if (conversationId !== '') {
  512. sendMessage(message, documentIds);
  513. } else {
  514. const data = await setConversation(message);
  515. if (data.retcode === 0) {
  516. const id = data.data.id;
  517. sendMessage(message, documentIds, id);
  518. }
  519. }
  520. },
  521. [conversationId, setConversation, sendMessage],
  522. );
  523. useEffect(() => {
  524. // #1289
  525. if (answer.answer && answer?.conversationId === conversationId) {
  526. addNewestAnswer(answer);
  527. }
  528. }, [answer, addNewestAnswer, conversationId]);
  529. useEffect(() => {
  530. // #1289 switch to another conversion window when the last conversion answer doesn't finish.
  531. if (conversationId) {
  532. setDone(true);
  533. }
  534. }, [setDone, conversationId]);
  535. const handlePressEnter = useCallback(
  536. (documentIds: string[]) => {
  537. if (trim(value) === '') return;
  538. addNewestConversation({ content: value, doc_ids: documentIds });
  539. if (done) {
  540. setValue('');
  541. handleSendMessage(value.trim(), documentIds);
  542. }
  543. },
  544. [addNewestConversation, handleSendMessage, done, setValue, value],
  545. );
  546. return {
  547. handlePressEnter,
  548. handleInputChange,
  549. value,
  550. setValue,
  551. loading: !done,
  552. };
  553. };
  554. export const useGetFileIcon = () => {
  555. const getFileIcon = (filename: string) => {
  556. const ext: string = getFileExtension(filename);
  557. const iconPath = fileIconMap[ext as keyof typeof fileIconMap];
  558. return `@/assets/svg/file-icon/${iconPath}`;
  559. };
  560. return getFileIcon;
  561. };
  562. export const useDeleteConversation = () => {
  563. const { dialogId } = useGetChatSearchParams();
  564. const { handleClickConversation } = useClickConversationCard();
  565. const showDeleteConfirm = useShowDeleteConfirm();
  566. const removeConversation = useRemoveConversation();
  567. const deleteConversation = (conversationIds: Array<string>) => async () => {
  568. const ret = await removeConversation(conversationIds, dialogId);
  569. if (ret === 0) {
  570. handleClickConversation('');
  571. }
  572. return ret;
  573. };
  574. const onRemoveConversation = (conversationIds: Array<string>) => {
  575. showDeleteConfirm({ onOk: deleteConversation(conversationIds) });
  576. };
  577. return { onRemoveConversation };
  578. };
  579. export const useRenameConversation = () => {
  580. const [conversation, setConversation] = useState<IClientConversation>(
  581. {} as IClientConversation,
  582. );
  583. const fetchConversation = useFetchConversation();
  584. const {
  585. visible: conversationRenameVisible,
  586. hideModal: hideConversationRenameModal,
  587. showModal: showConversationRenameModal,
  588. } = useSetModalState();
  589. const updateConversation = useUpdateConversation();
  590. const onConversationRenameOk = useCallback(
  591. async (name: string) => {
  592. const ret = await updateConversation({
  593. ...conversation,
  594. conversation_id: conversation.id,
  595. name,
  596. });
  597. if (ret.retcode === 0) {
  598. hideConversationRenameModal();
  599. }
  600. },
  601. [updateConversation, conversation, hideConversationRenameModal],
  602. );
  603. const loading = useOneNamespaceEffectsLoading('chatModel', [
  604. 'setConversation',
  605. ]);
  606. const handleShowConversationRenameModal = useCallback(
  607. async (conversationId: string) => {
  608. const ret = await fetchConversation(conversationId, false);
  609. if (ret.retcode === 0) {
  610. setConversation(ret.data);
  611. }
  612. showConversationRenameModal();
  613. },
  614. [showConversationRenameModal, fetchConversation],
  615. );
  616. return {
  617. conversationRenameLoading: loading,
  618. initialConversationName: conversation.name,
  619. onConversationRenameOk,
  620. conversationRenameVisible,
  621. hideConversationRenameModal,
  622. showConversationRenameModal: handleShowConversationRenameModal,
  623. };
  624. };
  625. export const useClickDrawer = () => {
  626. const { visible, showModal, hideModal } = useSetModalState();
  627. const [selectedChunk, setSelectedChunk] = useState<IChunk>({} as IChunk);
  628. const [documentId, setDocumentId] = useState<string>('');
  629. const clickDocumentButton = useCallback(
  630. (documentId: string, chunk: IChunk) => {
  631. showModal();
  632. setSelectedChunk(chunk);
  633. setDocumentId(documentId);
  634. },
  635. [showModal],
  636. );
  637. return {
  638. clickDocumentButton,
  639. visible,
  640. showModal,
  641. hideModal,
  642. selectedChunk,
  643. documentId,
  644. };
  645. };
  646. export const useSelectDialogListLoading = () => {
  647. return useOneNamespaceEffectsLoading('chatModel', ['listDialog']);
  648. };
  649. export const useSelectConversationListLoading = () => {
  650. return useOneNamespaceEffectsLoading('chatModel', ['listConversation']);
  651. };
  652. export const useSelectConversationLoading = () => {
  653. return useOneNamespaceEffectsLoading('chatModel', ['getConversation']);
  654. };
  655. export const useGetSendButtonDisabled = () => {
  656. const { dialogId, conversationId } = useGetChatSearchParams();
  657. return dialogId === '' && conversationId === '';
  658. };
  659. export const useSendButtonDisabled = (value: string) => {
  660. return trim(value) === '';
  661. };
  662. export const useCreateConversationBeforeUploadDocument = () => {
  663. const { setConversation } = useSetConversation();
  664. const { dialogId } = useGetChatSearchParams();
  665. const { handleClickConversation } = useClickConversationCard();
  666. const createConversationBeforeUploadDocument = useCallback(
  667. async (message: string) => {
  668. const data = await setConversation(message);
  669. if (data.retcode === 0) {
  670. const id = data.data.id;
  671. handleClickConversation(id);
  672. }
  673. return data;
  674. },
  675. [setConversation, handleClickConversation],
  676. );
  677. return {
  678. createConversationBeforeUploadDocument,
  679. dialogId,
  680. };
  681. };
  682. //#endregion