This repository provides a simple example of integrating the OpenAI API into a JavaScript application for creating a chatbot-like interaction. It is a beginner-friendly guide to get familiarity with GPT-3 model, JavaScript and HTML (before getting advanced with deploying it with Vercel, Node.js, servider-side environment). The chatbot is a very basic an AI assistant powered by OpenAI's natural language model - it only answers to users question.
The code is to be run only for your local environment. Keep your API key confidential: Never share your API key publicly or commit it to a public repository.
- Basic knowledge of JavaScript
- Visual Studio Code (or any other preferred code editor)
- OpenAI API key (sign up at OpenAI if you don't have one)
These instructions will get you a copy of the project up and running on your local machine for testing purposes:
- In the same foulder create index.html, script.js.
- Paste code provided accordingly - make sure the files are linked.
- The most tricky one: replace YOUR_OPENAI_KEY with your actual OpenAI API key (see, prerequisites).
- Make sure you DO NOT publish your code with your private key publically - run it locally ONLY.
- Enter your message in the input field.
- Click the "Send" button or press "Enter" to submit the message.
- The application will send your message to the OpenAI API and display the assistant's response below (may take a moment or two)
Feel free to customize the application to fit your needs. You can modify the HTML structure, CSS styles, and JavaScript code to enhance the user experience or add additional features.
After you are familiar with this, you can see next repo created, which explains how to handle your private key in public, which requires a few more steps. https://github.com/pgrach/js_openAI_beginner