Read the statement by Michael Teeuw here.
ChatGpt intergration
-
@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 -
HOLY SHIT I GOT IT TOO WORK!. ok i need to calm down i am so happy right now. so turn out i was just trying too call the everything with openai.apiKey instead of just apiKey and then i had too do somthing else i dont even remember what i did but now i got it too work and it displays on the magicmirror. but now comes the hard part. if you look in the code there is a variabele named question that the prompt uses and send too the api. and i am no expert but can you have the variable question be defined with some kind of speech too text thing?
-
@SILLEN-0 said in ChatGpt intergration:
and i am no expert but can you have the variable question be defined with some kind of speech too text thing?
i don’t know what you mean…
unless u want to capture speech and convert that to the text for openai
welcome to the problem I have highlighted since the beginning… there is no GOOD speech capture library, and nothing built in.
this is why the MMM-GoogleAssistant provides mechanisms (recipe) to use the captured text for non- google uses.
MMM-Voice uses the pocketsphinx lib, from carnegie mellon, I think this one is terrible for me, <60% accurate and I have to keep saying it over and over.
GA and most others use cloud based services (none free)
but put a filter (hotword, like ok google, or alexa) in front to keep the cost down, not convert everything.the other mirror platform I support , smart-mirror , is voice based, so your ‘plugin’ can get the text from the speech. not compatible with MM.
-
i have MMM-googleassistant and i have used the recipes for some other stuff but could you get that too work with chatgpt. saying somthing like "ok-google chatgpt followed by the question you want too ask and then it takes the question makes it a variable or somthing that the prompt can read and then refresh the answer on the magicmirror. also what do you mean by (none free) MMM-google assistant is free. but i think it wouldnt be a big issue having too pay for chat gpt as in all of my testing and making api calls i have only paid 0.09 usd
-
@SILLEN-0 so to use ga recipe it would send a notification and your module side would get that and send that text to node_helper… rest is the same
-
@SILLEN-0 meaning of life. I assume service has blocked killer questions
-
@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…
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login
