Skip to content

Commit b1a6f91

Browse files
committed
Improving OpenAI image handling
1 parent a0bc8d7 commit b1a6f91

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

components/llmwhisperer/actions/extract-text/extract-text.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ export default {
9999
},
100100
methods: {
101101
getHeaders() {
102-
return "application/octet-stream";
102+
return {
103+
"Content-Type": "application/octet-stream",
104+
};
103105
},
104106
async getData(data) {
105107
return getFileStream(data);

components/openai/actions/chat/chat.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default {
4343
images: {
4444
label: "Images",
4545
type: "string[]",
46-
description: "Provide one or more images to [OpenAI's vision model](https://platform.openai.com/docs/guides/vision). Accepts URLs or base64 encoded strings. Compatible with the `gpt4-vision-preview` model",
46+
description: "Provide one or more images to [OpenAI's vision model](https://platform.openai.com/docs/guides/vision). Each entry should be either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.jpg`) Compatible with the `gpt4-vision-preview` model",
4747
optional: true,
4848
},
4949
audio: {

components/openai/actions/common/common.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,15 @@ export default {
8585
let content = [];
8686
if (this.images) {
8787
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);
92+
}
93+
const base64Image = Buffer.concat(chunks).toString("base64");
8894
content.push({
89-
"type": "image_url",
90-
"image_url": {
91-
"url": image,
92-
},
95+
"type": "input_image",
96+
"image_url": `data:image/jpeg;base64,${base64Image}`,
9397
});
9498
}
9599
}

0 commit comments

Comments
 (0)