dbm-graph-api 1.1.15 → 1.1.16

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.15",
3
+ "version": "1.1.16",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -0,0 +1,69 @@
1
+ import Dbm from "dbm";
2
+
3
+ export default class HelpSectionSuggestions extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ async getData(aData, aEncodeSession) {
9
+
10
+ await aEncodeSession.outputController.requireRole("admin");
11
+
12
+ let returnObject = {};
13
+
14
+ let content = aData["value"];
15
+ returnObject["content"] = content;
16
+
17
+ let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
18
+ let item = await database.createObject("private", ["aiGeneratedHelpSectionSuggestions"]);
19
+ await item.updateField("content", content);
20
+ returnObject["id"] = item.id;
21
+
22
+ let alreadyAdded = [
23
+ "All about this section"
24
+ ];
25
+
26
+ let alreadyAddedString = "The page already have these titles: " + JSON.stringify(alreadyAdded);
27
+
28
+ let contentString = "Content of the page: " + JSON.stringify(content);
29
+
30
+ let instructions = "Analyze the content and generate a list of questions and link titles that this page answers. Do the link titles as a call to action. {additionalInstructions} Respond with only a json object {helpSectionTitles: array of {question: string, linkTitle: string}}, no markdown.";
31
+ instructions = instructions.split("{data}").join(contentString);
32
+
33
+ let additionalInstructions = "";
34
+ instructions = instructions.split("{additionalInstructions}").join(additionalInstructions);
35
+
36
+ let body = {
37
+ "model": "gpt-4o-mini",
38
+ "response_format": { "type": "json_object" },
39
+ "messages": [
40
+ {"role":"system","content": instructions},
41
+ {"role": "user", "content": alreadyAddedString},
42
+ {"role": "user", "content": contentString}
43
+ ],
44
+ "temperature": 0.1
45
+ }
46
+
47
+ let headers = {
48
+ "Content-Type": "application/json",
49
+ 'Authorization': 'Bearer ' + Dbm.getInstance().repository.getItem("openAi").token
50
+ }
51
+
52
+ let response = await fetch('https://api.openai.com/v1/chat/completions', {
53
+ method: "POST",
54
+ headers: headers,
55
+ body: JSON.stringify(body),
56
+ });
57
+
58
+ let data = await response.json();
59
+ await item.updateField("response", data);
60
+
61
+ let message = data.choices[0].message;
62
+ let responseContent = JSON.parse(message.content);
63
+ console.log(responseContent);
64
+
65
+ returnObject["titles"] = responseContent["helpSectionTitles"];
66
+
67
+ return returnObject;
68
+ }
69
+ }
@@ -2,6 +2,7 @@ export {default as Example} from "./Example.js";
2
2
  export {default as UploadS3} from "./UploadS3.js";
3
3
  export {default as FreeUrl} from "./FreeUrl.js";
4
4
  export {default as SeoSummary} from "./SeoSummary.js";
5
+ export {default as HelpSectionSuggestions} from "./HelpSectionSuggestions.js";
5
6
  export {default as AltText} from "./AltText.js";
6
7
  export {default as Breadcrumb} from "./Breadcrumb.js";
7
8
  export {default as Question} from "./Question.js";
@@ -208,6 +208,7 @@ let fullDataSetup = function() {
208
208
 
209
209
  registerDataFunction("admin/freeUrl", new DbmGraphApi.data.FreeUrl());
210
210
  registerDataFunction("admin/seoSummary", new DbmGraphApi.data.SeoSummary());
211
+ registerDataFunction("admin/helpSectionSuggestions", new DbmGraphApi.data.HelpSectionSuggestions());
211
212
  registerDataFunction("admin/altText", new DbmGraphApi.data.AltText());
212
213
 
213
214
  registerDataFunction("server/status", new DbmGraphApi.data.server.Status());