### What problem does this PR solve? Feat: Create a conversation before uploading files #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
35 lines
872 B
TypeScript
35 lines
872 B
TypeScript
import { MessageType } from '@/constants/chat';
|
|
import { useUpdateConversation } from '@/hooks/use-chat-request';
|
|
import { useCallback } from 'react';
|
|
import { useParams } from 'umi';
|
|
|
|
export const useSetConversation = () => {
|
|
const { id: dialogId } = useParams();
|
|
const { updateConversation } = useUpdateConversation();
|
|
|
|
const setConversation = useCallback(
|
|
async (
|
|
message: string,
|
|
isNew: boolean = false,
|
|
conversationId?: string,
|
|
) => {
|
|
const data = await updateConversation({
|
|
dialog_id: dialogId,
|
|
name: message,
|
|
is_new: isNew,
|
|
conversation_id: conversationId,
|
|
message: [
|
|
{
|
|
role: MessageType.Assistant,
|
|
content: message,
|
|
},
|
|
],
|
|
});
|
|
|
|
return data;
|
|
},
|
|
[updateConversation, dialogId],
|
|
);
|
|
|
|
return { setConversation };
|
|
};
|