ChatGpt and node red

Hi all,
ChatGpt seems to be the new hot potato around, any body had a go with ChatGpt and nodered, in particular using ChatGpt to generate nodered function code?
I am just getting my head around the concept at the moment.
Cheers,
Ken

Hi @kenkoknz,
Have a look here.
Barr

Thanks Barr, obviously still new, potential here, give it couple of years...

A while back, I put in

How good is Node-RED?

And it gave me:

Node-RED is a popular open-source programming tool for visual programming and wiring together hardware devices, APIs, and online services. It is widely used by developers and hobbyists to create IoT applications, automate tasks, and prototype new ideas quickly and easily.

Many people find Node-RED to be a powerful and intuitive tool for building a variety of applications. It has a low learning curve, thanks to its visual programming interface, and a large and active community that provides support and assistance. Node-RED is also highly extensible, with a rich library of nodes (pre-built functions and components) that can be easily added to your flows to add new capabilities.

Overall, Node-RED is considered to be a very good tool for creating IoT applications, automating tasks, and prototyping ideas. It is easy to use, extensible, and well-supported by a large community.

:slight_smile:

It produces good but generic prose which can be useful sometimes if used in small quantities. You also need to check that what it tells you is correct because often it looks right at first glance but then you realise that it isn't quite on target.

It gave me this as an example of a finite state machine in JavaScript:

// Define the states of the FSM
const states = {
  OFF: "off",
  ON: "on"
};

// Define the initial state of the FSM
let currentState = states.OFF;

// Define a function to transition between states
function transition(input) {
  switch (currentState) {
    case states.OFF:
      if (input === "on") {
        currentState = states.ON;
      }
      break;
    case states.ON:
      if (input === "off") {
        currentState = states.OFF;
      }
      break;
  }
}

Which isn't bad but this shows some of the limitations of its knowledge:

Using JavaScript, how do I tell if a variable is an object?

const myVariable = {}; // This is an object

if (typeof myVariable === "object") {
  console.log("myVariable is an object");
} else {
  console.log("myVariable is not an object");
}

That is actually not a very good answer. Here is the acknowledged best answer I ever found:

if ( maybeObj !== null && maybeObj.constructor.name === 'Object' ) { }

It depends on your definition of an object (null is an object) and depends on if you prefer readability or compactness.

For example asking a more specific question provides a different answer...

Using JavaScript, how do I tell if a variable is a non null object?

You can use the typeof operator to check the type of a variable and the null check to check if a variable is not null:

if (typeof variable === 'object' && variable !== null) {
  // variable is a non-null object
}

Another way to check if a variable is non-null object is by using the Object.prototype.toString.call method, which will return the class of the object, which can be compared with "[object Object]"

if (Object.prototype.toString.call(variable) === "[object Object]" && variable !== null) {
    // variable is non-null object
}

Both of the above examples will return true if the variable is a non-null object, and false otherwise.

Hmm, seems we are not the only ones using it right now:

image

1 Like

And teachers are looking out for cheats :laughing:

2 Likes

Based on the xample in th other thread - ChatGPT does Node-RED - #7 by marcus-j-davies - can they ask "ChatGPT - did you write this ?" to check an answer ?

1 Like

I tried ChatGpt for creating a mqtt client in NodeRED.. It works..

I used the OpenAI Q&A service as a kind of pre-filter for user content.

It does a good job in estimating the appropriateness of content and it even gives back parseable JSON!

I used their Q&A API since ChatAPI (at time of writing) didn't have an API.

