Skip to content

Commit 019f1cb

Browse files
michelle0927malexanderlim
authored andcommitted
OpenAI - Add audio functionality to Chat action (#14367)
* accept audio input * versions * add configuration error
1 parent 3cc761b commit 019f1cb

File tree

9 files changed

+35
-9
lines changed

9 files changed

+35
-9
lines changed

components/openai/actions/chat/chat.mjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
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,
78
name: "Chat",
8-
version: "0.2.0",
9+
version: "0.2.1",
910
key: "openai-chat",
1011
description: "The Chat API, using the `gpt-3.5-turbo` or `gpt-4` model. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
1112
type: "action",
@@ -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/classify-items-into-categories/classify-items-into-categories.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import common from "../common/common-helper.mjs";
33
export default {
44
...common,
55
name: "Classify Items into Categories",
6-
version: "0.1.0",
6+
version: "0.1.1",
77
key: "openai-classify-items-into-categories",
88
description: "Classify items into specific categories using the Chat API. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
99
type: "action",

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,

components/openai/actions/create-embeddings/create-embeddings.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import common from "../common/common.mjs";
44

55
export default {
66
name: "Create Embeddings",
7-
version: "0.0.12",
7+
version: "0.0.13",
88
key: "openai-create-embeddings",
99
description: "Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. [See the documentation](https://platform.openai.com/docs/api-reference/embeddings)",
1010
type: "action",

components/openai/actions/create-transcription/create-transcription.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const pipelineAsync = promisify(stream.pipeline);
2424

2525
export default {
2626
name: "Create Transcription (Whisper)",
27-
version: "0.1.12",
27+
version: "0.1.13",
2828
key: "openai-create-transcription",
2929
description: "Transcribes audio into the input language. [See the documentation](https://platform.openai.com/docs/api-reference/audio/create).",
3030
type: "action",

components/openai/actions/send-prompt/send-prompt.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import common from "../common/common.mjs";
44
export default {
55
...common,
66
name: "Create Completion (Send Prompt)",
7-
version: "0.1.11",
7+
version: "0.1.12",
88
key: "openai-send-prompt",
99
description: "OpenAI recommends using the **Chat** action for the latest `gpt-3.5-turbo` API, since it's faster and 10x cheaper. This action creates a completion for the provided prompt and parameters using the older `/completions` API. [See the documentation](https://beta.openai.com/docs/api-reference/completions/create)",
1010
type: "action",

components/openai/actions/summarize/summarize.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import constants from "../../common/constants.mjs";
44
export default {
55
...common,
66
name: "Summarize Text",
7-
version: "0.1.0",
7+
version: "0.1.1",
88
key: "openai-summarize",
99
description: "Summarizes text using the Chat API. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
1010
type: "action",

components/openai/actions/translate-text/translate-text.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const langOptions = lang.LANGUAGES.map((l) => ({
99
export default {
1010
...common,
1111
name: "Translate Text (Whisper)",
12-
version: "0.1.0",
12+
version: "0.1.1",
1313
key: "openai-translate-text",
1414
description: "Translate text from one language to another using the Chat API. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
1515
type: "action",

components/openai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/openai",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "Pipedream OpenAI Components",
55
"main": "openai.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)