@pipedream/openai 0.1.10 → 0.2.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 (33) hide show
  1. package/actions/cancel-run/cancel-run.mjs +33 -0
  2. package/actions/chat/chat.mjs +9 -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 +25 -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-image/create-image.mjs +55 -2
  9. package/actions/create-message/create-message.mjs +64 -0
  10. package/actions/create-run/create-run.mjs +64 -0
  11. package/actions/create-thread/create-thread.mjs +36 -0
  12. package/actions/create-thread-and-run/create-thread-and-run.mjs +61 -0
  13. package/actions/create-transcription/create-transcription.mjs +2 -3
  14. package/actions/delete-file/delete-file.mjs +26 -0
  15. package/actions/list-files/list-files.mjs +26 -0
  16. package/actions/list-messages/list-messages.mjs +54 -0
  17. package/actions/list-run-steps/list-run-steps.mjs +65 -0
  18. package/actions/list-runs/list-runs.mjs +68 -0
  19. package/actions/modify-assistant/modify-assistant.mjs +82 -0
  20. package/actions/modify-message/modify-message.mjs +42 -0
  21. package/actions/modify-run/modify-run.mjs +42 -0
  22. package/actions/retrieve-file/retrieve-file.mjs +26 -0
  23. package/actions/retrieve-file-content/retrieve-file-content.mjs +25 -0
  24. package/actions/retrieve-run/retrieve-run.mjs +33 -0
  25. package/actions/retrieve-run-step/retrieve-run-step.mjs +40 -0
  26. package/actions/send-prompt/send-prompt.mjs +2 -2
  27. package/actions/submit-tool-outputs-to-run/submit-tool-outputs-to-run.mjs +41 -0
  28. package/actions/summarize/summarize.mjs +1 -1
  29. package/actions/translate-text/translate-text.mjs +1 -1
  30. package/actions/upload-file/upload-file.mjs +41 -0
  31. package/openai.app.mjs +627 -0
  32. package/package.json +1 -1
  33. package/app/openai.app.mjs +0 -180
@@ -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
- };