@inductiv/node-red-openai-api 0.3.4 → 0.3.6
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/lib.js +26 -2
- package/node.js +4 -0
- package/package.json +3 -3
package/lib.js
CHANGED
|
@@ -29,6 +29,11 @@ var OpenaiApi = (function () {
|
|
|
29
29
|
}
|
|
30
30
|
return headers;
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
setNodeRef(node){
|
|
34
|
+
this.node = node;
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
getFromEndpoint(path, parameters, expectedQueryParams, customHeaders) {
|
|
33
38
|
return new Promise((resolve, reject) => {
|
|
34
39
|
var domain = this.domain;
|
|
@@ -148,18 +153,37 @@ var OpenaiApi = (function () {
|
|
|
148
153
|
headers: headers,
|
|
149
154
|
params: queryParameters,
|
|
150
155
|
data: data,
|
|
156
|
+
responseType: data.stream === true ? "stream" : "json"
|
|
151
157
|
};
|
|
152
158
|
|
|
153
|
-
// Axios POST request
|
|
154
159
|
axios(config)
|
|
155
160
|
.then((response) => {
|
|
156
|
-
|
|
161
|
+
if (config.responseType === "stream") {
|
|
162
|
+
// Handle the stream response
|
|
163
|
+
response.data.on('data', (chunk) => {
|
|
164
|
+
// Convert chunk from Uint8Array to string
|
|
165
|
+
const chunkAsString = new TextDecoder().decode(chunk);
|
|
166
|
+
|
|
167
|
+
// Emit converted data chunks as Node-RED messages
|
|
168
|
+
this.node.send({ payload: chunkAsString });
|
|
169
|
+
}).on('end', () => {
|
|
170
|
+
// Handle the end of the stream
|
|
171
|
+
resolve({ payload: "Stream ended" });
|
|
172
|
+
}).on('error', (err) => {
|
|
173
|
+
// Handle any errors
|
|
174
|
+
reject(err);
|
|
175
|
+
});
|
|
176
|
+
} else {
|
|
177
|
+
// Handle non-stream response (e.g., JSON)
|
|
178
|
+
resolve(response);
|
|
179
|
+
}
|
|
157
180
|
})
|
|
158
181
|
.catch((error) => {
|
|
159
182
|
reject(error);
|
|
160
183
|
});
|
|
161
184
|
});
|
|
162
185
|
}
|
|
186
|
+
|
|
163
187
|
deleteFromEndpoint(path, parameters, expectedQueryParams, customHeaders) {
|
|
164
188
|
return new Promise((resolve, reject) => {
|
|
165
189
|
parameters = parameters || {};
|
package/node.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inductiv/node-red-openai-api",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "Go beyond ChatGPT and DALL·E 3: this Node-RED node seamlessly integrates a range of OpenAI services, including Assistants, Threads, Vision, and Audio, enabling
|
|
3
|
+
"version": "0.3.6",
|
|
4
|
+
"description": "Go beyond ChatGPT and DALL·E 3: this Node-RED node seamlessly integrates a range of OpenAI services, including Assistants, Threads, Vision, and Audio, enabling feature-rich enhancement of your AI workflows with any OpenAI REST API-compatible solution.",
|
|
5
5
|
"main": "node.js",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=12.0.0"
|
|
@@ -40,4 +40,4 @@
|
|
|
40
40
|
"type": "git",
|
|
41
41
|
"url": "git+https://github.com/allanbunch/node-red-openai-api.git"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|