@pipedream/openai 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +89 -20
  2. package/actions/analyze-image-content/analyze-image-content.mjs +131 -0
  3. package/actions/cancel-run/cancel-run.mjs +2 -1
  4. package/actions/chat/chat.mjs +5 -7
  5. package/actions/chat-with-assistant/chat-with-assistant.mjs +129 -0
  6. package/actions/classify-items-into-categories/classify-items-into-categories.mjs +27 -10
  7. package/actions/common/common-assistants.mjs +128 -0
  8. package/actions/common/common-helper.mjs +10 -3
  9. package/actions/{create-speech/create-speech.mjs → convert-text-to-speech/convert-text-to-speech.mjs} +3 -3
  10. package/actions/create-assistant/create-assistant.mjs +14 -22
  11. package/actions/create-batch/create-batch.mjs +78 -0
  12. package/actions/create-embeddings/create-embeddings.mjs +3 -3
  13. package/actions/create-fine-tuning-job/create-fine-tuning-job.mjs +14 -3
  14. package/actions/create-image/create-image.mjs +42 -88
  15. package/actions/create-moderation/create-moderation.mjs +35 -0
  16. package/actions/create-thread/create-thread.mjs +110 -8
  17. package/actions/create-transcription/create-transcription.mjs +4 -4
  18. package/actions/delete-file/delete-file.mjs +6 -5
  19. package/actions/list-files/list-files.mjs +3 -2
  20. package/actions/list-messages/list-messages.mjs +18 -21
  21. package/actions/list-run-steps/list-run-steps.mjs +18 -25
  22. package/actions/list-runs/list-runs.mjs +17 -34
  23. package/actions/modify-assistant/modify-assistant.mjs +13 -23
  24. package/actions/retrieve-file/retrieve-file.mjs +6 -5
  25. package/actions/retrieve-file-content/retrieve-file-content.mjs +29 -6
  26. package/actions/retrieve-run/retrieve-run.mjs +2 -1
  27. package/actions/retrieve-run-step/retrieve-run-step.mjs +8 -1
  28. package/actions/send-prompt/send-prompt.mjs +8 -3
  29. package/actions/submit-tool-outputs-to-run/submit-tool-outputs-to-run.mjs +18 -3
  30. package/actions/summarize/summarize.mjs +11 -10
  31. package/actions/translate-text/translate-text.mjs +9 -5
  32. package/actions/upload-file/upload-file.mjs +1 -1
  33. package/common/constants.mjs +154 -3
  34. package/openai.app.mjs +230 -269
  35. package/package.json +1 -1
  36. package/sources/{common.mjs → common/common.mjs} +11 -9
  37. package/sources/new-batch-completed/new-batch-completed.mjs +46 -0
  38. package/sources/new-batch-completed/test-event.mjs +29 -0
  39. package/sources/new-file-created/new-file-created.mjs +5 -3
  40. package/sources/new-file-created/test-event.mjs +10 -0
  41. package/sources/new-fine-tuning-job-created/new-fine-tuning-job-created.mjs +5 -3
  42. package/sources/new-fine-tuning-job-created/test-event.mjs +19 -0
  43. package/sources/new-run-state-changed/new-run-state-changed.mjs +4 -2
  44. package/sources/new-run-state-changed/test-event.mjs +36 -0
  45. package/actions/common/constants.mjs +0 -14
  46. package/actions/create-message/create-message.mjs +0 -64
  47. package/actions/create-run/create-run.mjs +0 -65
  48. package/actions/create-thread-and-run/create-thread-and-run.mjs +0 -62
  49. package/actions/modify-message/modify-message.mjs +0 -42
  50. package/actions/modify-run/modify-run.mjs +0 -45
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/openai",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Pipedream OpenAI Components",
5
5
  "main": "openai.app.mjs",
