提交 | 用户 | 时间
|
820397
|
1 |
import { getAccessToken } from '@/utils/auth' |
H |
2 |
import { fetchEventSource } from '@microsoft/fetch-event-source' |
|
3 |
import { config } from '@/config/axios/config' |
|
4 |
|
|
5 |
export interface AiMindMapGenerateReqVO { |
|
6 |
prompt: string |
|
7 |
} |
|
8 |
|
|
9 |
export const AiMindMapApi = { |
|
10 |
generateMindMap: ({ |
|
11 |
data, |
|
12 |
onClose, |
|
13 |
onMessage, |
|
14 |
onError, |
|
15 |
ctrl |
|
16 |
}: { |
|
17 |
data: AiMindMapGenerateReqVO |
|
18 |
onMessage?: (res: any) => void |
|
19 |
onError?: (...args: any[]) => void |
|
20 |
onClose?: (...args: any[]) => void |
|
21 |
ctrl: AbortController |
|
22 |
}) => { |
|
23 |
const token = getAccessToken() |
|
24 |
return fetchEventSource(`${config.base_url}/ai/mind-map/generate-stream`, { |
|
25 |
method: 'post', |
|
26 |
headers: { |
|
27 |
'Content-Type': 'application/json', |
|
28 |
Authorization: `Bearer ${token}` |
|
29 |
}, |
|
30 |
openWhenHidden: true, |
|
31 |
body: JSON.stringify(data), |
|
32 |
onmessage: onMessage, |
|
33 |
onerror: onError, |
|
34 |
onclose: onClose, |
|
35 |
signal: ctrl.signal |
|
36 |
}) |
|
37 |
} |
|
38 |
} |