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
36
37
38
| import { getAccessToken } from '@/utils/auth'
| import { fetchEventSource } from '@microsoft/fetch-event-source'
| import { config } from '@/config/axios/config'
|
| export interface AiMindMapGenerateReqVO {
| prompt: string
| }
|
| export const AiMindMapApi = {
| generateMindMap: ({
| data,
| onClose,
| onMessage,
| onError,
| ctrl
| }: {
| data: AiMindMapGenerateReqVO
| onMessage?: (res: any) => void
| onError?: (...args: any[]) => void
| onClose?: (...args: any[]) => void
| ctrl: AbortController
| }) => {
| const token = getAccessToken()
| return fetchEventSource(`${config.base_url}/ai/mind-map/generate-stream`, {
| method: 'post',
| headers: {
| 'Content-Type': 'application/json',
| Authorization: `Bearer ${token}`
| },
| openWhenHidden: true,
| body: JSON.stringify(data),
| onmessage: onMessage,
| onerror: onError,
| onclose: onClose,
| signal: ctrl.signal
| })
| }
| }
|
|