Node.js project that combines OpenAI's API with MQTT for real-time AI-driven interactions in IoT ecosystems.
This project aims to provide a simple and efficient way to integrate OpenAI's ChatGPT with MQTT protocol, enabling real-time AI-driven interactions within IoT ecosystems. By leveraging the power of OpenAI's language models, users can interact with their connected devices using natural language. This project is suitable for a wide range of IoT applications, such as smart homes, industrial automation, and other IoT domains.
- Node.js and npm installed on your system
- An OpenAI API key
- An MQTT broker to connect to (e.g., EMQX, EMQX Cloud)
-
Clone the repository:
git clone https://github.com/your-username/openai-mqtt-nodejs.git
-
Go to the project directory:
cd openai-mqtt-nodejs
-
Install the dependencies:
npm install
-
Create a
.env
file in the project root directory with the following content:OPENAI_API_KEY=your_openai_api_key
-
Update the OPTIONS object in index.js with your MQTT broker's connection details.
-
Start the application:
node index.js
or
npm run start
-
The application will automatically connect to the MQTT broker and subscribe to the
chatgpt/request/+
topic. -
To interact with the ChatGPT, publish a message to a user-specific topic like
chatgpt/request/user1
. The application will receive the message, send it to the OpenAI API, and publish the response to a corresponding topic likechatgpt/response/user1
.
Each user should have their unique topic for requests and responses to ensure user isolation. Replace user1
with an appropriate identifier for each user.
Contributions are welcome! If you'd like to contribute to the project, please follow the steps below:
-
Fork the repository.
-
Create a new branch with a descriptive name.
-
Commit your changes to the branch.
-
Push the changes to your fork.
-
Open a pull request with the main repository.
This project is licensed under the MIT License. See the LICENSE file for more information.