banner
P2N2

P2N2

P2N2代表两个正电荷,两个负电荷,而这正是氦原子的内部结构。夏荷的英文名称是Helim,来自Helium。 你可能觉得这样取名字脑洞未免太大了,但我觉得挺适合的。
mastodon

More GPT "One Sentence" API: HitokotoGPT

HitokotoGPT is a simple script I created on a whim to provide a "hitokoto" interface based on ChatGPT.

The original version of this so-called "hitokoto" interface is a project that returns a sentence every time the API is requested, to add an artistic touch to websites. HitokotoGPT takes it a step further by using ChatGPT to dynamically generate these sentences, making the literary decoration on the website more innovative.

Built on ChatGPT, HitokotoGPT is a simple Python program that can be easily deployed. With this program, you can easily obtain "famous quotes" generated by ChatGPT. You can deploy this program yourself or use a public interface. The public interface provided with this project is for testing purposes only and is not responsible for its stability.

Deployment Guide#

Meet system requirements#

This project is very lightweight and can run smoothly on machines that can run Python in general. However, you need to ensure that the machine running this program can access the OpenAI API.

This project depends on libraries such as uvicorn and fastapi to run. So, please execute the following command in the CLI to automatically install all the required dependencies:

pip install -r requirements.txt

This installation process will end quickly. After completion, please check the port status of the firewall to see if port 65530 is open. This program listens on port 65530. If you find high ports inconvenient to use, please modify the port variable in config.json to the port number you want to open.

Perform necessary settings#

All the configurations of this project are stored in the config.json file. Please open the config.json file in the default directory and configure it according to the following prompts.

{
    "api_key" : "your openai api key", //OpenAI API authentication key
    "access_token" : "access token to access the web server", //Access token for HitokotoGPT interface authentication
    "port" : 65530, //Port on which the API service listens, do not modify unless necessary
    "database" : "testdebug", //Name of the SQLite database, do not modify unless necessary
    "rate" : "1/min", //Request rate limit for each source IP
    "rate_cached" : "3/min" //Request rate limit for non-real-time generated content
}

Calling the interface#

Important: This project can set a rate limit, but please make sure to align the rate limit of this project with the frequency limit of OpenAI, otherwise, unpredictable consequences may occur.

The request body should be sent uniformly as JSON. The interface only handles POST requests with the content type of JSON, and other requests will result in an error.

Authentication#

This project uses simple authentication. Please use the gptauth parameter with a value set in the JSON file when accessing all interfaces.

Instantly generated hitokoto#

In this mode, this program will request the OpenAI API and generate a hitokoto based on the default prompt and return it. Please note that this request may be significantly delayed or even fail due to the speed of OpenAI. Please do not use instantly generated hitokoto in prominent positions on the page, as it may not load for a long time.

Interface URL: /hitokoto (POST)

Request parameters:

  • gptauth (string): Authentication key (required)
  • encycle (boolean): Set whether the hitokoto generated in this request is allowed to be used for non-repeating cached generation. This is used when calling the /hitokoto-cached interface and selecting the "no repetition" mode. (optional, default is false)

Pre-generated/cached hitokoto#

When calling the "instantly generated hitokoto" interface, all generations will be recorded in an SQLite database for this interface to call pre-submitted generations. At the same time, you can also use ./batch.py to generate a large number of hitokoto during off-peak hours and store them in the database. You can choose to use the "repetition" or "no repetition" mode, but please note that even if you select the "no repetition" mode in this interface, you may still see the same hitokoto because its usage status in the "instantly generated hitokoto" interface is set to "not used". Of course, you won't see it again because its usage status has been set to "used".

However, if the "no repetition" mode cannot find a hitokoto that has never been used, the interface will directly return a hitokoto that has been used without any prompts. Please be careful.

Interface URL: /hitokoto-cached (POST)

Request parameters:

  • gptauth (same as above)
  • recycle (boolean): Set to true to use "repetition" mode, set to false to use "no repetition" mode (optional, default is false)

Off-peak batch generation#

With batch.py, you can generate a large number of hitokoto and store them in the database for future use.

The specific operation is to set the value of the sentence_num variable in batch.py to determine the number of generations. At the same time, you can use other programs to execute batch.py during off-peak hours when there is less traffic or schedule it to run every one or two hours to increase the success rate and ensure that there is always a hitokoto available.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.