acheong08 / ChatGPT
- вторник, 6 декабря 2022 г. в 00:36:42
Lightweight package for interacting with ChatGPT's API by OpenAI. Uses reverse engineered official API.
Reverse Engineered ChatGPT by OpenAI. Extensible for chatbots etc.
This is not an official OpenAI product. This is a personal project and is not affiliated with OpenAI in any way. Don't sue me
The CLI functionality is for demo and testing only.
@rawandahmad698 has a much better CLI tool at
pip3 install revChatGPT --upgrade
{
"email": "<YOUR_EMAIL>",
"password": "<YOUR_PASSWORD>"
}
Save this in config.json
in current working directory
$ python3 -m revChatGPT
ChatGPT - A command-line interface to OpenAI's ChatGPT (https://chat.openai.com/chat)
Repo: github.com/acheong08/ChatGPT
Arguments: Use --stream to enable data streaming. (Doesn't work on MacOS)
Type '!help' to show commands
Press enter twice to submit your question.
You: !help
!help - Show this message
!reset - Forget the current conversation
!refresh - Refresh the session authentication
!exit - Exit the program
Refresh every so often in case the token expires.
pip3 install revChatGPT --upgrade
from revChatGPT.revChatGPT import Chatbot
import json
# Get your config in JSON
config = {
"email": "<YOUR_EMAIL>",
"password": "<YOUR_PASSWORD>"
}
chatbot = Chatbot(config, conversation_id=None)
chatbot.reset_chat() # Forgets conversation
chatbot.refresh_session() # Uses the session_token to get a new bearer token
resp = chatbot.get_chat_response(prompt, output="text") # Sends a request to the API and returns the response by OpenAI
resp['message'] # The message sent by the response
resp['conversation_id'] # The current conversation id
resp['parent_id'] # The ID of the response
# This returns a stream of text (live update)
resp = chatbot.get_chat_response(prompt, output="stream")
for message in resp: # You have to loop through the response stream
print(line['message']) # Same format as text return type
...
This can be imported to projects for bots and much more. You can have multiple independent conversations by keeping track of the conversation_id.
If you have a cool project you want added to the list, open an issue.