@pipedream/openai 0.1.10 → 0.3.0

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 (39) hide show
  1. package/actions/cancel-run/cancel-run.mjs +33 -0
  2. package/actions/chat/chat.mjs +20 -2
  3. package/actions/classify-items-into-categories/classify-items-into-categories.mjs +1 -1
  4. package/actions/common/common-helper.mjs +1 -1
  5. package/actions/common/common.mjs +28 -11
  6. package/actions/create-assistant/create-assistant.mjs +71 -0
  7. package/actions/create-embeddings/create-embeddings.mjs +2 -2
  8. package/actions/create-fine-tuning-job/create-fine-tuning-job.mjs +57 -0
  9. package/actions/create-image/create-image.mjs +55 -2
  10. package/actions/create-message/create-message.mjs +64 -0
  11. package/actions/create-run/create-run.mjs +64 -0
  12. package/actions/create-speech/create-speech.mjs +73 -0
  13. package/actions/create-thread/create-thread.mjs +36 -0
  14. package/actions/create-thread-and-run/create-thread-and-run.mjs +61 -0
  15. package/actions/create-transcription/create-transcription.mjs +2 -3
  16. package/actions/delete-file/delete-file.mjs +26 -0
  17. package/actions/list-files/list-files.mjs +27 -0
  18. package/actions/list-messages/list-messages.mjs +54 -0
  19. package/actions/list-run-steps/list-run-steps.mjs +65 -0
  20. package/actions/list-runs/list-runs.mjs +68 -0
  21. package/actions/modify-assistant/modify-assistant.mjs +82 -0
  22. package/actions/modify-message/modify-message.mjs +42 -0
  23. package/actions/modify-run/modify-run.mjs +42 -0
  24. package/actions/retrieve-file/retrieve-file.mjs +26 -0
  25. package/actions/retrieve-file-content/retrieve-file-content.mjs +25 -0
  26. package/actions/retrieve-run/retrieve-run.mjs +33 -0
  27. package/actions/retrieve-run-step/retrieve-run-step.mjs +40 -0
  28. package/actions/send-prompt/send-prompt.mjs +2 -2
  29. package/actions/submit-tool-outputs-to-run/submit-tool-outputs-to-run.mjs +41 -0
  30. package/actions/summarize/summarize.mjs +1 -1
  31. package/actions/translate-text/translate-text.mjs +1 -1
  32. package/actions/upload-file/upload-file.mjs +46 -0
  33. package/common/constants.mjs +23 -0
  34. package/openai.app.mjs +712 -0
  35. package/package.json +4 -3
  36. package/sources/common.mjs +51 -0
  37. package/sources/new-file-created/new-file-created.mjs +38 -0
  38. package/sources/new-fine-tuning-job-created/new-fine-tuning-job-created.mjs +24 -0
  39. package/app/openai.app.mjs +0 -180
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@pipedream/openai",
3
- "version": "0.1.10",
3
+ "version": "0.3.0",
4
4
  "description": "Pipedream OpenAI Components",
5
- "main": "app/openai.app.mjs",
5
+ "main": "openai.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "openai"
@@ -18,7 +18,8 @@
18
18
  "@pipedream/platform": "^1.2.1",
19
19
  "@pipedream/types": "^0.1.4",
20
20
  "got": "^12.6.0",
21
- "openai": "^3.2.1"
21
+ "openai": "^3.2.1",
22
+ "form-data": "^4.0.0"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@types/node": "^17.0.45"
@@ -0,0 +1,51 @@
1
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
+ import openai from "../openai.app.mjs";
3
+
4
+ export default {
5
+ props: {
6
+ openai,
7
+ db: "$.service.db",
8
+ timer: {
9
+ type: "$.interface.timer",
10
+ default: {
11
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12
+ },
13
+ },
14
+ },
15
+ methods: {
16
+ _getSavedItems() {
17
+ return this.db.get("savedItems") ?? [];
18
+ },
19
+ _setSavedItems(value) {
20
+ this.db.set("savedItems", value);
21
+ },
22
+ getMeta() {
23
+ throw new Error("No item metadata implemented!");
24
+ },
25
+ async getData() {
26
+ throw new Error("No item fetching implemented!");
27
+ },
28
+ async getAndProcessItems(maxEvents) {
29
+ const savedItems = this._getSavedItems();
30
+ const { data } = await this.getData();
31
+ data
32
+ ?.filter(({ id }) => !savedItems.includes(id))
33
+ .reverse()
34
+ .forEach((item, index) => {
35
+ if (!maxEvents || index < maxEvents) {
36
+ this.$emit(item, this.getMeta(item));
37
+ }
38
+ savedItems.push(item.id);
39
+ });
40
+ this._setSavedItems(savedItems);
41
+ },
42
+ },
43
+ hooks: {
44
+ async deploy() {
45
+ await this.getAndProcessItems(10);
46
+ },
47
+ },
48
+ async run() {
49
+ await this.getAndProcessItems();
50
+ },
51
+ };
@@ -0,0 +1,38 @@
1
+ import openai from "../../openai.app.mjs";
2
+ import common from "../common.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ key: "openai-new-file-created",
7
+ name: "New File Created",
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)",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ props: {
13
+ ...common.props,
14
+ purpose: {
15
+ propDefinition: [
16
+ openai,
17
+ "purpose",
18
+ ],
19
+ description: "If specified, events will only be emitted for files with the specified purpose.",
20
+ optional: true,
21
+ },
22
+ },
23
+ methods: {
24
+ ...common.methods,
25
+ async getData() {
26
+ return this.openai.listFiles({
27
+ purpose: this.purpose,
28
+ });
29
+ },
30
+ getMeta(item) {
31
+ return {
32
+ id: item.id,
33
+ summary: `New File: ${item.filename}`,
34
+ ts: item.created_at * 1000,
35
+ };
36
+ },
37
+ },
38
+ };
@@ -0,0 +1,24 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "openai-new-fine-tuning-job-created",
6
+ name: "New Fine Tuning Job Created",
7
+ 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.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getData() {
14
+ return this.openai.listFineTuningJobs();
15
+ },
16
+ getMeta(item) {
17
+ return {
18
+ id: item.id,
19
+ summary: `New Fine Tuning Job: ${item.id}`,
20
+ ts: item.created_at * 1000,
21
+ };
22
+ },
23
+ },
24
+ };
@@ -1,180 +0,0 @@
1
- import { axios } from "@pipedream/platform";
2
-
3
- export default {
4
- type: "app",
5
- app: "openai",
6
- propDefinitions: {
7
- completionModelId: {
8
- label: "Model",
9
- description: "The ID of the model to use for completions. **This action doesn't support the ChatGPT `turbo` models**. Use the **Chat** action for those, instead.",
10
- type: "string",
11
- async options() {
12
- return (await this.getCompletionModels({})).map((model) => model.id);
13
- },
14
- default: "text-davinci-003",
15
- },
16
- chatCompletionModelId: {
17
- label: "Model",
18
- description: "The ID of the model to use for chat completions",
19
- type: "string",
20
- async options() {
21
- return (await this.getChatCompletionModels({})).map((model) => model.id);
22
- },
23
- default: "gpt-3.5-turbo",
24
- },
25
- embeddingsModelId: {
26
- label: "Model",
27
- description: "The ID of the embeddings model to use. OpenAI recommends using `text-embedding-ada-002` for nearly all use cases: \"It's better, cheaper, and simpler to use. [Read the blog post announcement](https://openai.com/blog/new-and-improved-embedding-model)\".",
28
- type: "string",
29
- async options() {
30
- return (await this.getEmbeddingsModels({})).map((model) => model.id);
31
- },
32
- default: "text-embedding-ada-002",
33
- },
34
- },
35
- methods: {
36
- _apiKey() {
37
- return this.$auth.api_key;
38
- },
39
- _baseApiUrl() {
40
- return "https://api.openai.com/v1";
41
- },
42
- _commonHeaders() {
43
- return {
44
- "Authorization": `Bearer ${this._apiKey()}`,
45
- "Accept": "application/json",
46
- "User-Agent": "@PipedreamHQ/pipedream v1.0",
47
- };
48
- },
49
- async _makeRequest({
50
- $ = this,
51
- path,
52
- ...args
53
- } = {}) {
54
- return axios($, {
55
- url: `${this._baseApiUrl()}${path}`,
56
- headers: {
57
- ...this._commonHeaders(),
58
- },
59
- maxBodyLength: Infinity,
60
- ...args,
61
- });
62
- },
63
- async models({ $ }) {
64
- const { data: models } = await this._makeRequest({
65
- $,
66
- path: "/models",
67
- });
68
- return models.sort((a, b) => a?.id.localeCompare(b?.id));
69
- },
70
- async getChatCompletionModels({ $ }) {
71
- const models = await this.models({
72
- $,
73
- });
74
- return models.filter((model) => model.id.match(/turbo|gpt/gi));
75
- },
76
- async getCompletionModels({ $ }) {
77
- const models = await this.models({
78
- $,
79
- });
80
- return models.filter((model) => {
81
- const { id } = model;
82
- return (
83
- id.match(/^(?=.*\b(babbage|davinci|ada|curie)\b)(?!.*\b(whisper|turbo|edit|insert|search|embedding|similarity|001)\b).*$/gm)
84
- );
85
- });
86
- },
87
- async getEmbeddingsModels({ $ }) {
88
- const models = await this.models({
89
- $,
90
- });
91
- return models.filter((model) => {
92
- const { id } = model;
93
- return (
94
- id.match(/^(text-embedding-ada-002|.*-(davinci|curie|babbage|ada)-.*-001)$/gm)
95
- );
96
- });
97
- },
98
- async _makeCompletion({
99
- $, path, args,
100
- }) {
101
- const data = await this._makeRequest({
102
- $,
103
- path,
104
- method: "POST",
105
- data: args,
106
- });
107
-
108
- // For completions, return the text of the first choice at the top-level
109
- let generated_text;
110
- if (path === "/completions") {
111
- const { choices } = data;
112
- generated_text = choices?.[0]?.text;
113
- }
114
- // For chat completions, return the assistant message at the top-level
115
- let generated_message;
116
- if (path === "/chat/completions") {
117
- const { choices } = data;
118
- generated_message = choices?.[0]?.message;
119
- }
120
-
121
- return {
122
- generated_text,
123
- generated_message,
124
- ...data,
125
- };
126
- },
127
- async createCompletion({
128
- $, args,
129
- }) {
130
- return this._makeCompletion({
131
- $,
132
- path: "/completions",
133
- args,
134
- });
135
- },
136
- async createChatCompletion({
137
- $, args,
138
- }) {
139
- return this._makeCompletion({
140
- $,
141
- path: "/chat/completions",
142
- args,
143
- });
144
- },
145
- async createImage({
146
- $, args,
147
- }) {
148
- return this._makeRequest({
149
- $,
150
- path: "/images/generations",
151
- data: args,
152
- method: "POST",
153
- });
154
- },
155
- async createEmbeddings({
156
- $, args,
157
- }) {
158
- return this._makeRequest({
159
- $,
160
- path: "/embeddings",
161
- data: args,
162
- method: "POST",
163
- });
164
- },
165
- async createTranscription({
166
- $, form,
167
- }) {
168
- return this._makeRequest({
169
- $,
170
- path: "/audio/transcriptions",
171
- method: "POST",
172
- headers: {
173
- ...this._commonHeaders(),
174
- "Content-Type": `multipart/form-data; boundary=${form._boundary}`,
175
- },
176
- data: form,
177
- });
178
- },
179
- },
180
- };