6
6
  "keywords": [
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
- import openai from "../openai.app.mjs";
2
+ import openai from "../../openai.app.mjs";
3
3
 
4
4
  export default {
5
5
  props: {
@@ -13,11 +13,11 @@ export default {
13
13
  },
14
14
  },
15
15
  methods: {
16
- _getSavedItems() {
17
- return this.db.get("savedItems") ?? [];
16
+ _getLastCreated() {
17
+ return this.db.get("lastCreated") || 0;
18
18
  },
19
- _setSavedItems(value) {
20
- this.db.set("savedItems", value);
19
+ _setLastCreated(lastCreated) {
20
+ this.db.set("lastCreated", lastCreated);
21
21
  },
22
22
  getMeta() {
23
23
  throw new Error("No item metadata implemented!");
@@ -26,18 +26,20 @@ export default {
26
26
  throw new Error("No item fetching implemented!");
27
27
  },
28
28
  async getAndProcessItems(maxEvents) {
29
- const savedItems = this._getSavedItems();
29
+ const lastCreated = this._getLastCreated();
30
30
  const { data } = await this.getData();
31
+ if (!data?.length) {
32
+ return;
33
+ }
34
+ this._setLastCreated(data[0].created_at);
31
35
  data
32
- ?.filter(({ id }) => !savedItems.includes(id))
36
+ ?.filter(({ created_at }) => created_at >= lastCreated)
33
37
  .reverse()
34
38
  .forEach((item, index) => {
35
39
  if (!maxEvents || index < maxEvents) {
36
40
  this.$emit(item, this.getMeta(item));
37
41
  }
38
- savedItems.push(item.id);
39
42
  });
40
- this._setSavedItems(savedItems);
41
43
  },
42
44
  },
43
45
  hooks: {
@@ -0,0 +1,46 @@
1
+ import common from "../common/common.mjs";
2
+ import sampleEmit from "./test-event.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ key: "openai-new-batch-completed",
7
+ name: "New Batch Completed",
8
+ description: "Emit new event when a new batch is completed in OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/batch/list)",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ methods: {
13
+ ...common.methods,
14
+ _getLastCompleted() {
15
+ return this.db.get("lastCompleted") || 0;
16
+ },
17
+ _setLastCompleted(lastCompleted) {
18
+ this.db.set("lastCompleted", lastCompleted);
19
+ },
20
+ getMeta(batch) {
21
+ return {
22
+ id: batch.id,
23
+ summary: `Batch Completed with ID ${batch.id}`,
24
+ ts: batch.completed_at * 1000,
25
+ };
26
+ },
27
+ async getAndProcessItems(max) {
28
+ const lastCompleted = this._getLastCompleted();
29
+ let maxCompleted = lastCompleted;
30
+ const results = this.openai.paginate({
31
+ resourceFn: this.openai.listBatches,
32
+ max,
33
+ });
34
+ const batches = [];
35
+ for await (const batch of results) {
36
+ if (batch.completed_at && batch.completed_at > lastCompleted) {
37
+ batches.push(batch);
38
+ maxCompleted = Math.max(batch.completed_at, maxCompleted);
39
+ }
40
+ }
41
+ this._setLastCompleted(maxCompleted);
42
+ batches.reverse().forEach((item) => this.$emit(item, this.getMeta(item)));
43
+ },
44
+ },
45
+ sampleEmit,
46
+ };
@@ -0,0 +1,29 @@
1
+ export default {
2
+ "id": "batch_abc123",
3
+ "object": "batch",
4
+ "endpoint": "/v1/completions",
5
+ "errors": null,
6
+ "input_file_id": "file-abc123",
7
+ "completion_window": "24h",
8
+ "status": "completed",
9
+ "output_file_id": "file-cvaTdG",
10
+ "error_file_id": "file-HOWS94",
11
+ "created_at": 1711471533,
12
+ "in_progress_at": 1711471538,
13
+ "expires_at": 1711557933,
14
+ "finalizing_at": 1711493133,
15
+ "completed_at": 1711493163,
16
+ "failed_at": null,
17
+ "expired_at": null,
18
+ "cancelling_at": null,
19
+ "cancelled_at": null,
20
+ "request_counts": {
21
+ "total": 100,
22
+ "completed": 95,
23
+ "failed": 5
24
+ },
25
+ "metadata": {
26
+ "customer_id": "user_123456789",
27
+ "batch_description": "Nightly eval job",
28
+ }
29
+ }
@@ -1,11 +1,12 @@
1
- import common from "../common.mjs";
1
+ import common from "../common/common.mjs";
2
+ import sampleEmit from "./test-event.mjs";
2
3
 
3
4
  export default {
4
5
  ...common,
5
6
  key: "openai-new-file-created",
6
7
  name: "New File Created",
7
8
  description: "Emit new event when a new file is created in OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/files/list)",
8
- version: "0.0.5",
9
+ version: "0.0.6",
9
10
  type: "source",
10
11
  dedupe: "unique",
11
12
  props: {
@@ -21,7 +22,7 @@ export default {
21
22
  },
22
23
  methods: {
23
24
  ...common.methods,
24
- async getData() {
25
+ getData() {
25
26
  return this.openai.listFiles({
26
27
  purpose: this.purpose,
27
28
  });
@@ -34,4 +35,5 @@ export default {
34
35
  };
35
36
  },
36
37
  },
38
+ sampleEmit,
37
39
  };
@@ -0,0 +1,10 @@
1
+ export default {
2
+ "id": "file-abc123",
3
+ "object": "file",
4
+ "bytes": 140,
5
+ "created_at": 1613779121,
6
+ "filename": "puppy.jsonl",
7
+ "purpose": "fine-tune",
8
+ "status": "processed",
9
+ "status_details": null
10
+ }
@@ -1,16 +1,17 @@
1
- import common from "../common.mjs";
1
+ import common from "../common/common.mjs";
2
+ import sampleEmit from "./test-event.mjs";
2
3
 
3
4
  export default {
4
5
  ...common,
5
6
  key: "openai-new-fine-tuning-job-created",
6
7
  name: "New Fine Tuning Job Created",
7
8
  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)",
8
- version: "0.0.5",
9
+ version: "0.0.6",
9
10
  type: "source",
10
11
  dedupe: "unique",
11
12
  methods: {
12
13
  ...common.methods,
13
- async getData() {
14
+ getData() {
14
15
  return this.openai.listFineTuningJobs();
15
16
  },
16
17
  getMeta(item) {
@@ -21,4 +22,5 @@ export default {
21
22
  };
22
23
  },
23
24
  },
25
+ sampleEmit,
24
26
  };
@@ -0,0 +1,19 @@
1
+ export default {
2
+ "object": "fine_tuning.job",
3
+ "id": "ftjob-vbCfZSaivshuV18SjpCQwu2I",
4
+ "model": "gpt-3.5-turbo-0125",
5
+ "created_at": 1715284148,
6
+ "finished_at": null,
7
+ "fine_tuned_model": null,
8
+ "organization_id": "org-IQsNYSuAzzwvzXiKFGa1BeR4",
9
+ "result_files": [],
10
+ "status": "failed",
11
+ "validation_file": null,
12
+ "training_file": "file-D1svkZhYUtI4E8IpYsmIs3qY",
13
+ "hyperparameters": null,
14
+ "trained_tokens": null,
15
+ "user_provided_suffix": null,
16
+ "seed": 66573047,
17
+ "estimated_finish": null,
18
+ "integrations": []
19
+ }
@@ -1,11 +1,12 @@
1
- import common from "../common.mjs";
1
+ import common from "../common/common.mjs";
2
+ import sampleEmit from "./test-event.mjs";
2
3
 
3
4
  export default {
4
5
  ...common,
5
6
  key: "openai-new-run-state-changed",
6
7
  name: "New Run State Changed",
7
8
  description: "Emit new event every time a run changes its status. [See the documentation](https://platform.openai.com/docs/api-reference/runs/listRuns)",
8
- version: "0.0.1",
9
+ version: "0.0.2",
9
10
  type: "source",
10
11
  dedupe: "unique",
11
12
  props: {
@@ -81,4 +82,5 @@ export default {
81
82
  setStatusItems(buildStatusItems(data));
82
83
  },
83
84
  },
85
+ sampleEmit,
84
86
  };
@@ -0,0 +1,36 @@
1
+ export default {
2
+ "id": "run_RW7H8ICHslGIXBCBpgXn4OJy",
3
+ "object": "thread.run",
4
+ "created_at": 1715284963,
5
+ "assistant_id": "asst_aHkRGOagtHiTJJF7hNqLqcrv",
6
+ "thread_id": "thread_IqZAvwcU3SVsLeFeJ7fkx6LN",
7
+ "status": "completed",
8
+ "started_at": 1715284963,
9
+ "expires_at": null,
10
+ "cancelled_at": null,
11
+ "failed_at": null,
12
+ "completed_at": 1715284966,
13
+ "required_action": null,
14
+ "last_error": null,
15
+ "model": "gpt-4-turbo",
16
+ "instructions": "",
17
+ "tools": [],
18
+ "file_ids": [],
19
+ "metadata": {},
20
+ "temperature": 1,
21
+ "top_p": 1,
22
+ "max_completion_tokens": null,
23
+ "max_prompt_tokens": null,
24
+ "truncation_strategy": {
25
+ "type": "auto",
26
+ "last_messages": null
27
+ },
28
+ "incomplete_details": null,
29
+ "usage": {
30
+ "prompt_tokens": 25,
31
+ "completion_tokens": 25,
32
+ "total_tokens": 50
33
+ },
34
+ "response_format": "auto",
35
+ "tool_choice": "auto"
36
+ }
@@ -1,14 +0,0 @@
1
- export default {
2
- IMAGE_SIZES: [
3
- "256x256",
4
- "512x512",
5
- "1024x1024",
6
- ],
7
- TRANSCRIPTION_FORMATS: [
8
- "json",
9
- "text",
10
- "srt",
11
- "verbose_json",
12
- "vtt",
13
- ],
14
- };
@@ -1,64 +0,0 @@
1
- import openai from "../../openai.app.mjs";
2
-
3
- export default {
4
- key: "openai-create-message",
5
- name: "Create Message (Assistants)",
6
- description: "Create a message in a thread. [See the documentation](https://platform.openai.com/docs/api-reference/messages/createMessage)",
7
- version: "0.0.7",
8
- type: "action",
9
- props: {
10
- openai,
11
- threadId: {
12
- propDefinition: [
13
- openai,
14
- "threadId",
15
- ],
16
- },
17
- content: {
18
- propDefinition: [
19
- openai,
20
- "content",
21
- ],
22
- },
23
- role: {
24
- propDefinition: [
25
- openai,
26
- "role",
27
- ],
28
- default: "user",
29
- },
30
- fileIds: {
31
- propDefinition: [
32
- openai,
33
- "fileIds",
34
- ],
35
- optional: true,
36
- },
37
- metadata: {
38
- propDefinition: [
39
- openai,
40
- "metadata",
41
- ],
42
- optional: true,
43
- },
44
- },
45
- async run({ $ }) {
46
- const fileIdsArray = this.fileIds
47
- ? this.fileIds.map((fileId) => fileId.trim())
48
- : undefined;
49
- const metadataObject = this.metadata
50
- ? JSON.parse(this.metadata)
51
- : undefined;
52
-
53
- const response = await this.openai.createMessage({
54
- threadId: this.threadId,
55
- content: this.content,
56
- role: this.role,
57
- fileIds: fileIdsArray,
58
- metadata: metadataObject,
59
- });
60
-
61
- $.export("$summary", `Successfully created a message in thread ${this.threadId}`);
62
- return response;
63
- },
64
- };
@@ -1,65 +0,0 @@
1
- import { parseToolsArray } from "../../common/helpers.mjs";
2
- import openai from "../../openai.app.mjs";
3
-
4
- export default {
5
- key: "openai-create-run",
6
- name: "Create Run (Assistants)",
7
- description: "Creates a run given a thread ID and assistant ID. [See the documentation](https://platform.openai.com/docs/api-reference/runs/create)",
8
- version: "0.1.3",
9
- type: "action",
10
- props: {
11
- openai,
12
- threadId: {
13
- propDefinition: [
14
- openai,
15
- "threadId",
16
- ],
17
- },
18
- assistantId: {
19
- propDefinition: [
20
- openai,
21
- "assistantId",
22
- ],
23
- },
24
- model: {
25
- propDefinition: [
26
- openai,
27
- "model",
28
- ],
29
- },
30
- instructions: {
31
- propDefinition: [
32
- openai,
33
- "instructions",
34
- ],
35
- },
36
- tools: {
37
- propDefinition: [
38
- openai,
39
- "tools",
40
- ],
41
- },
42
- metadata: {
43
- propDefinition: [
44
- openai,
45
- "metadata",
46
- ],
47
- },
48
- },
49
- async run({ $ }) {
50
- const response = await this.openai.createRun({
51
- threadId: this.threadId,
52
- assistantId: this.assistantId,
53
- model: this.model,
54
- instructions: this.instructions,
55
- tools: parseToolsArray(this.tools),
56
- metadata: this.metadata,
57
- });
58
-
59
- const summary = response.id
60
- ? `Successfully created a run with ID: ${response.id}`
61
- : `Successfully created a run in thread ${this.threadId}`;
62
- $.export("$summary", summary);
63
- return response;
64
- },
65
- };
@@ -1,62 +0,0 @@
1
- import { parseToolsArray } from "../../common/helpers.mjs";
2
- import openai from "../../openai.app.mjs";
3
-
4
- export default {
5
- key: "openai-create-thread-and-run",
6
- name: "Create Thread and Run (Assistants)",
7
- description: "Create a thread and run it in one request using the specified assistant ID and optional parameters. [See the documentation](https://platform.openai.com/docs/api-reference)",
8
- version: "0.1.3",
9
- type: "action",
10
- props: {
11
- openai,
12
- assistantId: {
13
- propDefinition: [
14
- openai,
15
- "assistantId",
16
- ],
17
- },
18
- thread: {
19
- type: "object",
20
- label: "Thread",
21
- description: "The thread object containing messages and other optional properties.",
22
- optional: true,
23
- },
24
- model: {
25
- propDefinition: [
26
- openai,
27
- "model",
28
- ],
29
- },
30
- instructions: {
31
- propDefinition: [
32
- openai,
33
- "instructions",
34
- ],
35
- },
36
- tools: {
37
- propDefinition: [
38
- openai,
39
- "tools",
40
- ],
41
- },
42
- metadata: {
43
- propDefinition: [
44
- openai,
45
- "metadata",
46
- ],
47
- },
48
- },
49
- async run({ $ }) {
50
- const response = await this.openai.createThreadAndRun({
51
- assistant_id: this.assistantId,
52
- thread: this.thread,
53
- model: this.model,
54
- instructions: this.instructions,
55
- tools: parseToolsArray(this.tools),
56
- metadata: this.metadata,
57
- });
58
-
59
- $.export("$summary", `Successfully created thread and initiated run with ID: ${response.id}`);
60
- return response;
61
- },
62
- };
@@ -1,42 +0,0 @@
1
- import openai from "../../openai.app.mjs";
2
-
3
- export default {
4
- key: "openai-modify-message",
5
- name: "Modify Message (Assistants)",
6
- description: "Modifies an existing message in a thread. [See the documentation](https://platform.openai.com/docs/api-reference/messages/modifyMessage)",
7
- version: "0.0.7",
8
- type: "action",
9
- props: {
10
- openai,
11
- threadId: {
12
- propDefinition: [
13
- openai,
14
- "threadId",
15
- ],
16
- },
17
- messageId: {
18
- propDefinition: [
19
- openai,
20
- "messageId",
21
- ],
22
- },
23
- metadata: {
24
- type: "string",
25
- label: "Metadata",
26
- description: "Metadata for the message in JSON string format",
27
- optional: true,
28
- },
29
- },
30
- async run({ $ }) {
31
- const response = await this.openai.modifyMessage({
32
- threadId: this.threadId,
33
- messageId: this.messageId,
34
- metadata: this.metadata
35
- ? JSON.parse(this.metadata)
36
- : undefined,
37
- });
38
-
39
- $.export("$summary", `Successfully modified message ${this.messageId} in thread ${this.threadId}`);
40
- return response;
41
- },
42
- };
@@ -1,45 +0,0 @@
1
- import openai from "../../openai.app.mjs";
2
-
3
- export default {
4
- key: "openai-modify-run",
5
- name: "Modify Run (Assistants)",
6
- description: "Modifies an existing run. [See the documentation](https://platform.openai.com/docs/api-reference/runs/modifyRun)",
7
- version: "0.0.6",
8
- type: "action",
9
- props: {
10
- openai,
11
- threadId: {
12
- propDefinition: [
13
- openai,
14
- "threadId",
15
- ],
16
- },
17
- runId: {
18
- propDefinition: [
19
- openai,
20
- "runId",
21
- ({ threadId }) => ({
22
- threadId,
23
- }),
24
- ],
25
- },
26
- metadata: {
27
- propDefinition: [
28
- openai,
29
- "metadata",
30
- ],
31
- },
32
- },
33
- async run({ $ }) {
34
- const response = await this.openai.modifyRun({
35
- threadId: this.threadId,
36
- runId: this.runId,
37
- ...(this.metadata && {
38
- metadata: this.metadata,
39
- }),
40
- });
41
-
42
- $.export("$summary", `Successfully modified run with ID: ${this.runId}`);
43
- return response;
44
- },
45
- };