-
Notifications
You must be signed in to change notification settings - Fork 0
/
subflow.json
202 lines (202 loc) · 9.18 KB
/
subflow.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
{
"id": "70c990f5226211c0",
"type": "subflow",
"name": "Image Generation",
"info": "## Properties\n\n - **[Required]** `msg.OPENAI_API_KEY`: This is the API key provided by OpenAI. It is necessary for authentication when making requests to the OpenAI API.\n\n1. When `msg.type` is set to `create_image`:\n - **[Required]** `msg.prompt`: A text description of the desired image(s). The maximum length is 1000 characters.\n\n - `msg.n`: The number of images to generate. Must be between 1 and 10.\n - `msg.size`: The size of the generated images. Must be one of ***256x256***, ***512x512***, or ***1024x1024***.\n - `msg.response_format`: The format in which the generated images are returned. Must be one of ***url*** or ***b64_json***.\n - `msg.user`: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids)\n\n2. When `msg.type` is set to `create_image_edit`:\n - **[Required]** `msg.image`: The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask. For example:\n ```json\n msg.image = {\n \"value\": msg.req.files[0].buffer,\n \"options\": {\n \"filename\": msg.req.files[0].originalname\n }\n };\n ```\n\n - `msg.mask`: An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`. For example\n ```json\n msg.mask = {\n \"value\": msg.req.files[1].buffer,\n \"options\": {\n \"filename\": msg.req.files[1].originalname\n }\n };\n ```\n\n - **[Required]** `msg.prompt`: A text description of the desired image(s). The maximum length is 1000 characters.\n\n - `msg.n`: The number of images to generate. Must be between 1 and 10.\n - `msg.size`: The size of the generated images. Must be one of ***256x256***, ***512x512***, or ***1024x1024***.\n - `msg.response_format`: The format in which the generated images are returned. Must be one of ***url*** or ***b64_json***.\n - `msg.user`: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids)\n\n3. When `msg.type` is set to `create_image_variation`:\n - **[Required]** `msg.image`: The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square. For example\n ```json\n msg.image = {\n \"value\": msg.req.files[0].buffer,\n \"options\": {\n \"filename\": msg.req.files[0].originalname\n }\n };\n ```\n - `msg.n`: The number of images to generate. Must be between 1 and 10.\n \n - `msg.size`: The size of the generated images. Must be one of ***256x256***, ***512x512***, or ***1024x1024***.\n - `msg.response_format`: The format in which the generated images are returned. Must be one of ***url*** or ***b64_json***.\n - `msg.user`: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids)\n",
"category": "",
"in": [
{
"x": 200,
"y": 160,
"wires": [
{
"id": "83490fe977b3b046"
}
]
}
],
"out": [
{
"x": 620,
"y": 200,
"wires": [
{
"id": "83490fe977b3b046",
"port": 1
},
{
"id": "98bd7701e736895c",
"port": 0
}
]
}
],
"env": [
{
"name": "OPENAI_API_KEY",
"type": "cred",
"ui": {
"label": {
"en-US": "OpenAI Key"
},
"type": "input",
"opts": {
"types": [
"cred"
]
}
}
},
{
"name": "prompt",
"type": "str",
"value": "",
"ui": {
"label": {
"en-US": "Prompt"
},
"type": "input",
"opts": {
"types": [
"str"
]
}
}
},
{
"name": "actionType",
"type": "str",
"value": "create_image",
"ui": {
"label": {
"en-US": "Type"
},
"type": "select",
"opts": {
"opts": [
{
"l": {
"en-US": "create_image"
},
"v": "create_image"
},
{
"l": {
"en-US": "create_image_edit"
},
"v": "create_image_edit"
},
{
"l": {
"en-US": "create_image_variation"
},
"v": "create_image_variation"
}
]
}
}
}
],
"meta": {
"module": "node-red-contrib-image-generation-ubos",
"type": "image-generation-ubos",
"version": "1.0.0",
"author": "vovajr11",
"desc": "Descr",
"keywords": "node-red",
"license": "MIT"
},
"credentials": {
"OPENAI_API_KEY": "",
"has_OPENAI_API_KEY": false
},
"color": "#74AA9C",
"status": {
"x": 440,
"y": 240,
"wires": [
{
"id": "d6b1390ae936e28f",
"port": 0
}
]
},
"flow": [
{
"id": "83490fe977b3b046",
"type": "function",
"z": "70c990f5226211c0",
"name": "Request to OpenAI",
"func": "/*\n Type: Create image\n @param \"OPENAI_API_KEY\" {string} Required\n @param \"prompt\" {string} Required\n @param \"n\" {integer} Optional | Defaults to 1\n @param \"size\" {string} Optional | Defaults to 1024x1024\n @param \"response_format\" {string} Optional | Defaults to url\n @param \"user\" {string} Optional\n*/\n\n/*\n Type: Create image edit\n @param \"OPENAI_API_KEY\" {string} Required\n @param \"prompt\" {string} Required\n @param \"image\" {string} Required\n @param \"mask\" {string} Optional\n @param \"n\" {integer} Optional | Defaults to 1\n @param \"size\" {string} Optional | Defaults to 1024x1024\n @param \"response_format\" {string} Optional | Defaults to url\n @param \"user\" {string} Optional\n*/\n\n/*\n Type: Create image variation\n @param \"OPENAI_API_KEY\" {string} Required\n @param \"image\" {string} Required\n @param \"n\" {integer} Optional | Defaults to 1\n @param \"size\" {string} Optional | Defaults to 1024x1024\n @param \"response_format\" {string} Optional | Defaults to url\n @param \"user\" {string} Optional\n*/\n\nconst actionType = msg.type || env.get(\"actionType\"); // \"create_image\" | \"create_image_edit\" | \"create_image_variation\"\n\nif (!env.get(\"OPENAI_API_KEY\") && !msg.OPENAI_API_KEY) {\n msg.payload = \"Enter OPENAI_API_KEY\";\n node.status({ fill: \"red\", shape: \"dot\", text: \"disconnected\" });\n\n return [null, msg];\n}\n\nconst baseRequestBody = {\n n: msg.n,\n size: msg.size,\n response_format: msg.response_format,\n user: msg.user,\n}\n\nmsg.method = \"POST\";\n\nif (actionType === \"create_image\") {\n msg.headers = {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${env.get(\"OPENAI_API_KEY\") || msg.OPENAI_API_KEY}`\n };\n\n msg.url = `https://api.openai.com/v1/images/generations`;\n\n msg.payload = {\n ...baseRequestBody,\n prompt: msg.prompt\n };\n\n reqStatus();\n\n return [msg, null];\n}\n\nif (actionType === \"create_image_edit\") {\n msg.headers = {\n 'Content-Type': 'multipart/form-data',\n 'Authorization': `Bearer ${env.get(\"OPENAI_API_KEY\") || msg.OPENAI_API_KEY}`\n };\n\n msg.url = `https://api.openai.com/v1/images/edits`;\n\n msg.payload = {\n ...baseRequestBody,\n image: msg.image,\n mask: msg.mask,\n prompt: msg.prompt\n };\n\n reqStatus();\n\n return [msg, null];\n}\n\nif (actionType === \"create_image_variation\") {\n msg.headers = {\n 'Content-Type': 'multipart/form-data',\n 'Authorization': `Bearer ${env.get(\"OPENAI_API_KEY\") || msg.OPENAI_API_KEY}`\n };\n\n msg.url = `https://api.openai.com/v1/images/variations`;\n \n msg.payload = {\n ...baseRequestBody,\n image: msg.image,\n };\n\n reqStatus();\n\n return [msg, null];\n}\n\nmsg.payload = \"Invalid type\";\nnode.status({ fill: \"red\", shape: \"dot\", text: \"disconnected\" });\n\nfunction reqStatus() {\n return node.status({ fill: \"blue\", shape: \"dot\", text: \"requesting\" });\n}\n\nreturn [null, msg];",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 350,
"y": 160,
"wires": [
[
"887d96a7616d4c54"
],
[]
]
},
{
"id": "887d96a7616d4c54",
"type": "http request",
"z": "70c990f5226211c0",
"name": "Open AI",
"method": "use",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 540,
"y": 120,
"wires": [
[
"98bd7701e736895c"
]
]
},
{
"id": "d6b1390ae936e28f",
"type": "status",
"z": "70c990f5226211c0",
"name": "",
"scope": [
"83490fe977b3b046",
"98bd7701e736895c"
],
"x": 320,
"y": 240,
"wires": [
[]
]
},
{
"id": "98bd7701e736895c",
"type": "function",
"z": "70c990f5226211c0",
"name": "set status",
"func": "node.status({ fill: \"green\", shape: \"dot\", text: \"finished\" });\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 700,
"y": 120,
"wires": [
[]
]
}
]
}