(options: ICommonObject, allowImageUploads: boolean)
| 810 | |
| 811 | /** Converts image uploads to base64 image_url content items for model consumption. */ |
| 812 | const _addImagesToMessages = async (options: ICommonObject, allowImageUploads: boolean): Promise<MessageContentImageUrl[]> => { |
| 813 | const imageContent: MessageContentImageUrl[] = [] |
| 814 | |
| 815 | if (!allowImageUploads || !options?.uploads?.length) return imageContent |
| 816 | |
| 817 | const imageUploads = getImageUploads(options.uploads) |
| 818 | for (const upload of imageUploads) { |
| 819 | let url = upload.data |
| 820 | if (upload.type === 'stored-file') { |
| 821 | const fileName = sanitizeFileName(upload.name) |
| 822 | url = await storedFileToBase64(fileName, upload.mime, options) |
| 823 | } |
| 824 | if (url) { |
| 825 | imageContent.push({ |
| 826 | type: 'image_url', |
| 827 | image_url: { url } |
| 828 | }) |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | return imageContent |
| 833 | } |
no test coverage detected