|
|
@@ -12,7 +12,7 @@ export function createQsAiDialogue(data = {}) {
|
|
|
|
|
|
/**
|
|
|
* 强生菲林 AI 流式问答。
|
|
|
- * 请求体严格使用 qsAi 新接口约定的 conversationId、content、useContext、attachments 四个字段。
|
|
|
+ * 无附件时使用 JSON 请求;有附件时使用 multipart/form-data,其中 request 为 JSON 请求体、files 为本地文件。
|
|
|
*/
|
|
|
export async function sendQsAiChatMessageStream(
|
|
|
conversationId,
|
|
|
@@ -27,25 +27,23 @@ export async function sendQsAiChatMessageStream(
|
|
|
attachments = []
|
|
|
) {
|
|
|
const token = localStorage.getItem('token')
|
|
|
- const requestAttachments = attachments.map(({ url, name, type, contentType }) => ({
|
|
|
- url,
|
|
|
- name,
|
|
|
- contentType: contentType || type || 'application/octet-stream'
|
|
|
- }))
|
|
|
+ const request = { conversationId, content, useContext }
|
|
|
+ const files = attachments.map((attachment) => attachment.file || attachment).filter((file) => file instanceof File)
|
|
|
+ const hasFiles = files.length > 0
|
|
|
+ const formData = new FormData()
|
|
|
+ if (hasFiles) {
|
|
|
+ formData.append('request', new Blob([JSON.stringify(request)], { type: 'application/json' }))
|
|
|
+ files.forEach((file) => formData.append('files', file, file.name))
|
|
|
+ }
|
|
|
|
|
|
return fetchEventSource(`${import.meta.env.VITE_BASE_URL}/bjdxWeb/qsAi/dialogue-send-stream`, {
|
|
|
method: 'post',
|
|
|
headers: {
|
|
|
- 'Content-Type': 'application/json',
|
|
|
+ ...(hasFiles ? {} : { 'Content-Type': 'application/json' }),
|
|
|
...(token ? { Authorization: `Bearer ${token}` } : {})
|
|
|
},
|
|
|
openWhenHidden: true,
|
|
|
- body: JSON.stringify({
|
|
|
- conversationId,
|
|
|
- content,
|
|
|
- useContext,
|
|
|
- attachments: requestAttachments
|
|
|
- }),
|
|
|
+ body: hasFiles ? formData : JSON.stringify(request),
|
|
|
onmessage: onMessage,
|
|
|
onerror: onError,
|
|
|
onclose: onClose,
|