@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
@@ -1,11 +1,12 @@
1
- import { parseToolsArray } from "../../common/helpers.mjs";
2
1
  import openai from "../../openai.app.mjs";
2
+ import common from "../common/common-assistants.mjs";
3
3
 
4
4
  export default {
5
+ ...common,
5
6
  key: "openai-create-assistant",
6
7
  name: "Create Assistant",
7
- description: "Creates an assistant with a model and instructions. [See the docs here](https://platform.openai.com/docs/api-reference/assistants/createAssistant)",
8
- version: "0.1.3",
8
+ description: "Creates an assistant with a model and instructions. [See the documentation](https://platform.openai.com/docs/api-reference/assistants/createAssistant)",
9
+ version: "0.1.4",
9
10
  type: "action",
10
11
  props: {
11
12
  openai,
@@ -33,35 +34,26 @@ export default {
33
34
  "instructions",
34
35
  ],
35
36
  },
36
- tools: {
37
- propDefinition: [
38
- openai,
39
- "tools",
40
- ],
41
- },
42
- file_ids: {
43
- propDefinition: [
44
- openai,
45
- "file_ids",
46
- ],
47
- },
48
37
  metadata: {
49
38
  propDefinition: [
50
39
  openai,
51
40
  "metadata",
52
41
  ],
53
42
  },
43
+ ...common.props,
54
44
  },
