@kumologica/sdk 4.0.0 → 4.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/package.json +7 -7
- package/src/app/lib/ai/openai.js +0 -108
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumologica/sdk",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"productName": "Kumologica Designer",
|
|
5
5
|
"copyright": "Copyright 2020 Kumologica Pty Ltd, All Rights Reserved.",
|
|
6
6
|
"author": "Kumologica Pty Ltd <contact@kumologica.com>",
|
|
@@ -88,9 +88,9 @@
|
|
|
88
88
|
"@aws-sdk/signature-v4": "^3.370.0",
|
|
89
89
|
"@aws-sdk/types": "^3.936.0",
|
|
90
90
|
"@electron/remote": "^2.0.8",
|
|
91
|
-
"@kumologica/builder": "4.0.
|
|
92
|
-
"@kumologica/devkit": "4.0.
|
|
93
|
-
"@kumologica/runtime": "4.0.
|
|
91
|
+
"@kumologica/builder": "4.0.1",
|
|
92
|
+
"@kumologica/devkit": "4.0.1",
|
|
93
|
+
"@kumologica/runtime": "4.0.1",
|
|
94
94
|
"ajv": "8.10.0",
|
|
95
95
|
"archive-type": "^4.0.0",
|
|
96
96
|
"basic-auth": "2.0.1",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"js-yaml": "3.13.1",
|
|
128
128
|
"json-cycle": "^1.3.0",
|
|
129
129
|
"jsonata": "1.7.0",
|
|
130
|
-
"jsonpath": "1.0
|
|
130
|
+
"jsonpath": "1.3.0",
|
|
131
131
|
"make-dir": "^3.1.0",
|
|
132
132
|
"memorystore": "1.6.1",
|
|
133
133
|
"mime": "2.4.4",
|
|
@@ -179,8 +179,8 @@
|
|
|
179
179
|
"grunt-terser": "2.0.0",
|
|
180
180
|
"istanbul": "^0.4.5",
|
|
181
181
|
"license-checker": "^25.0.1",
|
|
182
|
-
"license-compatibility-checker": "^0.3.
|
|
183
|
-
"license-report": "^
|
|
182
|
+
"license-compatibility-checker": "^0.3.5",
|
|
183
|
+
"license-report": "^6.8.2",
|
|
184
184
|
"mocha": "10.2.0",
|
|
185
185
|
"node-sass": "9.0.0",
|
|
186
186
|
"tslint": "^5.18.0",
|
package/src/app/lib/ai/openai.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const OpenAI = require('openai');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { applyLayout } = require('./layout');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require('dotenv').config()
|
|
8
|
-
|
|
9
|
-
// utils
|
|
10
|
-
function unescapeObject(obj) {
|
|
11
|
-
// Check if the input is an object
|
|
12
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
13
|
-
return obj; // Return as is if not an object
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Iterate over each property of the object
|
|
17
|
-
for (let key in obj) {
|
|
18
|
-
if (obj.hasOwnProperty(key)) {
|
|
19
|
-
// If the property is a string, unescape it
|
|
20
|
-
if (typeof obj[key] === 'string') {
|
|
21
|
-
obj[key] = unescapeString(obj[key]);
|
|
22
|
-
}
|
|
23
|
-
// If the property is an object, recursively unescape its properties
|
|
24
|
-
else if (typeof obj[key] === 'object') {
|
|
25
|
-
obj[key] = unescapeObject(obj[key]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return obj;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Function to unescape a string
|
|
34
|
-
function unescapeString(str) {
|
|
35
|
-
// Remove all occurrences of "\n
|
|
36
|
-
str = str.replace(/\\n\s*|\\n/g, '');
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return str.replace(/\\(.)/g, function (_, char) {
|
|
40
|
-
switch (char) {
|
|
41
|
-
case 'n': return '\n'; // Replace '\n' with newline character
|
|
42
|
-
case 't': return '\t'; // Replace '\t' with tab character
|
|
43
|
-
case 'r': return '\r'; // Replace '\r' with carriage return character
|
|
44
|
-
case 'b': return '\b'; // Replace '\b' with backspace character
|
|
45
|
-
case 'f': return '\f'; // Replace '\f' with form feed character
|
|
46
|
-
case '\\': return '\\'; // Replace '\\' with backslash character
|
|
47
|
-
case '"': return '"'; // Replace '\"' with double quote character
|
|
48
|
-
case "'": return "'"; // Replace "\'" with single quote character
|
|
49
|
-
default: return char; // Return the character as is if not an escape sequence
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class OpenAIClient {
|
|
56
|
-
// attributes
|
|
57
|
-
openai = null;
|
|
58
|
-
version = null;
|
|
59
|
-
|
|
60
|
-
constructor(props) {
|
|
61
|
-
this.openai = new OpenAI({
|
|
62
|
-
apiKey: props.key || process.env.OPENAI_API_KEY || '***',
|
|
63
|
-
dangerouslyAllowBrowser: true
|
|
64
|
-
});
|
|
65
|
-
this.version = props.version || 'gpt-3.5-turbo';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getSystemPrompt() {
|
|
69
|
-
if (!this.systemPrompt) {
|
|
70
|
-
try {
|
|
71
|
-
this.systemPrompt = fs.readFileSync(path.join(__dirname, 'prompt.txt'), 'utf-8');
|
|
72
|
-
} catch (err) {
|
|
73
|
-
throw err;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return this.systemPrompt;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async t2c(userTask) {
|
|
80
|
-
let userMessage = `
|
|
81
|
-
Generate kumologica flow. Do not include any extra explanation, just the json document. For the following user description:
|
|
82
|
-
${userTask}`;
|
|
83
|
-
try {
|
|
84
|
-
let spec = this.getSystemPrompt();
|
|
85
|
-
const chatCompletion = await this.openai.chat.completions.create({
|
|
86
|
-
model: this.version,
|
|
87
|
-
messages: [
|
|
88
|
-
{ role: 'system', content: spec },
|
|
89
|
-
{ role: 'user', content: userMessage }
|
|
90
|
-
]
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const resp = chatCompletion.choices[0].message.content;
|
|
94
|
-
console.log('[openai] Resp=', resp);
|
|
95
|
-
const respo = JSON.parse(resp);
|
|
96
|
-
console.log('[openai] Resp.flow=', JSON.parse(respo.flow));
|
|
97
|
-
console.log('[openai] Unscaped - Resp.flow', unescapeObject(JSON.parse(respo.flow)));
|
|
98
|
-
return applyLayout(unescapeObject(JSON.parse(respo.flow)));
|
|
99
|
-
} catch (err) {
|
|
100
|
-
console.log(err);
|
|
101
|
-
throw new Error(err.toString());
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = {
|
|
107
|
-
OpenAIClient
|
|
108
|
-
}
|