🚀 A simple Node.js project demonstrating the power of the OpenAI API! This example interacts with the GPT-4o-mini model to generate chatbot responses. Easily set up and run in just a few steps!
Before running this project, ensure you have the following:
✅ Node.js installed (v20.x or higher recommended)
✅ OpenAI API key from OpenAI
Clone the repository or download the code to your local machine:
git clone https://github.com/ananthurajj/nodeOpenApiExample1.git
cd nodeOpenApiExample1
Install the required dependencies:
npm install
Create a .env file in the root of the project and add your OpenAI API key (🔒 Make sure to keep this secure!):
OPENAI_API_KEY=your-api-key-here
Run the project using the following command:
npm start
When you run the script, it will send a request to OpenAI asking for a programming joke and display the response in the terminal. 🤖💬
Here's a quick overview of the project structure:
📦node-openai-example
┣ 📜example.mjs # Main script to interact with OpenAI
┣ 📜package.json # Project metadata and scripts
┣ 📜README.md # You're reading it! ✨
┗ 📜.env # Environment variables (not included in repo)
This project relies on the following packages:
openai: Official OpenAI API client.
dotenv: Loads environment variables from a .env file
To install them, use:
npm install
Once you run the project, you’ll see a funny programming joke like this:
{
role: 'assistant',
content: 'Why do programmers prefer dark mode?\n\nBecause light attracts bugs!',
refusal: null
}
This project is licensed under the ISC License.
Feel free to contribute or open issues if you find any bugs 🐞 or have suggestions. Contributions are always welcome! ✨