@pipedream/openai 0.0.1

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.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2020 Pipedream, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ export default {
2
+ IMAGE_SIZES: [
3
+ "256x256",
4
+ "512x512",
5
+ "1024x1024",
6
+ ],
7
+ RESPONSE_FORMATS: [
8
+ "url",
9
+ "b64_json",
10
+ ],
11
+ };
@@ -0,0 +1,55 @@
1
+ import openai from "../../openai.app.mjs";
2
+ import constants from "../common/constants.mjs";
3
+
4
+ export default {
5
+ name: "Create Image",
6
+ version: "0.0.1",
7
+ key: "openai-create-image",
8
+ description: "Creates an image given a prompt. [See docs here](https://beta.openai.com/docs/api-reference/images/create)",
9
+ type: "action",
10
+ props: {
11
+ openai,
12
+ prompt: {
13
+ label: "Prompt",
14
+ description: "A text description of the desired image(s). The maximum length is 1000 characters.",
15
+ type: "string",
16
+ },
17
+ n: {
18
+ label: "N",
19
+ description: "The number of images to generate. Must be between 1 and 10.",
20
+ type: "integer",
21
+ optional: true,
22
+ },
23
+ size: {
24
+ label: "Size",
25
+ description: "The size of the generated images.",
26
+ type: "string",
27
+ optional: true,
28
+ options: constants.IMAGE_SIZES,
29
+ },
30
+ responseFormat: {
31
+ label: "Response Format",
32
+ description: "The format in which the generated images are returned.",
33
+ type: "string",
34
+ optional: true,
35
+ options: constants.RESPONSE_FORMATS,
36
+ },
37
+ },
38
+ async run({ $ }) {
39
+ const response = await this.openai.createImage({
40
+ $,
41
+ data: {
42
+ prompt: this.prompt,
43
+ n: this.n,
44
+ size: this.size,
45
+ response_format: this.responseFormat,
46
+ },
47
+ });
48
+
49
+ if (response) {
50
+ $.export("$summary", `Successfully created image with id ${response.id}`);
51
+ }
52
+
53
+ return response;
54
+ },
55
+ };
@@ -0,0 +1,111 @@
1
+ import openai from "../../openai.app.mjs";
2
+
3
+ export default {
4
+ name: "Send Prompt",
5
+ version: "0.0.1",
6
+ key: "openai-send-prompt",
7
+ description: "Creates a completion for the provided prompt and parameters. [See docs here](https://beta.openai.com/docs/api-reference/completions/create)",
8
+ type: "action",
9
+ props: {
10
+ openai,
11
+ modelId: {
12
+ propDefinition: [
13
+ openai,
14
+ "modelId",
15
+ ],
16
+ },
17
+ prompt: {
18
+ label: "Prompt",
19
+ description: "The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document.",
20
+ type: "string[]",
21
+ optional: true,
22
+ },
23
+ suffix: {
24
+ label: "Suffix",
25
+ description: "The suffix that comes after a completion of inserted text.",
26
+ type: "string",
27
+ optional: true,
28
+ },
29
+ maxTokens: {
30
+ label: "Max Tokens",
31
+ description: "The maximum number of [tokens](https://beta.openai.com/tokenizer) to generate in the completion.",
32
+ type: "integer",
33
+ optional: true,
34
+ },
35
+ temperature: {
36
+ label: "Temperature",
37
+ description: "What [sampling temperature](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277) to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer.",
38
+ type: "string",
39
+ optional: true,
40
+ },
41
+ topP: {
42
+ label: "Top P",
43
+ description: "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.",
44
+ type: "string",
45
+ optional: true,
46
+ },
47
+ n: {
48
+ label: "N",
49
+ description: "How many completions to generate for each prompt.",
50
+ type: "string",
51
+ optional: true,
52
+ },
53
+ stop: {
54
+ label: "Stop",
55
+ description: "Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.",
56
+ type: "string[]",
57
+ optional: true,
58
+ },
59
+ presencePenalty: {
60
+ label: "Presence Penalty",
61
+ description: "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.",
62
+ type: "string",
63
+ optional: true,
64
+ },
65
+ frequencyPenalty: {
66
+ label: "Frequency Penalty",
67
+ description: "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.",
68
+ type: "string",
69
+ optional: true,
70
+ },
71
+ bestOf: {
72
+ label: "Best Of",
73
+ description: "Generates best_of completions server-side and returns the \"best\" (the one with the highest log probability per token). Results cannot be streamed.",
74
+ type: "integer",
75
+ optional: true,
76
+ },
77
+ },
78
+ async run({ $ }) {
79
+ const response = await this.openai.sendPrompt({
80
+ $,
81
+ data: {
82
+ model: this.modelId,
83
+ prompt: this.prompt,
84
+ max_tokens: this.maxTokens,
85
+ temperature: this.temperature
86
+ ? +this.temperature
87
+ : this.temperature,
88
+ top_p: this.topP
89
+ ? +this.topP
90
+ : this.topP,
91
+ n: this.n
92
+ ? +this.n
93
+ : this.n,
94
+ stop: this.stop,
95
+ presence_penalty: this.presencePenalty
96
+ ? +this.presencePenalty
97
+ : this.presencePenalty,
98
+ frequency_penalty: this.frequencyPenalty
99
+ ? +this.frequencyPenalty
100
+ : this.frequencyPenalty,
101
+ best_of: this.bestOf,
102
+ },
103
+ });
104
+
105
+ if (response) {
106
+ $.export("$summary", `Successfully sent prompt with id ${response.id}`);
107
+ }
108
+
109
+ return response;
110
+ },
111
+ };
package/openai.app.mjs ADDED
@@ -0,0 +1,57 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "openai",
6
+ propDefinitions: {
7
+ modelId: {
8
+ label: "Model ID",
9
+ description: "ID of the model to use",
10
+ type: "string",
11
+ async options() {
12
+ const { data: models } = await this.getModels();
13
+
14
+ return models.map((model) => model.id);
15
+ },
16
+ },
17
+ },
18
+ methods: {
19
+ _apiKey() {
20
+ return this.$auth.api_key;
21
+ },
22
+ _apiUrl() {
23
+ return "https://api.openai.com/v1";
24
+ },
25
+ async _makeRequest({
26
+ $ = this, path, ...args
27
+ }) {
28
+ return axios($, {
29
+ url: `${this._apiUrl()}${path}`,
30
+ headers: {
31
+ Authorization: `Bearer ${this._apiKey()}`,
32
+ },
33
+ ...args,
34
+ });
35
+ },
36
+ async getModels(args = {}) {
37
+ return this._makeRequest({
38
+ path: "/models",
39
+ ...args,
40
+ });
41
+ },
42
+ async sendPrompt(args = {}) {
43
+ return this._makeRequest({
44
+ path: "/completions",
45
+ method: "post",
46
+ ...args,
47
+ });
48
+ },
49
+ async createImage(args = {}) {
50
+ return this._makeRequest({
51
+ path: "/images/generations",
52
+ method: "post",
53
+ ...args,
54
+ });
55
+ },
56
+ },
57
+ };
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipedream/openai",
3
+ "version": "0.0.1",
4
+ "description": "Pipedream OpenAI Components",
5
+ "main": "openai.app.mjs",
6
+ "keywords": [
7
+ "pipedream",
8
+ "openai"
9
+ ],
10
+ "homepage": "https://pipedream.com/apps/openai",
11
+ "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
+ "license": "MIT",
13
+ "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "dependencies": {
18
+ "@pipedream/platform": "^1.2.1"
19
+ }
20
+ }