Skip to content

pgrach/js_openai_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

js_openai_api

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.

Important

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.

Prerequisites

  • 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)

Getting Started

These instructions will get you a copy of the project up and running on your local machine for testing purposes:

  1. In the same foulder create index.html, script.js.
  2. Paste code provided accordingly - make sure the files are linked.
  3. The most tricky one: replace YOUR_OPENAI_KEY with your actual OpenAI API key (see, prerequisites).
  4. Make sure you DO NOT publish your code with your private key publically - run it locally ONLY.

Usage

  1. Enter your message in the input field.
  2. Click the "Send" button or press "Enter" to submit the message.
  3. The application will send your message to the OpenAI API and display the assistant's response below (may take a moment or two)

Customization

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.

Next steps

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

About

for beginners_a quick way to try chat completion with js only

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors