Skip to main content

How to use ChatGPT with Node-RED

This deep dive demonstrates how to use ChatGPT with Node‑RED.


Things To Note

  • All Block Outputs contain all the info that comes out once an image is triggered.

All Block Output node

  • Copy the debug output from the All Block Outputs.

Copy the All Block Outputs debug value

All Block Outputs

This node outputs data after each capture made by the camera and containing all AI block data. The data is in the form of a JSON object. The data includes the following:

Payload FieldTypeDescription
payload.capture_idintegerThe capture ID of this capture
payload.recipe_idintegerThe recipe ID of this recipe
payload.camera_idstringA unique string identifier for this camera
payload.inspection_idintegerA rolling 16-bit integer that increments for each inspection
payload.inspection_timestringISO 8601 formatted timestamp of the capture for each inspection
payload.image_urlstringHTTP url to the capture image (jpg)
payload.alignment.successbooleanSuccessful algined part or not
payload.alignment.center_location_xintegerCenter location x of aligned part
payload.alignment.center_location_yintegerCenter location y of aligned part
payload.alignment.confidencefloat (0-1)Confidence of alignment

ChatGPT/Gemini/Copilot

  • Enter the prompt: “Here is the Input I have from Node Red : Insert the copied value here. enter prompt when you want it to fail and return msg.payload in boolean True or False”

ChatGPT Prompt Screen

Example

  • Here we have taught the AI to look for holes in the mounting plate.

Example annotation of mounting plate

  • Copy the values from the Node-RED debug block and paste it in ChatGPT with the following example prompt.
    • “Here is the Input I have from Node Red : Insert the copied value here. I want the camera to fail if there are less than 11 holes and return msg.payload in boolean True or False”

Example prompt

  • Take a look at the function block and read the comments on the logic.
  • See if it's doing the right thing (what was asked of it), and if so, copy the code it gives you.
  • Get a function node from the nodes and connect it to the Inspection Pass/Fail block.

Example of function block added to flow

Example ChatGPT window with function node code

  • Copy the code in the function block, make sure all the nodes are connected correctly and click Deploy.

Example screenshot showing number of blobs

Example Edit function node window

Deploy button