Skip to content

Commit 43a8e92

Browse files
committed
Merge remote-tracking branch 'origin/master' into issue-14432
2 parents 5124329 + 4f6c4b2 commit 43a8e92

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

components/openai/actions/chat/chat.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import openai from "../../openai.app.mjs";
22
import common from "../common/common.mjs";
33
import constants from "../../common/constants.mjs";
4+
import { ConfigurationError } from "@pipedream/platform";
45

56
export default {
67
...common,
@@ -38,7 +39,13 @@ export default {
3839
images: {
3940
label: "Images",
4041
type: "string[]",
41-
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`",
42+
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",
43+
optional: true,
44+
},
45+
audio: {
46+
type: "string",
47+
label: "Audio",
48+
description: "Provide the file path to an audio file in the `/tmp` directory. For use with the `gpt-4o-audio-preview` model. Currently supports `wav` and `mp3` files.",
4249
optional: true,
4350
},
4451
responseFormat: {
@@ -65,6 +72,10 @@ export default {
6572
};
6673
},
6774
async run({ $ }) {
75+
if (this.audio && !this.modelId.includes("gpt-4o-audio-preview")) {
76+
throw new ConfigurationError("Use of audio files requires using the `gpt-4o-audio-preview` model.");
77+
}
78+
6879
const args = this._getChatArgs();
6980

7081
const response = await this.openai.createChatCompletion({

components/openai/actions/common/common.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ConfigurationError } from "@pipedream/platform";
22
import constants from "../../common/constants.mjs";
33
import { parse } from "../../common/helpers.mjs";
4+
import fs from "fs";
45

56
const CHAT_DOCS_MESSAGE_FORMAT_URL = "https://platform.openai.com/docs/guides/chat/introduction";
67

@@ -92,6 +93,20 @@ export default {
9293
}
9394
}
9495

96+
if (this.audio) {
97+
const fileContent = fs.readFileSync(this.audio.includes("tmp/")
98+
? this.audio
99+
: `/tmp/${this.audio}`).toString("base64");
100+
const extension = this.audio.match(/\.(\w+)$/)?.[1];
101+
content.push({
102+
type: "input_audio",
103+
input_audio: {
104+
data: fileContent,
105+
format: extension,
106+
},
107+
});
108+
}
109+
95110
content.push({
96111
"type": "text",
97112
"text": this.userMessage,

0 commit comments

Comments
 (0)