Read the statement by Michael Teeuw here.
ChatGpt intergration
-
@SILLEN-0 Log is not defined in Rainmap, nothing after that runs
only in browser side
best when doing your dev is to only use your module
add console.log stmts to your node_helper so u can see it’s progress in the console output
-
yea i fixed that problem but now with the same script it is just stuck at loading response
-
@SILLEN-0 look at the logs… loading means data did not arrive to replace the dummy message
-
@SILLEN-0 did the node helper get a response from lib?
-
i think the problem is with node helper not actually sending a api request because if i look in usage tab on the openai api page it should show activity but it says that it has not recieved any api requests:
but it should work! im going too look into it now and see if i can fix it. -
@SILLEN-0 as I said add console.log statements to the node helper so you can see the flow in the console output…
-
yea i just did that and i get this error in the console:
0|MagicMirror | [14.01.2023 13:01.03.714] [LOG] Received QUESTION notification with payload: What is the weather like today? 0|MagicMirror | [14.01.2023 13:01.03.724] [LOG] Error in getResponse: TypeError: Cannot set properties of undefined (setting 'apiKey') 0|MagicMirror | at /home/pi/MagicMirror/modules/chatgpt/node_helper.js:12:27 0|MagicMirror | at new Promise (<anonymous>) 0|MagicMirror | at Class.getResponse (/home/pi/MagicMirror/modules/chatgpt/node_helper.js:11:16) 0|MagicMirror | at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/chatgpt/node_helper.js:31:18) 0|MagicMirror | at Socket.<anonymous> (/home/pi/MagicMirror/js/node_helper.js:108:11) 0|MagicMirror | at Socket.emit (node:events:513:28) 0|MagicMirror | at Socket.emitUntyped (/home/pi/MagicMirror/node_modules/socket.io/dist/typed-events.js:69:22) 0|MagicMirror | at /home/pi/MagicMirror/node_modules/socket.io/dist/socket.js:614:39 0|MagicMirror | at process.processTicksAndRejections (node:internal/process/task_queues:78:11)
and this is my node_helper file:
const NodeHelper = require("node_helper"); const openai = require("openai").default; console.log(openai); module.exports = NodeHelper.create({ start: function() { console.log("Starting node helper for: " + this.name); }, // Send a message to the chatGPT API and receive a response getResponse: function(question) { return new Promise((resolve, reject) => { openai.apiKey = "XXXXXXXXXXXXXX"; openai.Completion.create({ prompt: question, temperature: 0.7 }, (error, response) => { if (error) { reject(error); } else { console.log("Received response from API: ", response); resolve(response.choices[0].text); } }); }); }, // Handle socket notifications socketNotificationReceived: function(notification, payload) { if (notification === "QUESTION") { console.log("Received QUESTION notification with payload: ", payload); this.getResponse(payload) .then((response) => { console.log("Sending RESPONSE notification with payload: ", response); this.sendSocketNotification("RESPONSE", response); }) .catch((error) => { console.log("Error in getResponse: ", error); }); } }, });
-
@SILLEN-0 was openainin context before the
return new Promise inside getResponse() -
@sdetweil if im honest i have no idea what you mean by that. as i said i am very bad at any sort of coding this whole thing is held up with ducktape could you try to explain more what you mean by that?
-
@SILLEN-0 the error says that at the time of trying to to assign the apiKey to the openai object, the openai object is null (0)
TypeError: Cannot set properties of undefined (setting 'apiKey') 0|MagicMirror | at /home/pi/MagicMirror/modules/chatgpt/node_helper.js:12:27
‘undefined’ here is openai,
so, I see you print the object just after the require() at the top
const openai = require("openai").default; console.log(openai);
and ‘assume’ that you looked at the output of npm start (where console.log messages go) and are satisfied that the require(‘openai’) worked
so now to check again later
so I would add and another console.log(openai)
after the getResponse:getResponse: function(question) { // here .. is the openai object good (not null) here? return new Promise((resolve, reject) => { openai.apiKey = "XXXXXXXXXXXXXX"; // this is the statement that failed