forked from xianjianlf2/MindGeniusAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatNode.ts
35 lines (33 loc) · 876 Bytes
/
chatNode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { ChatOptions } from '.'
import { fetchChat } from '.'
import { useNodeStore } from '@/stores'
function useNodeStoreConfig(data: any) {
const nodeStore = useNodeStore()
const config: ChatOptions = {
url: '/api/chatNode',
data,
openHandler: () => {
nodeStore.clearMessage()
nodeStore.toggleLoading(true)
},
messageSendHandler: (data) => {
nodeStore.appendMessage(`${data}`)
},
messageDoneHandler: () => {
nodeStore.toggleLoading(false)
nodeStore.splitTextToNodes()
},
messageCloseHandler: () => {
nodeStore.toggleLoading(false)
},
errorHandler: () => {
nodeStore.toggleLoading(false)
},
}
return config
}
export function fetchChatNode(content: string) {
const config = useNodeStoreConfig({ content })
const controller = fetchChat (config)
return controller
}