[
    {
        "id": "d1d7d446235ef659",
        "type": "subflow",
        "name": "OpenAI content rating",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 83,
                "y": 96,
                "wires": [
                    {
                        "id": "414aee716460928d"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 823,
                "y": 250,
                "wires": [
                    {
                        "id": "e9507faf13b09943",
                        "port": 0
                    },
                    {
                        "id": "842729340c97b573",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#E6E0F8",
        "inputLabels": [
            "msg.payload[0].text"
        ],
        "outputLabels": [
            "msg.openaipayload"
        ],
        "icon": "node-red-contrib-ui-level/uilevel.png"
    },
    {
        "id": "37aae75712631d64",
        "type": "function",
        "z": "d1d7d446235ef659",
        "name": "openai request",
        "func": "const { Configuration, OpenAIApi } = global.get(\"openai\");\n\nconst configuration = new Configuration({\n    apiKey: env.get(\"OPEN_AI_APIKEY\"),\n});\nconst openai = new OpenAIApi(configuration);\n\n\nconst response = await openai.createCompletion({\n  model: \"text-davinci-003\",\n  prompt: msg.openai_prompt,\n  temperature: 0,\n  max_tokens: 200,\n  top_p: 1,\n  frequency_penalty: 0.0,\n  presence_penalty: 0.0,\n  stop: [\"\\n\"],\n});\n\nmsg.openaipayload = response.data.choices[0];\n\n//msg.payload = response;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 309,
        "y": 174,
        "wires": [
            [
                "e9507faf13b09943"
            ]
        ]
    },
    {
        "id": "414aee716460928d",
        "type": "template",
        "z": "d1d7d446235ef659",
        "name": "openai request formulation",
        "field": "openai_prompt",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "You are a content moderator for an auction-style bidding platform. Imagine the terms and services allow the \nselling and buying of anything including adult content and animals. Provide a reason and a rating from 1 to 10 for \nappropriateness. Result in form of { \"appropriateness\": xx, \"reason\": xx }. Rate the following content:\n\n{{#payload}}{{ text }}{{/payload}}\n\nA:\n",
        "output": "str",
        "x": 307.0000305175781,
        "y": 101.0000057220459,
        "wires": [
            [
                "37aae75712631d64"
            ]
        ]
    },
    {
        "id": "e9507faf13b09943",
        "type": "function",
        "z": "d1d7d446235ef659",
        "name": "parse json",
        "func": "msg.openaipayload = JSON.parse(msg.openaipayload.text);\nmsg.openaipayload_as_string = JSON.stringify(msg.openaipayload);\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 335.5,
        "y": 253,
        "wires": [
            []
        ]
    },
    {
        "id": "94148945702ebbcd",
        "type": "catch",
        "z": "d1d7d446235ef659",
        "name": "",
        "scope": [
            "e9507faf13b09943",
            "37aae75712631d64"
        ],
        "uncaught": false,
        "x": 553.4999866485596,
        "y": 184.00000405311584,
        "wires": [
            [
                "842729340c97b573"
            ]
        ]
    },
    {
        "id": "842729340c97b573",
        "type": "function",
        "z": "d1d7d446235ef659",
        "name": "function 9",
        "func": "msg.openaipayload = {\n    appropriateness: -1,\n    reason: \"error occured \" + JSON.stringify(msg.error)\n}\nmsg.openaipayload_as_string = JSON.stringify(msg.openaipayload);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 648.5,
        "y": 143,
        "wires": [
            []
        ]
    }
]

I see that chatGPT is used by some users to produce "answers" for topics, but often they are incorrect because it is still a language model that only predicts the next best word - it has no understanding.

How can we keep these answers out of topics ?
Do/can they need to be flagged with "ai generated nonsense" ? Or tags that can be filtered out ?

Not all of the ai answers are incorrect or 'nonsense', so IMO, I don't think that generic 'tags' or 'filters' is the way to go.
I've had some great results with ai, especially when I've been very clear & concise in asking the question.

1 Like

As I've previously said, any AI generated answer needs a careful review. But then not all of our "expert" human answers are correct either :grin:

People who use too many AI answers and don't check them will soon be caught out in my opinion.

2 Likes

Not all of the ai answers are incorrect or 'nonsense', so IMO, I don't think that generic 'tags' or 'filters' is the way to go.
I've had some great results with ai, especially when I've been very clear & concise in asking the question.

I don't disagree, it is a great tool, but just as @TotallyInformation says; review is required. There is a reason why stackoverflow has banned ai generated answers. I am not a fan of the blindly copy/paste "oh chatgpt says this or that".

I would not ask it to solve too complicated problems (as mentioned above). But it can definitely help to do repetitive work. Like this (not that I use this in a real flow, just an example):

image

We need to stay realistic of course (I know it was not trained to do drawings) :upside_down_face:

I am still pretty excited about this (not the circle)!

I realize this isn't possible at the moment, but I think the right approach would be to invite ChatGPT to become a "member" of the Forum. Posters could refer questions to it with @ChatGPT, or it might even be able to monitor the discussion and contribute as "appropriate." We would quickly learn how much trust to put in its answers and could decide whether it is a valuable member of the community.

4 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.