A ChatGPT chat interface written in native JavaScript and is implemented based on openai's GPT-3.5 turbo API interface, and uses the solution provided by the official interface document to realize the function of memorizing the historical dialogue context, so that it can continue to communicate and achieve a continuous dialogue effect close to the official website ChatGPT.
According to the official website document information, the usage fee is 90% cheaper than the previous 003 model.
Static web page: http://sdsds222.gitee.io/chat-gpt-3.5.js


Software Architecture Description Javascript HTML CSS
To use this page, you need to bring your own openai's apikey in advance, otherwise all functions will not be able to be used normally.
Based on native Javascript, it can be directly deployed to a static web hosting platform to run.
Enter "/help" in the input box to view supported instructions. These instructions can be used to change the parameters of sending requests to adjust the behavior of the AI:
/help (for viewing help information)
/apikey (used to set the apikey. Only by registering and obtaining the apikey on the official website can you use this service normally)
/prompt (Add a pre-context for each sent text)
/system (Add a system-level description for each text sent)
/maxtoken (used to control the number of words that ChatGPT can generate each time)
/tpr (can be used to control the diversity of chatbot generation)
/top (can be used to control the quality of chatbot generation)
/fp (can be used to control the "newness" of chatbot generation)
/pp (used to control the length of sentences generated by bot)
/info (used to display the values of the current parameters)
/csize (used to set the number of memory history conversations)
/mode (used to set whether to enable continuous dialogue mode)
After entering /info, the values of all parameters will be displayed:

Since the principle of this project's continuous dialogue is to send the previous historical dialogue content as a context to the interface of GPT-3.5 turbo, this may lead to waste of account quotas. You can enter "/mode" in the console and "false" in the input box to turn off the continuous dialogue mode.
Reasonable use of system and prampt parameters to set the pre-context of each sentence can keep the AI's tone and personality consistent for a long time, and can also prevent the key information from being forgotten by the AI.
Some of the code in this project is generated by ChatGPT.
Here we record the author's two new clustering algorithms:
1. By firing some squares of certain sizes to different angles in the space, the square moves in a straight line, and stops when the square collides with the sample point, and the square will stop moving when it encounters the square. The square will continue to accumulate until it cannot be put down. This will fill the gaps without points in the entire space with blocks, and the remaining space bubbles with only sample points without blocks are classified into classes, thereby realizing clustering.
2. The idea of a clustering algorithm: by firing some pinballs to different angles in space, treating each sample point as a square. If the pinball collides with the sample point square, mark the sample square as an edge square and ejecting in other directions. Just like the game of brick shooting, after a period of time, these edge squares will wrap the inner blocks, connect these edge squares into a circle, and the sample points in the circle are one type. This method draws on brickwork, flour and snowballing in nature.