diff --git a/src/revChatGPT/__main__.py b/src/revChatGPT/__main__.py index 7cc3aed625..aa257c630c 100644 --- a/src/revChatGPT/__main__.py +++ b/src/revChatGPT/__main__.py @@ -33,7 +33,7 @@ def get_input(prompt): import sys while True: - prompt = get_input("You: ") + prompt = get_input("\nYou:\n") if prompt.startswith("!"): if prompt == "!help": print(""" @@ -56,19 +56,24 @@ def get_input(prompt): continue elif prompt == "!exit": break + import textwrap + + messages = [] + lines_printed=0 + try: - print("Please wait for ChatGPT to formulate its full response...") - response = chatbot.get_chat_response(prompt) + print("Chatbot: ") + for message in chatbot.get_chat_response(prompt, output="stream"): + formatted_messages = textwrap.wrap(message, width=80) + if (len(formatted_messages) > lines_printed+1): + print(formatted_messages[lines_printed]) + lines_printed+=1 + print(formatted_messages[lines_printed]) except Exception as e: print("Something went wrong!") print(e) continue - # Erase the "Please wait" line when done waiting - sys.stdout.write("\033[F\033[K") - print("\n") - print("Chatbot:", response['message']) - print("\n") arguments=list(sys.argv) del arguments[0] diff --git a/src/revChatGPT/revChatGPT.py b/src/revChatGPT/revChatGPT.py index 02de6d95f7..7de9a7d73c 100644 --- a/src/revChatGPT/revChatGPT.py +++ b/src/revChatGPT/revChatGPT.py @@ -40,6 +40,7 @@ def get_chat_response(self, prompt, output="text"): "parent_message_id":self.parent_id, "model":"text-davinci-002-render" } + #print("bar") if output == "text": response = requests.post("https://chat.openai.com/backend-api/conversation", headers=self.headers, data=json.dumps(data)) try: @@ -62,6 +63,7 @@ def get_chat_response(self, prompt, output="text"): continue line = line[6:] line = json.loads(line) + #print(line) try: message = line["message"]["content"]["parts"][0] except: @@ -70,6 +72,7 @@ def get_chat_response(self, prompt, output="text"): except: continue else: + print("foo") return ValueError("Output must be either 'text' or 'response'") def refresh_session(self):