/ChatGPT_Clone

Implementation of a text completion system that uses OpenAI's GPT-3 API

Primary LanguageHTML

This code is a simple implementation of a text completion system that uses OpenAI's GPT-3 API. The code starts by creating an input text field and a submit button using the document.createElement method. The input field and submit button are then centered on the page using CSS styles.

Once the user inputs text and clicks the submit button, the code sends a post request to the OpenAI API with the input text as the prompt. The API response is then parsed and the first response choice is extracted. This response is then added to the page as a new div element.

The code also includes error handling for the case where the API returns a 429 error (insufficient quota), by implementing exponential backoff. If a 429 error is encountered, the code will wait a specified amount of time before retrying the API request. This allows the code to continue functioning even if the API rate limit is temporarily exceeded.