55
45
  async run({ $ }) {
56
46
  const response = await this.openai.createAssistant({
57
47
  $,
58
- model: this.model,
59
- name: this.name,
60
- description: this.description,
61
- instructions: this.instructions,
62
- tools: parseToolsArray(this.tools),
63
- file_ids: this.file_ids,
64
- metadata: this.metadata,
48
+ data: {
49
+ model: this.model,
50
+ name: this.name,
51
+ description: this.description,
52
+ instructions: this.instructions,
53
+ tools: this.buildTools(),
54
+ tool_resources: this.buildToolResources(),
55
+ metadata: this.metadata,
56
+ },
65
57
  });
66
58
 
67
59
  $.export("$summary", `Successfully created an assistant with ID: ${response.id}`);
@@ -0,0 +1,78 @@
1
+ import openai from "../../openai.app.mjs";
2
+ import constants from "../../common/constants.mjs";
3
+ import { ConfigurationError } from "@pipedream/platform";
4
+ import FormData from "form-data";
5
+ import fs from "fs";
6
+
7
+ export default {
8
+ key: "openai-create-batch",
9
+ name: "Create Batch",
10
+ description: "Creates and executes a batch from an uploaded file of requests. [See the documentation](https://platform.openai.com/docs/api-reference/batch/create)",
11
+ version: "0.0.1",
12
+ type: "action",
13
+ props: {
14
+ openai,
15
+ endpoint: {
16
+ type: "string",
17
+ label: "Endpoint",
18
+ description: "The endpoint to be used for all requests in the batch",
19
+ options: constants.BATCH_ENDPOINTS,
20
+ },
21
+ fileId: {
22
+ propDefinition: [
23
+ openai,
24
+ "fileId",
25
+ () => ({
26
+ purpose: "batch",
27
+ }),
28
+ ],
29
+ optional: true,
30
+ },
31
+ filePath: {
32
+ type: "string",
33
+ label: "File Path",
34
+ description: "The path to a .jsonl file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
35
+ optional: true,
36
+ },
37
+ metadata: {
38
+ propDefinition: [
39
+ openai,
40
+ "metadata",
41
+ ],
42
+ },
43
+ },
44
+ async run({ $ }) {
45
+ if (!this.fileId && !this.filePath) {
46
+ throw new ConfigurationError("Must provide one of File ID or File Path");
47
+ }
48
+
49
+ let fileId = this.fileId;
50
+ if (this.filePath) {
51
+ const fileData = new FormData();
52
+ const content = fs.createReadStream(this.filePath.includes("tmp/")
53
+ ? this.filePath
54
+ : `/tmp/${this.filePath}`);
55
+ fileData.append("purpose", "batch");
56
+ fileData.append("file", content);
57
+
58
+ const { id } = await this.openai.uploadFile({
59
+ $,
60
+ data: fileData,
61
+ headers: fileData.getHeaders(),
62
+ });
63
+ fileId = id;
64
+ }
65
+
66
+ const response = await this.openai.createBatch({
67
+ $,
68
+ data: {
69
+ input_file_id: fileId,
70
+ endpoint: this.endpoint,
71
+ completion_window: "24h",
72
+ metadata: this.metadata,
73
+ },
74
+ });
75
+ $.export("$summary", `Successfully created batch with ID ${response.id}`);
76
+ return response;
77
+ },
78
+ };
@@ -4,9 +4,9 @@ import common from "../common/common.mjs";
4
4
 
5
5
  export default {
6
6
  name: "Create Embeddings",
7
- version: "0.0.8",
7
+ version: "0.0.9",
8
8
  key: "openai-create-embeddings",
9
- description: "Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. [See the docs here](https://platform.openai.com/docs/api-reference/embeddings)",
9
+ 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)",
10
10
  type: "action",
11
11
  props: {
12
12
  openai,
@@ -36,7 +36,7 @@ export default {
36
36
 
37
37
  const response = await this.openai.createEmbeddings({
38
38
  $,
39
- args: {
39
+ data: {
40
40
  model: this.modelId,
41
41
  input: this.input,
42
42
  },
@@ -4,7 +4,7 @@ export default {
4
4
  key: "openai-create-fine-tuning-job",
5
5
  name: "Create Fine Tuning Job",
6
6
  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)",
7
- version: "0.0.5",
7
+ version: "0.0.6",
8
8
  type: "action",
9
9
  props: {
10
10
  openai,
@@ -17,8 +17,13 @@ export default {
17
17
  trainingFile: {
18
18
  propDefinition: [
19
19
  openai,
20
- "trainingFile",
20
+ "fileId",
21
+ () => ({
22
+ purpose: "fine-tune",
23
+ }),
21
24
  ],
25
+ label: "Training File",
26
+ description: "The ID of an uploaded file that contains training data. You can use the **Upload File** action and reference the returned ID here.",
22
27
  },
23
28
  hyperParameters: {
24
29
  type: "object",
@@ -33,7 +38,13 @@ export default {
33
38
  optional: true,
34
39
  },
35
40
  validationFile: {
36
- type: "string",
41
+ propDefinition: [
42
+ openai,
43
+ "fileId",
44
+ () => ({
45
+ purpose: "fine-tune",
46
+ }),
47
+ ],
37
48
  label: "Validation File",
38
49
  description: "The ID of an uploaded file that contains validation data. [See details in the documentation](https://platform.openai.com/docs/api-reference/fine-tuning/create#fine-tuning-create-validation_file).",
39
50
  optional: true,
@@ -1,10 +1,11 @@
1
1
  import openai from "../../openai.app.mjs";
2
+ import constants from "../../common/constants.mjs";
2
3
 
3
4
  export default {
4
5
  name: "Create Image (Dall-E)",
5
- version: "0.1.13",
6
+ version: "0.1.14",
6
7
  key: "openai-create-image",
7
- description: "Creates an image given a prompt returning a URL to the image. [See docs here](https://platform.openai.com/docs/api-reference/images)",
8
+ description: "Creates an image given a prompt returning a URL to the image. [See the documentation](https://platform.openai.com/docs/api-reference/images)",
8
9
  type: "action",
9
10
  props: {
10
11
  openai,
@@ -12,79 +13,20 @@ export default {
12
13
  label: "Model",
13
14
  description: "Choose the DALL·E models to generate image(s) with.",
14
15
  type: "string",
15
- options: [
16
- {
17
- label: "dall-e-2",
18
- value: "dall-e-2",
19
- },
20
- {
21
- label: "dall-e-3",
22
- value: "dall-e-3",
23
- },
24
- ],
25
- default: "dall-e-3",
16
+ options: constants.IMAGE_MODELS,
17
+ reloadProps: true,
26
18
  },
27
19
  prompt: {
28
20
  label: "Prompt",
29
- description: "A text description of the desired image(s). The maximum length is 1000 characters.",
21
+ description: "A text description of the desired image(s). The maximum length is 1000 characters for dall-e-2 and 4000 characters for dall-e-3.",
30
22
  type: "string",
31
23
  },
32
- n: {
33
- label: "N",
34
- description: "The number of images to generate. Must be between 1 and 10.",
35
- type: "integer",
36
- optional: true,
37
- default: 1,
38
- },
39
- quality: {
40
- label: "Quality",
41
- description: "The quality of the image",
42
- type: "string",
43
- optional: true,
44
- options: [
45
- {
46
- label: "Standard",
47
- value: "standard",
48
- },
49
- {
50
- label: "HD",
51
- value: "hd",
52
- },
53
- ],
54
- default: "standard",
55
- },
56
- style: {
57
- label: "Style",
58
- description: "The style of the image",
59
- type: "string",
60
- optional: true,
61
- options: [
62
- {
63
- label: "Natural",
64
- value: "natural",
65
- },
66
- {
67
- label: "Vivid",
68
- value: "vivid",
69
- },
70
- ],
71
- default: "natural",
72
- },
73
24
  responseFormat: {
74
25
  label: "Response Format",
75
26
  description: "The format in which the generated images are returned.",
76
27
  type: "string",
77
28
  optional: true,
78
- options: [
79
- {
80
- label: "URL",
81
- value: "url",
82
- },
83
- {
84
- label: "Base64 JSON",
85
- value: "b64_json",
86
- },
87
- ],
29
+ options: constants.IMAGE_RESPONSE_FORMATS,
88
30
  default: "url",
89
31
  },
90
32
  size: {
@@ -92,35 +34,47 @@ export default {
92
34
  description: "The size of the generated images.",
93
35
  type: "string",
94
36
  optional: true,
95
- options: [
96
- {
97
- label: "256x256",
98
- value: "256x256",
99
- },
100
- {
101
- label: "512x512",
102
- value: "512x512",
103
- },
104
- {
105
- label: "1024x1024",
106
- value: "1024x1024",
107
- },
108
- {
109
- label: "1792x1024",
110
- value: "1792x1024",
111
- },
112
- {
113
- label: "1024x1792",
114
- value: "1024x1792",
115
- },
116
- ],
37
+ options: constants.IMAGE_SIZES,
117
38
  default: "1024x1024",
118
39
  },
119
40
  },
41
+ async additionalProps() {
42
+ const props = {};
43
+ if (!this.model) {
44
+ return props;
45
+ }
46
+ if (this.model !== "dall-e-3") {
47
+ props.n = {
48
+ type: "integer",
49
+ label: "N",
50
+ description: "The number of images to generate. Must be between 1 and 10.",
51
+ optional: true,
52
+ default: 1,
53
+ };
54
+ } else {
55
+ props.quality = {
56
+ type: "string",
57
+ label: "Quality",
58
+ description: "The quality of the image",
59
+ options: constants.IMAGE_QUALITIES,
60
+ optional: true,
61
+ default: "standard",
62
+ };
63
+ props.style = {
64
+ type: "string",
65
+ label: "Style",
66
+ description: "The style of the image",
67
+ options: constants.IMAGE_STYLES,
68
+ optional: true,
69
+ default: "natural",
70
+ };
71
+ }
72
+ return props;
73
+ },
120
74
  async run({ $ }) {
121
75
  const response = await this.openai.createImage({
122
76
  $,
123
- args: {
77
+ data: {
124
78
  prompt: this.prompt,
125
79
  n: this.n,
126
80
  size: this.size,
@@ -0,0 +1,35 @@
1
+ import openai from "../../openai.app.mjs";
2
+ import constants from "../../common/constants.mjs";
3
+
4
+ export default {
5
+ key: "openai-create-moderation",
6
+ name: "Create Moderation",
7
+ description: "Classifies if text is potentially harmful. [See the documentation](https://platform.openai.com/docs/api-reference/moderations/create)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ openai,
12
+ input: {
13
+ type: "string",
14
+ label: "Input",
15
+ description: "The input text to classify",
16
+ },
17
+ model: {
18
+ type: "string",
19
+ label: "Model",
20
+ description: "The model to use",
21
+ options: constants.MODERATION_MODELS,
22
+ },
23
+ },
24
+ async run({ $ }) {
25
+ const response = await this.openai.createModeration({
26
+ $,
27
+ data: {
28
+ input: this.input,
29
+ model: this.model,
30
+ },
31
+ });
32
+ $.export("$summary", `Successfully created moderation with ID ${response.id}`);
33
+ return response;
34
+ },
35
+ };
@@ -1,10 +1,12 @@
1
1
  import openai from "../../openai.app.mjs";
2
+ import common from "../common/common-assistants.mjs";
3
+ import constants from "../../common/constants.mjs";
2
4
 
3
5
  export default {
4
6
  key: "openai-create-thread",
5
7
  name: "Create Thread (Assistants)",
6
- description: "Creates a thread with optional messages and metadata. [See the documentation](https://platform.openai.com/docs/api-reference/threads/createThread)",
7
- version: "0.0.5",
8
+ 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)",
9
+ version: "0.0.6",
8
10
  type: "action",
9
11
  props: {
10
12
  openai,
@@ -22,15 +24,115 @@ export default {
22
24
  ],
23
25
  optional: true,
24
26
  },
27
+ runThread: {
28
+ type: "boolean",
29
+ label: "Run Thread",
30
+ description: "Set to `true` to run the thread after creation",
31
+ optional: true,
32
+ reloadProps: true,
33
+ },
34
+ toolTypes: {
35
+ type: "string[]",
36
+ label: "Tool Types",
37
+ description: "The types of tools to enable on the assistant",
38
+ options: constants.TOOL_TYPES.filter((type) => type !== "function"),
39
+ optional: true,
40
+ reloadProps: true,
41
+ },
42
+ },
43
+ async additionalProps() {
44
+ const props = {};
45
+ if (this.runThread) {
46
+ props.assistantId = {
47
+ type: "string",
48
+ label: "Assistant ID",
49
+ description: "The unique identifier for the assistant.",
50
+ options: async () => { return this.getAssistantPropOptions(); },
51
+ };
52
+ props.model = {
53
+ type: "string",
54
+ label: "Model",
55
+ description: "The ID of the model to use for the assistant",
56
+ options: async () => { return this.getAssistantModelPropOptions(); },
57
+ };
58
+ props.instructions = {
59
+ type: "string",
60
+ label: "Instructions",
61
+ description: "The system instructions that the assistant uses.",
62
+ optional: true,
63
+ };
64
+ props.waitForCompletion = {
65
+ type: "boolean",
66
+ label: "Wait For Completion",
67
+ description: "Set to `true` to poll the API in 3-second intervals until the run is completed",
68
+ optional: true,
69
+ };
70
+ }
71
+ const toolProps = this.toolTypes?.length
72
+ ? await this.getToolProps()
73
+ : {};
74
+ return {
75
+ ...props,
76
+ ...toolProps,
77
+ };
78
+ },
79
+ methods: {
80
+ ...common.methods,
81
+ async getAssistantPropOptions() {
82
+ const { data } = await this.openai.listAssistants();
83
+ return data.map(({
84
+ name, id,
85
+ }) => ({
86
+ label: name || id,
87
+ value: id,
88
+ }));
89
+ },
90
+ async getAssistantModelPropOptions() {
91
+ const models = (await this.openai.models({})).filter(({ id }) => (id.includes("gpt-3.5-turbo") || id.includes("gpt-4-turbo")) && (id !== "gpt-3.5-turbo-0301"));
92
+ return models.map(({ id }) => id);
93
+ },
25
94
  },
26
95
  async run({ $ }) {
27
- const response = await this.openai.createThread({
28
- $,
29
- messages: this.messages,
30
- metadata: this.metadata,
31
- });
96
+ const messages = this.messages?.length
97
+ ? this.messages.map((message) => ({
98
+ role: "user",
99
+ content: message,
100
+ }))
101
+ : undefined;
102
+ let response = !this.runThread
103
+ ? await this.openai.createThread({
104
+ $,
105
+ data: {
106
+ messages,
107
+ metadata: this.metadata,
108
+ tool_resources: this.buildToolResources(),
109
+ },
110
+ })
111
+ : await this.openai.createThreadAndRun({
112
+ $,
113
+ data: {
114
+ assistant_id: this.assistantId,
115
+ thread: {
116
+ messages,
117
+ metadata: this.metadata,
118
+ },
119
+ model: this.model,
120
+ instructions: this.instructions,
121
+ tools: this.buildTools(),
122
+ tool_resources: this.buildToolResources(),
123
+ metadata: this.metadata,
124
+ },
125
+ });
126
+
127
+ if (this.waitForCompletion) {
128
+ const runId = response.id;
129
+ const threadId = response.thread_id;
130
+ response = await this.pollRunUntilCompleted(response, threadId, runId, $);
131
+ }
32
132
 
33
- $.export("$summary", `Successfully created a thread with ID: ${response.id}`);
133
+ $.export("$summary", `Successfully created a thread ${this.runThread
134
+ ? "and run"
135
+ : ""} with ID: ${response.id}`);
34
136
  return response;
35
137
  },
36
138
  };
@@ -13,7 +13,7 @@ import stream from "stream";
13
13
  import { promisify } from "util";
14
14
  import openai from "../../openai.app.mjs";
15
15
  import common from "../common/common.mjs";
16
- import constants from "../common/constants.mjs";
16
+ import constants from "../../common/constants.mjs";
17
17
  import lang from "../common/lang.mjs";
18
18
 
19
19
  const COMMON_AUDIO_FORMATS_TEXT = "Your audio file must be in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.";
@@ -24,9 +24,9 @@ const pipelineAsync = promisify(stream.pipeline);
24
24
 
25
25
  export default {
26
26
  name: "Create Transcription (Whisper)",
27
- version: "0.1.8",
27
+ version: "0.1.9",
28
28
  key: "openai-create-transcription",
29
- description: "Transcribes audio into the input language. [See docs here](https://platform.openai.com/docs/api-reference/audio/create).",
29
+ description: "Transcribes audio into the input language. [See the documentation](https://platform.openai.com/docs/api-reference/audio/create).",
30
30
  type: "action",
31
31
  props: {
32
32
  openai,
@@ -227,7 +227,7 @@ export default {
227
227
 
228
228
  file = path;
229
229
  } else if (url) {
230
- const ext = extname(url);
230
+ const ext = extname(url).split("?")[0];
231
231
 
232
232
  const response = await axios({
233
233
  method: "GET",
@@ -4,23 +4,24 @@ export default {
4
4
  key: "openai-delete-file",
5
5
  name: "Delete File",
6
6
  description: "Deletes a specified file from OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/files/delete)",
7
- version: "0.0.6",
7
+ version: "0.0.7",
8
8
  type: "action",
9
9
  props: {
10
10
  openai,
11
- file_id: {
11
+ fileId: {
12
12
  propDefinition: [
13
13
  openai,
14
- "file_id",
14
+ "fileId",
15
15
  ],
16
16
  },
17
17
  },
18
18
  async run({ $ }) {
19
19
  const response = await this.openai.deleteFile({
20
- file_id: this.file_id,
20
+ $,
21
+ file_id: this.fileId,
21
22
  });
22
23
 
23
- $.export("$summary", `Successfully deleted file with ID: ${this.file_id}`);
24
+ $.export("$summary", `Successfully deleted file with ID: ${this.fileId}`);
24
25
  return response;
25
26
  },
26
27
  };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "openai-list-files",
5
5
  name: "List Files",
6
6
  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)",
7
- version: "0.0.6",
7
+ version: "0.0.7",
8
8
  type: "action",
9
9
  props: {
10
10
  openai,
@@ -18,9 +18,10 @@ export default {
18
18
  },
19
19
  async run({ $ }) {
20
20
  const response = await this.openai.listFiles({
21
+ $,
21
22
  purpose: this.purpose,
22
23
  });
23
- const summary = `Successfully listed ${response.length} files`;
24
+ const summary = `Successfully listed ${response.data.length} files`;
24
25
  $.export("$summary", summary);
25
26
  return response;
26
27
  },
@@ -4,7 +4,7 @@ export default {
4
4
  key: "openai-list-messages",
5
5
  name: "List Messages (Assistants)",
6
6
  description: "Lists the messages for a given thread. [See the documentation](https://platform.openai.com/docs/api-reference/messages/listMessages)",
7
- version: "0.0.7",
7
+ version: "0.0.8",
8
8
  type: "action",
9
9
  props: {
10
10
  openai,
@@ -26,29 +26,26 @@ export default {
26
26
  "order",
27
27
  ],
28
28
  },
29
- after: {
30
- propDefinition: [
31
- openai,
32
- "after",
33
- ],
34
- },
35
- before: {
36
- propDefinition: [
37
- openai,
38
- "before",
39
- ],
40
- },
41
29
  },
42
30
  async run({ $ }) {
43
- const response = await this.openai.listMessages({
44
- threadId: this.threadId,
45
- limit: this.limit,
46
- order: this.order,
47
- after: this.after,
48
- before: this.before,
31
+ const response = this.openai.paginate({
32
+ resourceFn: this.openai.listMessages,
33
+ args: {
34
+ $,
35
+ threadId: this.threadId,
36
+ params: {
37
+ order: this.order,
38
+ },
39
+ },
40
+ max: this.limit,
49
41
  });
50
42
 
51
- $.export("$summary", `Successfully listed ${response.data.length} messages for thread ID ${this.threadId}`);
52
- return response.data;
43
+ const messages = [];
44
+ for await (const message of response) {
45
+ messages.push(message);
46
+ }
47
+
48
+ $.export("$summary", `Successfully listed ${messages.length} messages for thread ID ${this.threadId}`);
49
+ return messages;
53
50
  },
54
51
  };