|
|
|
@@ -6,6 +6,7 @@ import { |
|
|
|
useFetchNextConversation, |
|
|
|
useFetchNextConversationList, |
|
|
|
useFetchNextDialog, |
|
|
|
useFetchNextDialogList, |
|
|
|
useGetChatSearchParams, |
|
|
|
useRemoveNextConversation, |
|
|
|
useRemoveNextDialog, |
|
|
|
@@ -202,15 +203,24 @@ export const useEditDialog = () => { |
|
|
|
|
|
|
|
//#region conversation |
|
|
|
|
|
|
|
const useFindPrologueFromDialogList = () => { |
|
|
|
const { dialogId } = useGetChatSearchParams(); |
|
|
|
const { data: dialogList } = useFetchNextDialogList(true); |
|
|
|
const prologue = useMemo(() => { |
|
|
|
return dialogList.find((x) => x.id === dialogId)?.prompt_config.prologue; |
|
|
|
}, [dialogId, dialogList]); |
|
|
|
|
|
|
|
return prologue; |
|
|
|
}; |
|
|
|
|
|
|
|
export const useSelectDerivedConversationList = () => { |
|
|
|
const { t } = useTranslate('chat'); |
|
|
|
|
|
|
|
const [list, setList] = useState<Array<IConversation>>([]); |
|
|
|
const { data: currentDialog } = useFetchNextDialog(); |
|
|
|
const { data: conversationList, loading } = useFetchNextConversationList(); |
|
|
|
const { dialogId } = useGetChatSearchParams(); |
|
|
|
const prologue = currentDialog?.prompt_config?.prologue ?? ''; |
|
|
|
const { setNewConversationRouteParams } = useSetNewConversationRouteParams(); |
|
|
|
const prologue = useFindPrologueFromDialogList(); |
|
|
|
|
|
|
|
const addTemporaryConversation = useCallback(() => { |
|
|
|
const conversationId = getConversationId(); |
|
|
|
@@ -291,13 +301,11 @@ export const useSelectNextMessages = () => { |
|
|
|
removeMessagesAfterCurrentMessage, |
|
|
|
} = useSelectDerivedMessages(); |
|
|
|
const { data: conversation, loading } = useFetchNextConversation(); |
|
|
|
const { data: dialog } = useFetchNextDialog(); |
|
|
|
const { conversationId, dialogId, isNew } = useGetChatSearchParams(); |
|
|
|
const prologue = useFindPrologueFromDialogList(); |
|
|
|
|
|
|
|
const addPrologue = useCallback(() => { |
|
|
|
if (dialogId !== '' && isNew === 'true') { |
|
|
|
const prologue = dialog.prompt_config?.prologue; |
|
|
|
|
|
|
|
const nextMessage = { |
|
|
|
role: MessageType.Assistant, |
|
|
|
content: prologue, |
|
|
|
@@ -306,7 +314,7 @@ export const useSelectNextMessages = () => { |
|
|
|
|
|
|
|
setDerivedMessages([nextMessage]); |
|
|
|
} |
|
|
|
}, [isNew, dialog, dialogId, setDerivedMessages]); |
|
|
|
}, [dialogId, isNew, prologue, setDerivedMessages]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
addPrologue(); |