This project uses python to simply implement the experience of how to call Chagpt's api for dialogue and other tasks.
- install python package(terminal):
- install openai api(optional): "pip install openai";
- install tiktoken to calculate the length of tokens: "pip install tiktoken" ,if tips "time out",please add the local sources,such as "pip install tiktoken -- timeout=300 -i https://pypi.tuna.tsinghua.edu.cn/simple";
- if you want to show conversation in your browser, you can install flask service dependency libraries use this conmmand: "pip install -r requirements.txt"
- Add your openAI key to the "authorization" in the config/chatgpt_config.py;
- Two method you can choose:
-
show in terminal:
-
show in your browser:
- run this command "python manager.py"
- open your browser, and type the address:http://127.0.0.1:9200/ ,then you can see the page load as below:
-
-
You can also use the OpenAI api (https://platform.openai.com/docs/guides/chat) to call, but it’s more flexible and convenient to implement by yourself to expand more applicatioins.
-
The dialogue is entered directly from the command line. By default, the context of the dialogue will always be accumulated. If you want to clear the context, you can directly enter 'clear' on the command line.
-
The recently added method of deleting the history dialogue is implemented in tools/utils.py. At present, I think there is still a lot of room for optimization in this method. I try to adjust the parameters, this set of default parameters in config.py is relatively optimal in my attempt, you can also configure it in this file.
-
It is recommended to run test.py for the first time to ensure that your api key can access OpenAI’s api normally. If it cannot be accessed normally, please refer to the returned error message to set up your own OpenAI account or use another key.For example, if the error message shown in the screenshot below is returned,means that you have exceeded your free $18 in API credits. You can pay for more on the official website.
- support mutil-turn dialogue
- support delete the former dialogue automatically when the token length exceeds the limit of OpenAI API
- The content returned by the API can streaming display.