MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    ChatGpt intergration

    Scheduled Pinned Locked Moved Unsolved Requests
    59 Posts 7 Posters 35.9k Views 8 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      SILLEN 0
      last edited by

      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

      S 2 Replies Last reply Reply Quote 0
      • S Offline
        sdetweil @SILLEN 0
        last edited by

        @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

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          sdetweil @SILLEN 0
          last edited by

          @SILLEN-0 meaning of life. I assume service has blocked killer questions

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • S Offline
            SILLEN 0 @sdetweil
            last edited by

            @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

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              sdetweil @SILLEN 0
              last edited by

              @SILLEN-0 how to do what?

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                SILLEN 0 @sdetweil
                last edited by SILLEN 0

                @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

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  sdetweil @SILLEN 0
                  last edited by sdetweil

                  @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…

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  S 1 Reply Last reply Reply Quote 0
                  • S Offline
                    SILLEN 0 @sdetweil
                    last edited by SILLEN 0

                    @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

                    S 1 Reply Last reply Reply Quote 0
                    • S Offline
                      sdetweil @SILLEN 0
                      last edited by

                      @SILLEN-0 you said you understood recipe

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        SILLEN 0 @sdetweil
                        last edited by

                        @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

                        S 1 Reply Last reply Reply Quote 0
                        • S Offline
                          sdetweil @SILLEN 0
                          last edited by

                          @SILLEN-0 look at the memo and selfie shoot recipies

                          memo gets the rest of the words
                          selfie shoot ‘command’ is to send a notification

                          when the ‘command’ function is invoked it gets params… ie, the rest of the words

                          Sam

                          How to add modules

                          learning how to use browser developers window for css changes

                          S 1 Reply Last reply Reply Quote 0
                          • S Offline
                            SILLEN 0 @sdetweil
                            last edited by sdetweil

                            @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

                            S 2 Replies Last reply Reply Quote 0
                            • S Offline
                              sdetweil @SILLEN 0
                              last edited by sdetweil

                              @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…

                              Sam

                              How to add modules

                              learning how to use browser developers window for css changes

                              1 Reply Last reply Reply Quote 0
                              • S Offline
                                sdetweil @SILLEN 0
                                last edited by sdetweil

                                @SILLEN-0 also that is the error part of the pm2 logs --lines output

                                when I am developing

                                I don’t use pm2,
                                I just do

                                npm start  >somefile.txt 2>&1
                                

                                in the MagicMirror folder

                                then all the console output is in one file.
                                adding the logging module will reflect all the modulename.js log statements too

                                AND you can debug on the mm UI , ctrl-shift-i,
                                select the sources tab, find your module name.js in the left nav,

                                and you can put stops on lines of code and step thru it

                                Sam

                                How to add modules

                                learning how to use browser developers window for css changes

                                S 1 Reply Last reply Reply Quote 0
                                • S Offline
                                  SILLEN 0 @sdetweil
                                  last edited by

                                  @sdetweil hey. I’m sorry for not being able too answer but i have other stuff going on and a math test coming up. The text is sent over as a string and the module does recieved the string and gets a response from the API it is after that the issue is caused. I Google the error and people say that there is probably a loop in the code somewhere. I will try with the debug module when i have time. I really want too get this too work.

                                  S 1 Reply Last reply Reply Quote 0
                                  • S Offline
                                    sdetweil @SILLEN 0
                                    last edited by

                                    @SILLEN-0 the data back from the api looks like this

                                        status: 200,
                                        statusText: 'OK',
                                        headers: {
                                          date: 'Sun, 29 Jan 2023 23:56:49 GMT',
                                          'content-type': 'application/json',
                                          'content-length': '343',
                                          connection: 'close',
                                          'access-control-allow-origin': '*',
                                          'cache-control': 'no-cache, must-revalidate',
                                          'openai-model': 'text-davinci-003',
                                          'openai-organization': 'user-ieyrbalt3azhd9sd82splktg',
                                          'openai-processing-ms': '2790',
                                          'openai-version': '2020-10-01',
                                          'strict-transport-security': 'max-age=15724800; includeSubDomains',
                                          'x-request-id': 'd341b29147db89ee20886107e22b41a4'
                                        },
                                        config: {
                                          transitional: [Object],
                                          adapter: [Function: httpAdapter],
                                          transformRequest: [Array],
                                          transformResponse: [Array],
                                          timeout: 0,
                                          xsrfCookieName: 'XSRF-TOKEN',
                                          xsrfHeaderName: 'X-XSRF-TOKEN',
                                          maxContentLength: -1,
                                          maxBodyLength: -1,
                                          validateStatus: [Function: validateStatus],
                                          headers: [Object],
                                          method: 'post',
                                          data: '{"model":"text-davinci-003","prompt":"What is the weather like today?","temperature":0.7}',
                                          url: 'https://api.openai.com/v1/completions'
                                        },
                                        request: ClientRequest {
                                          _events: [Object: null prototype],
                                          _eventsCount: 7,
                                          _maxListeners: undefined,
                                          outputData: [],
                                          outputSize: 0,
                                          writable: true,
                                          destroyed: false,
                                          _last: true,
                                          chunkedEncoding: false,
                                          shouldKeepAlive: false,
                                          maxRequestsOnConnectionReached: false,
                                          _defaultKeepAlive: true,
                                          useChunkedEncodingByDefault: true,
                                          sendDate: false,
                                          _removedConnection: false,
                                          _removedContLen: false,
                                          _removedTE: false,
                                          _contentLength: null,
                                          _hasBody: true,
                                          _trailer: '',
                                          finished: true,
                                          _headerSent: true,
                                          _closed: false,
                                          socket: [TLSSocket],
                                          _header: 'POST /v1/completions HTTP/1.1\r\n' +
                                            'Accept: application/json, text/plain, */*\r\n' +
                                            'Content-Type: application/json\r\n' +
                                            'User-Agent: OpenAI/NodeJS/3.1.0\r\n' +
                                            'Authorization: Bearer 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\r\n' +
                                            'Content-Length: 89\r\n' +
                                            'Host: api.openai.com\r\n' +
                                            'Connection: close\r\n' +
                                            '\r\n',
                                          _keepAliveTimeout: 0,
                                          _onPendingData: [Function: nop],
                                          agent: [Agent],
                                          socketPath: undefined,
                                          method: 'POST',
                                          maxHeaderSize: undefined,
                                          insecureHTTPParser: undefined,
                                          path: '/v1/completions',
                                          _ended: true,
                                          res: [IncomingMessage],
                                          aborted: false,
                                          timeoutCb: null,
                                          upgradeOrConnect: false,
                                          parser: null,
                                          maxHeadersCount: null,
                                          reusedSocket: false,
                                          host: 'api.openai.com',
                                          protocol: 'https:',
                                          _redirectable: [Writable],
                                          [Symbol(kCapture)]: false,
                                          [Symbol(kNeedDrain)]: false,
                                          [Symbol(corked)]: 0,
                                          [Symbol(kOutHeaders)]: [Object: null prototype],
                                          [Symbol(kUniqueHeaders)]: null
                                        },
                                        data: {
                                          id: 'cmpl-6eBpQkPEmW4z1PoxRTTprs8Lhoqn4',
                                          object: 'text_completion',
                                          created: 1675036608,
                                          model: 'text-davinci-003',
                                          choices: [Array],
                                          usage: [Object]
                                        }
                                      }
                                    
                                      answer: {
                                        status: 200,
                                        statusText: 'OK',
                                        headers: {
                                          date: 'Sun, 29 Jan 2023 23:56:49 GMT',
                                          'content-type': 'application/json',
                                          'content-length': '343',
                                          connection: 'close',
                                          'access-control-allow-origin': '*',
                                          'cache-control': 'no-cache, must-revalidate',
                                          'openai-model': 'text-davinci-003',
                                          'openai-organization': 'user-ieyrbalt3azhd9sd82splktg',
                                          'openai-processing-ms': '2790',
                                          'openai-version': '2020-10-01',
                                          'strict-transport-security': 'max-age=15724800; includeSubDomains',
                                          'x-request-id': 'd341b29147db89ee20886107e22b41a4'
                                        },
                                        config: {
                                          transitional: [Object],
                                          adapter: [Function: httpAdapter],
                                          transformRequest: [Array],
                                          transformResponse: [Array],
                                          timeout: 0,
                                          xsrfCookieName: 'XSRF-TOKEN',
                                          xsrfHeaderName: 'X-XSRF-TOKEN',
                                          maxContentLength: -1,
                                          maxBodyLength: -1,
                                          validateStatus: [Function: validateStatus],
                                          headers: [Object],
                                          method: 'post',
                                          data: '{"model":"text-davinci-003","prompt":"What is the weather like today?","temperature":0.7}',
                                          url: 'https://api.openai.com/v1/completions'
                                        },
                                        request: ClientRequest {
                                          _events: [Object: null prototype],
                                          _eventsCount: 7,
                                          _maxListeners: undefined,
                                          outputData: [],
                                          outputSize: 0,
                                          writable: true,
                                          destroyed: false,
                                          _last: true,
                                          chunkedEncoding: false,
                                          shouldKeepAlive: false,
                                          maxRequestsOnConnectionReached: false,
                                          _defaultKeepAlive: true,
                                          useChunkedEncodingByDefault: true,
                                          sendDate: false,
                                          _removedConnection: false,
                                          _removedContLen: false,
                                          _removedTE: false,
                                          _contentLength: null,
                                          _hasBody: true,
                                          _trailer: '',
                                          finished: true,
                                          _headerSent: true,
                                          _closed: false,
                                          socket: [TLSSocket],
                                          _header: 'POST /v1/completions HTTP/1.1\r\n' +
                                            'Accept: application/json, text/plain, */*\r\n' +
                                            'Content-Type: application/json\r\n' +
                                            'User-Agent: OpenAI/NodeJS/3.1.0\r\n' +
                                            'Authorization: Bearer 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\r\n' +
                                            'Content-Length: 89\r\n' +
                                            'Host: api.openai.com\r\n' +
                                            'Connection: close\r\n' +
                                            '\r\n',
                                          _keepAliveTimeout: 0,
                                          _onPendingData: [Function: nop],
                                          agent: [Agent],
                                          socketPath: undefined,
                                          method: 'POST',
                                          maxHeaderSize: undefined,
                                          insecureHTTPParser: undefined,
                                          path: '/v1/completions',
                                          _ended: true,
                                          res: [IncomingMessage],
                                          aborted: false,
                                          timeoutCb: null,
                                          upgradeOrConnect: false,
                                          parser: null,
                                          maxHeadersCount: null,
                                          reusedSocket: false,
                                          host: 'api.openai.com',
                                          protocol: 'https:',
                                          _redirectable: [Writable],
                                          [Symbol(kCapture)]: false,
                                          [Symbol(kNeedDrain)]: false,
                                          [Symbol(corked)]: 0,
                                          [Symbol(kOutHeaders)]: [Object: null prototype],
                                          [Symbol(kUniqueHeaders)]: null
                                        },
                                        data: {
                                          id: 'cmpl-6eBpQkPEmW4z1PoxRTTprs8Lhoqn4',
                                          object: 'text_completion',
                                          created: 1675036608,
                                          model: 'text-davinci-003',
                                          choices: [Array],
                                          usage: [Object]
                                        }
                                      }
                                    

                                    i don’t see the text of the answer

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    P S 3 Replies Last reply Reply Quote 0
                                    • P Offline
                                      PraiseU Module Developer @sdetweil
                                      last edited by

                                      @sdetweil Hey any updates on this?

                                      1 Reply Last reply Reply Quote 0
                                      • P Offline
                                        PraiseU Module Developer @sdetweil
                                        last edited by

                                        @sdetweil Do you have any updates regarding the speech capture process?

                                        S 1 Reply Last reply Reply Quote 0
                                        • S Offline
                                          sdetweil @PraiseU
                                          last edited by

                                          @PraiseU I wasn’t working on any speech capture integration.

                                          I outlined the possibilities

                                          Sam

                                          How to add modules

                                          learning how to use browser developers window for css changes

                                          P 1 Reply Last reply Reply Quote 0
                                          • P Offline
                                            PraiseU Module Developer @sdetweil
                                            last edited by

                                            @sdetweil Oh okay! I found this Module https://github.com/TheStigh/MMM-VoiceCommander. Do you think it can be useful? or does it still have the problem with accuracy?

                                            S 1 Reply Last reply Reply Quote 0

                                            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
                                            • 1
                                            • 2
                                            • 3
                                            • 2 / 3
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy