|
1 | 1 | import { |
2 | | - ConfigurationError, getFileStream, |
| 2 | + ConfigurationError, getFileStreamAndMetadata, |
3 | 3 | } from "@pipedream/platform"; |
4 | 4 | import constants from "../../common/constants.mjs"; |
5 | 5 | import { parse } from "../../common/helpers.mjs"; |
@@ -85,27 +85,40 @@ export default { |
85 | 85 | let content = []; |
86 | 86 | if (this.images) { |
87 | 87 | for (const image of this.images) { |
88 | | - const stream = await getFileStream(image); |
89 | | - const chunks = []; |
90 | | - for await (const chunk of stream) { |
91 | | - chunks.push(chunk); |
| 88 | + let base64Image = image; |
| 89 | + let imageType = "image/jpeg"; |
| 90 | + if (image.startsWith("http") || image.includes("tmp/")) { |
| 91 | + const { |
| 92 | + stream, metadata, |
| 93 | + } = await getFileStreamAndMetadata(image); |
| 94 | + const chunks = []; |
| 95 | + for await (const chunk of stream) { |
| 96 | + chunks.push(chunk); |
| 97 | + } |
| 98 | + base64Image = Buffer.concat(chunks).toString("base64"); |
| 99 | + if (metadata.contentType) imageType = metadata.contentType; |
92 | 100 | } |
93 | | - const base64Image = Buffer.concat(chunks).toString("base64"); |
94 | 101 | content.push({ |
95 | | - "type": "input_image", |
96 | | - "image_url": `data:image/jpeg;base64,${base64Image}`, |
| 102 | + "type": "image_url", |
| 103 | + "image_url": { |
| 104 | + "url": base64Image.startsWith("data:") |
| 105 | + ? base64Image |
| 106 | + : `data:${imageType};base64,${base64Image}`, |
| 107 | + }, |
97 | 108 | }); |
98 | 109 | } |
99 | 110 | } |
100 | 111 |
|
101 | 112 | if (this.audio) { |
102 | | - const stream = await getFileStream(this.audio); |
| 113 | + const { |
| 114 | + stream, metadata, |
| 115 | + } = await getFileStreamAndMetadata(this.audio); |
103 | 116 | const chunks = []; |
104 | 117 | for await (const chunk of stream) { |
105 | 118 | chunks.push(chunk); |
106 | 119 | } |
107 | 120 | const fileContent = Buffer.concat(chunks).toString("base64"); |
108 | | - const extension = this.audio.match(/\.(\w+)$/)?.[1]; |
| 121 | + const extension = metadata.name.split(".").pop(); |
109 | 122 | content.push({ |
110 | 123 | type: "input_audio", |
111 | 124 | input_audio: { |
|
0 commit comments