Skip to content

Commit

Permalink
OpenAI Create Image (Dall-E) - add option to download image to /tmp (#…
Browse files Browse the repository at this point in the history
…12968)

* add option to download generated images to tmp

* versions
  • Loading branch information
michelle0927 authored Jul 25, 2024
1 parent 8c48a6d commit 1538170
Show file tree
Hide file tree
Showing 35 changed files with 77 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "openai-analyze-image-content",
name: "Analyze Image Content",
description: "Send a message or question about an image and receive a response. [See the documentation](https://platform.openai.com/docs/api-reference/runs/createThreadAndRun)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/cancel-run/cancel-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-cancel-run",
name: "Cancel Run (Assistants)",
description: "Cancels a run that is in progress. [See the documentation](https://platform.openai.com/docs/api-reference/runs/cancelRun)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-chat-with-assistant",
name: "Chat with Assistant",
description: "Sends a message and generates a response, storing the message history for a continuous conversation. [See the documentation](https://platform.openai.com/docs/api-reference/runs/createThreadAndRun)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/chat/chat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import constants from "../../common/constants.mjs";
export default {
...common,
name: "Chat",
version: "0.1.10",
version: "0.1.11",
key: "openai-chat",
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)",
type: "action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import common from "../common/common-helper.mjs";
export default {
...common,
name: "Classify Items into Categories",
version: "0.0.11",
version: "0.0.12",
key: "openai-classify-items-into-categories",
description: "Classify items into specific categories using the Chat API. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
type: "action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "openai-convert-text-to-speech",
name: "Convert Text to Speech (TTS)",
description: "Generates audio from the input text. [See the documentation](https://platform.openai.com/docs/api-reference/audio/createSpeech)",
version: "0.0.6",
version: "0.0.7",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-create-assistant",
name: "Create Assistant",
description: "Creates an assistant with a model and instructions. [See the documentation](https://platform.openai.com/docs/api-reference/assistants/createAssistant)",
version: "0.1.4",
version: "0.1.5",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/create-batch/create-batch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "openai-create-batch",
name: "Create Batch",
description: "Creates and executes a batch from an uploaded file of requests. [See the documentation](https://platform.openai.com/docs/api-reference/batch/create)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import common from "../common/common.mjs";

export default {
name: "Create Embeddings",
version: "0.0.9",
version: "0.0.10",
key: "openai-create-embeddings",
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)",
type: "action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-create-fine-tuning-job",
name: "Create Fine Tuning Job",
description: "Creates a job that fine-tunes a specified model from a given dataset. [See the documentation](https://platform.openai.com/docs/api-reference/fine-tuning/create)",
version: "0.0.6",
version: "0.0.7",
type: "action",
props: {
openai,
Expand Down
45 changes: 40 additions & 5 deletions components/openai/actions/create-image/create-image.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import openai from "../../openai.app.mjs";
import constants from "../../common/constants.mjs";
import fs from "fs";

export default {
name: "Create Image (Dall-E)",
version: "0.1.14",
version: "0.1.15",
key: "openai-create-image",
description: "Creates an image given a prompt returning a URL to the image. [See the documentation](https://platform.openai.com/docs/api-reference/images)",
type: "action",
Expand All @@ -28,6 +29,7 @@ export default {
optional: true,
options: constants.IMAGE_RESPONSE_FORMATS,
default: "url",
reloadProps: true,
},
size: {
label: "Size",
Expand All @@ -40,10 +42,17 @@ export default {
},
async additionalProps() {
const props = {};
if (!this.model) {
if (!this.model && !this.responseFormat) {
return props;
}
if (this.model !== "dall-e-3") {
if (this.responseFormat === "tmp") {
props.filename = {
type: "string",
label: "Filename",
description: "Filename of the new file in `/tmp` directory. Make sure to include the extension.",
};
}
if (this.model && this.model !== "dall-e-3") {
props.n = {
type: "integer",
label: "N",
Expand Down Expand Up @@ -78,15 +87,41 @@ export default {
prompt: this.prompt,
n: this.n,
size: this.size,
response_format: this.responseFormat,
response_format: this.responseFormat === "url"
? this.responseFormat
: "b64_json",
model: this.model,
quality: this.quality,
style: this.style,
},
});

if (this.responseFormat === "tmp") {
const n = this.n || 1;
const fileData = [];
for (let i = 0; i < n; i++) {
// if N > 0, name subsequent files "filename_1.ext", "filename_2.ext", etc.
const filename = i === 0
? this.filename
: this.filename.replace(/(\.[^/.]+)$/, `_${i}$1`);
const outputFilePath = filename.includes("tmp/")
? filename
: `/tmp/${filename}`;
await fs.writeFileSync(outputFilePath, Buffer.from(response.data[0].b64_json.toString(), "base64"));
fileData.push({
tmp: [
filename,
outputFilePath,
],
});
}
response.data = fileData;
}

if (response.data.length) {
$.export("$summary", `Successfully created ${response.data.length} images`);
$.export("$summary", `Successfully created ${response.data.length} image${response.data.length === 1
? ""
: "s"}`);
}

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "openai-create-moderation",
name: "Create Moderation",
description: "Classifies if text is potentially harmful. [See the documentation](https://platform.openai.com/docs/api-reference/moderations/create)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/create-thread/create-thread.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-create-thread",
name: "Create Thread (Assistants)",
description: "Creates a thread with optional messages and metadata, and optionally runs the thread using the specified assistant. [See the documentation](https://platform.openai.com/docs/api-reference/threads/createThread)",
version: "0.0.6",
version: "0.0.7",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const pipelineAsync = promisify(stream.pipeline);

export default {
name: "Create Transcription (Whisper)",
version: "0.1.9",
version: "0.1.10",
key: "openai-create-transcription",
description: "Transcribes audio into the input language. [See the documentation](https://platform.openai.com/docs/api-reference/audio/create).",
type: "action",
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/delete-file/delete-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-delete-file",
name: "Delete File",
description: "Deletes a specified file from OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/files/delete)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/list-files/list-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-list-files",
name: "List Files",
description: "Returns a list of files that belong to the user's organization. [See the documentation](https://platform.openai.com/docs/api-reference/files/list)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/list-messages/list-messages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-list-messages",
name: "List Messages (Assistants)",
description: "Lists the messages for a given thread. [See the documentation](https://platform.openai.com/docs/api-reference/messages/listMessages)",
version: "0.0.8",
version: "0.0.9",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-list-run-steps",
name: "List Run Steps (Assistants)",
description: "Returns a list of run steps belonging to a run. [See the documentation](https://platform.openai.com/docs/api-reference/runs/list-run-steps)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/list-runs/list-runs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-list-runs",
name: "List Runs (Assistants)",
description: "Returns a list of runs belonging to a thread. [See the documentation](https://platform.openai.com/docs/api-reference/runs/list)",
version: "0.0.8",
version: "0.0.9",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-modify-assistant",
name: "Modify an Assistant",
description: "Modifies an existing OpenAI assistant. [See the documentation](https://platform.openai.com/docs/api-reference/assistants/modifyAssistant)",
version: "0.1.4",
version: "0.1.5",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "openai-retrieve-file-content",
name: "Retrieve File Content",
description: "Retrieves the contents of the specified file. [See the documentation](https://platform.openai.com/docs/api-reference/files/retrieve-content)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/retrieve-file/retrieve-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-retrieve-file",
name: "Retrieve File",
description: "Retrieves a specific file from OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/files/retrieve)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-retrieve-run-step",
name: "Retrieve Run Step (Assistants)",
description: "Retrieve a specific run step in a thread. [See the documentation](https://platform.openai.com/docs/api-reference/runs/getRunStep)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/retrieve-run/retrieve-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-retrieve-run",
name: "Retrieve Run (Assistants)",
description: "Retrieves a specific run within a thread. [See the documentation](https://platform.openai.com/docs/api-reference/runs/getRun)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/send-prompt/send-prompt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import common from "../common/common.mjs";
export default {
...common,
name: "Create Completion (Send Prompt)",
version: "0.1.8",
version: "0.1.9",
key: "openai-send-prompt",
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)",
type: "action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "openai-submit-tool-outputs-to-run",
name: "Submit Tool Outputs to Run (Assistants)",
description: "Submits tool outputs to a run that requires action. [See the documentation](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)",
version: "0.0.7",
version: "0.0.8",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/summarize/summarize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import constants from "../../common/constants.mjs";
export default {
...common,
name: "Summarize Text",
version: "0.0.11",
version: "0.0.12",
key: "openai-summarize",
description: "Summarizes text using the Chat API. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
type: "action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const langOptions = lang.LANGUAGES.map((l) => ({
export default {
...common,
name: "Translate Text (Whisper)",
version: "0.0.13",
version: "0.0.14",
key: "openai-translate-text",
description: "Translate text from one language to another using the Chat API. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
type: "action",
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/upload-file/upload-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-upload-file",
name: "Upload File",
description: "Upload a file that can be used across various endpoints/features. The size of individual files can be a maximum of 512mb. [See the documentation](https://platform.openai.com/docs/api-reference/files/create)",
version: "0.0.10",
version: "0.0.11",
type: "action",
props: {
openai,
Expand Down
4 changes: 4 additions & 0 deletions components/openai/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const IMAGE_RESPONSE_FORMATS = [
label: "URL",
value: "url",
},
{
label: "Write file to /tmp directory",
value: "tmp",
},
{
label: "Base64 JSON",
value: "b64_json",
Expand Down
2 changes: 1 addition & 1 deletion components/openai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/openai",
"version": "0.5.3",
"version": "0.5.4",
"description": "Pipedream OpenAI Components",
"main": "openai.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-new-batch-completed",
name: "New Batch Completed",
description: "Emit new event when a new batch is completed in OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/batch/list)",
version: "0.0.1",
version: "0.0.2",
type: "source",
dedupe: "unique",
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-new-file-created",
name: "New File Created",
description: "Emit new event when a new file is created in OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/files/list)",
version: "0.0.6",
version: "0.0.7",
type: "source",
dedupe: "unique",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-new-fine-tuning-job-created",
name: "New Fine Tuning Job Created",
description: "Emit new event when a new fine-tuning job is created in OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/fine-tuning/list)",
version: "0.0.6",
version: "0.0.7",
type: "source",
dedupe: "unique",
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "openai-new-run-state-changed",
name: "New Run State Changed",
description: "Emit new event every time a run changes its status. [See the documentation](https://platform.openai.com/docs/api-reference/runs/listRuns)",
version: "0.0.2",
version: "0.0.3",
type: "source",
dedupe: "unique",
props: {
Expand Down

0 comments on commit 1538170

Please sign in to comment.