Read the statement by Michael Teeuw here.
ChatGpt intergration
-
@sdetweil any idea on how to do that? Also i fixed it i was just stupid i changed the default question if I had nothing else in the config.js but in there i had the question still set too what’s the weather like and when i changed that everything worked
-
@SILLEN-0 how to do what?
-
@sdetweil how would you make the recipie part and what to have as a command like how would you tell the recipie too send all text after the phrase chatgpt in the notification as question. and recieving that in the chatgpt.js
-
@SILLEN-0 the way modules communicate is thru notifications
sendNotification(someStringvalue, someData)
it’s a broadcast all modules receive it.
they examine the someStringvalue and see if it’s important to them and if so they process the someData., if not then they ignore it. there are hundreds of notifications firing all the time.
so you make a recipe that responds to a voice phrase chatGpt, and the rest is the question
and u have ga send the notification that your module is looking for.you should be able to see the recipe pattern by looking at others that do the same thing.
once your module recognizes the notification string, then it knows the data is the text of the question.
you module already has a receiveNotification function, so adding another compare for the notification string is the big work…
-
@sdetweil yea i guess but how in the world would you make it send just the phrase after chatgpt is said. in other words i have no idea how the recipie file should be coded
-
@SILLEN-0 you said you understood recipe
-
@sdetweil maybe i formulated it bad. i know how the recipie structure should look like and i can make simple recipies but having the notification only send everything after “chatgpt” that i have no idea how too do. as i said i am a beginner in coding and trying my best
-
@SILLEN-0 look at the memo and selfie shoot recipies
memo gets the rest of the words
selfie shoot ‘command’ is to send a notificationwhen the ‘command’ function is invoked it gets params… ie, the rest of the words
-
@sdetweil ok hello. alot of things have happend in the last week. i have got somthing that should be working but i had too fix abunch of errors in the code. but for the last couple of days i have been stuck on this perticular error in my code:
0|MagicMirror | [25.01.2023 21:05.25.175] [LOG] Error in getResponse: RangeError: Maximum call stack size exceeded 0|MagicMirror | at isBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:22:18) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:40:9) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:49:63) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:49:63) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:49:63) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:49:63) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:49:63) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:49:63) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:49:63) 0|MagicMirror | at hasBinary (/home/pi/MagicMirror/node_modules/socket.io-parser/build/cjs/is-binary.js:49:63)
the internet says that it is probobally a part of the code calling itself but i just cant seem too find anything. it may be super clear what the issue is here but i really cant seem too find the cause of the error. help would be greatly apprecieted. here is my code:
chatgpt.js:
Module.register("chatgpt",{ defaults: { question: "What is the weather like today?", }, start: function() { console.log("Starting module: " + this.name); this.question = this.config.question; }, notificationReceived: function(notification, payload) { if(notification === "ASK_QUESTION") { this.question = payload.question; console.log("Received question: " + this.question); this.sendSocketNotification("ASK_QUESTION", this.question); } }, socketNotificationReceived: function(notification, payload) { if(notification === "RESPONSE") { this.answer = payload.answer; console.log("Received answer: " + this.answer); console.log("Calling updateDom"); this.updateDom(); } else { console.log("Unhandled notification: " + notification); console.log("Payload: " + payload); } }, getDom: function() { var wrapper = document.createElement("div"); var question = document.createElement("div"); var answer = document.createElement("div"); if (this.answer) { answer.innerHTML = this.answer; } else { answer.innerHTML = "Ask me something"; } question.innerHTML = this.question; wrapper.appendChild(question); wrapper.appendChild(answer); return wrapper; }, });
node_helper.js:
const NodeHelper = require("node_helper"); const { Configuration, OpenAIApi } = require("openai"); module.exports = NodeHelper.create({ start: function() { console.log("Starting node helper for: " + this.name); this.configuration = new Configuration({ apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXX", }); this.openai = new OpenAIApi(this.configuration); }, // Send a message to the chatGPT API and receive a response getResponse: function(prompt) { return new Promise(async (resolve, reject) => { try { const response = await this.openai.createCompletion({ model: "text-davinci-003", prompt: prompt, temperature: 0.7, }); console.log("Received response from API: ", response); resolve(response); } catch (error) { console.log("Error in getResponse: ", error); reject(error); } }); }, // Handle socket notifications socketNotificationReceived: function(notification, payload) { if (notification === "ASK_QUESTION") { console.log("Received ASK_QUESTION notification with payload: ", payload); this.getResponse(payload) .then((response) => { // create a new object and update the answer property var responsePayload = {answer: response}; console.log("Sending RESPONSE notification with payload: ", responsePayload); this.sendSocketNotification("RESPONSE", responsePayload); }) .catch((error) => { console.log("Error in getResponse: ", error); }); } }, });
the api call is being made and everything else is working but as soon as i say “jarvis chatgpt say banana” or any other input i get the error
-
@SILLEN-0 what is the data format of the response?, text, json, ???
you said
‘say banana’
did it return a wav file?
if u add the MMM-Logging module, then u can see all the logs in one place (output of npm start)
socket-io requires a serializable object
says error is in getResponse() function,
so, did your module get multiple requests concurrently and send them on?
I would make the notification string more specific. ‘gpt question’
there are hundreds of notifications going on, possible there was another module sending that same string…