dbm-graph-api 1.1.14 → 1.1.15
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbm-graph-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@aws-sdk/client-s3": "^3.741.0",
|
|
15
15
|
"@aws-sdk/s3-request-presigner": "^3.741.0",
|
|
16
|
-
"dbm": "^1.1.
|
|
16
|
+
"dbm": "^1.1.11",
|
|
17
17
|
"mime": "^4.0.6",
|
|
18
18
|
"sharp": "^0.33.5",
|
|
19
19
|
"ws": "^8.18.0"
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import DbmGraphApi from "../../../index.js";
|
|
3
|
+
|
|
4
|
+
export default class Question extends Dbm.core.BaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getData(aData, aEncodeSession) {
|
|
10
|
+
let returnObject = {};
|
|
11
|
+
|
|
12
|
+
let question = aData["value"];
|
|
13
|
+
returnObject["question"] = question;
|
|
14
|
+
|
|
15
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
16
|
+
let questionItem = await database.createObject("private", ["customerQuestion"]);
|
|
17
|
+
await questionItem.updateField("question", question);
|
|
18
|
+
returnObject["id"] = questionItem.id;
|
|
19
|
+
|
|
20
|
+
let selectQuery = new DbmGraphApi.range.Query();
|
|
21
|
+
await selectQuery.setObjectType("helpSection");
|
|
22
|
+
selectQuery.includePrivate();
|
|
23
|
+
let items = await selectQuery.getObjects();
|
|
24
|
+
|
|
25
|
+
let currentArray = items;
|
|
26
|
+
let currentArrayLength = currentArray.length;
|
|
27
|
+
let helpPages = new Array(currentArrayLength);
|
|
28
|
+
|
|
29
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
30
|
+
let currentItem = currentArray[i];
|
|
31
|
+
let fields = await currentItem.getFields();
|
|
32
|
+
|
|
33
|
+
let codedObject = {id: currentItem.id, content: fields.title};
|
|
34
|
+
helpPages[i] = codedObject;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let helpPagesString = JSON.stringify(helpPages);
|
|
38
|
+
|
|
39
|
+
console.log(helpPages);
|
|
40
|
+
|
|
41
|
+
let instructions = "Find out which the best help pages for the question and return the id from this json: {data}. {additionalInstructions} Respond with only a json object {hasMatch: boolean, pages: array with ids of the pages (in order of relevance)}, no markdown.";
|
|
42
|
+
instructions = instructions.split("{data}").join(helpPagesString);
|
|
43
|
+
|
|
44
|
+
let additionalInstructions = "Units are stored in square feet, so convert square meters to feet.";
|
|
45
|
+
instructions = instructions.split("{additionalInstructions}").join(additionalInstructions);
|
|
46
|
+
|
|
47
|
+
let body = {
|
|
48
|
+
"model": "gpt-4o-mini",
|
|
49
|
+
"response_format": { "type": "json_object" },
|
|
50
|
+
"messages": [
|
|
51
|
+
{"role":"system","content": instructions},
|
|
52
|
+
{"role": "user", "content": question}
|
|
53
|
+
],
|
|
54
|
+
"temperature": 0.7
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let headers = {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
'Authorization': 'Bearer ' + Dbm.getInstance().repository.getItem("openAi").token
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: headers,
|
|
65
|
+
body: JSON.stringify(body),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
let data = await response.json();
|
|
69
|
+
await questionItem.updateField("response", data);
|
|
70
|
+
|
|
71
|
+
let message = data.choices[0].message;
|
|
72
|
+
let content = JSON.parse(message.content);
|
|
73
|
+
console.log(content);
|
|
74
|
+
|
|
75
|
+
let pages = [];
|
|
76
|
+
{
|
|
77
|
+
let currentArray = content.pages;
|
|
78
|
+
let currentArrayLength = currentArray.length;
|
|
79
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
80
|
+
let currentId = 1*currentArray[i];
|
|
81
|
+
|
|
82
|
+
if(!isNaN(currentId)) {
|
|
83
|
+
pages.push(currentId);
|
|
84
|
+
await aEncodeSession.encodeSingle(currentId, "helpSection");
|
|
85
|
+
await questionItem.addIncomingRelation(currentId, "suggestedFor");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
returnObject["answers"] = pages;
|
|
91
|
+
|
|
92
|
+
return returnObject;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -4,6 +4,7 @@ export {default as FreeUrl} from "./FreeUrl.js";
|
|
|
4
4
|
export {default as SeoSummary} from "./SeoSummary.js";
|
|
5
5
|
export {default as AltText} from "./AltText.js";
|
|
6
6
|
export {default as Breadcrumb} from "./Breadcrumb.js";
|
|
7
|
+
export {default as Question} from "./Question.js";
|
|
7
8
|
|
|
8
9
|
export * as server from "./server/index.js";
|
|
9
10
|
|
|
@@ -181,6 +181,13 @@ let fullEncodeSetup = function() {
|
|
|
181
181
|
currentEncode.item.register(encodePrefix + name);
|
|
182
182
|
currentEncode.item.setValue("encodingType", name);
|
|
183
183
|
}
|
|
184
|
+
|
|
185
|
+
{
|
|
186
|
+
let name = "helpSection";
|
|
187
|
+
let currentEncode = new DbmGraphApi.range.encode.HelpSection();
|
|
188
|
+
currentEncode.item.register(encodePrefix + name);
|
|
189
|
+
currentEncode.item.setValue("encodingType", name);
|
|
190
|
+
}
|
|
184
191
|
}
|
|
185
192
|
|
|
186
193
|
export {fullEncodeSetup};
|
|
@@ -197,6 +204,7 @@ let fullDataSetup = function() {
|
|
|
197
204
|
registerDataFunction("example", new DbmGraphApi.data.Example());
|
|
198
205
|
|
|
199
206
|
registerDataFunction("breadcrumb", new DbmGraphApi.data.Breadcrumb());
|
|
207
|
+
registerDataFunction("question", new DbmGraphApi.data.Question());
|
|
200
208
|
|
|
201
209
|
registerDataFunction("admin/freeUrl", new DbmGraphApi.data.FreeUrl());
|
|
202
210
|
registerDataFunction("admin/seoSummary", new DbmGraphApi.data.SeoSummary());
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class HelpSection extends EncodeBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getEncodedData(aId, aEncodingSession) {
|
|
10
|
+
|
|
11
|
+
let returnObject = {};
|
|
12
|
+
|
|
13
|
+
let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
|
|
14
|
+
|
|
15
|
+
let fields = await object.getFields();
|
|
16
|
+
returnObject["title"] = fields["title"] !== null ? fields["title"] : null;
|
|
17
|
+
returnObject["link"] = fields["link"] !== null ? fields["link"] : null;
|
|
18
|
+
|
|
19
|
+
return returnObject;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -16,5 +16,6 @@ export {default as Relations} from "./Relations.js";
|
|
|
16
16
|
export {default as ObjectTypes} from "./ObjectTypes.js";
|
|
17
17
|
export {default as RepresentingPage} from "./RepresentingPage.js";
|
|
18
18
|
export {default as PageRepresentation} from "./PageRepresentation.js";
|
|
19
|
+
export {default as HelpSection} from "./HelpSection.js";
|
|
19
20
|
|
|
20
21
|
export * as admin from "./admin/index.js";
|