mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 02:26:21 +08:00
fix(server): chat with image (#12699)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved the handling of attachments in chat messages for more efficient processing of images and files without impacting user experience. - **Chores** - Added internal logging to enhance monitoring of AI model interactions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -101,13 +101,13 @@ export async function chatToGPTMessage(
|
||||
({ attachment, mimeType } = attachment);
|
||||
}
|
||||
if (SIMPLE_IMAGE_URL_REGEX.test(attachment)) {
|
||||
const data =
|
||||
attachment.startsWith('data:') || useBase64Attachment
|
||||
? await fetch(attachment).then(r => r.arrayBuffer())
|
||||
: new URL(attachment);
|
||||
if (mimeType.startsWith('image/')) {
|
||||
contents.push({ type: 'image', image: attachment, mimeType });
|
||||
contents.push({ type: 'image', image: data, mimeType });
|
||||
} else {
|
||||
const data =
|
||||
attachment.startsWith('data:') || useBase64Attachment
|
||||
? await fetch(attachment).then(r => r.arrayBuffer())
|
||||
: new URL(attachment);
|
||||
contents.push({ type: 'file' as const, data, mimeType });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user