From 48b745fe23ef4b5ec2816c6058cec982ed9f7181 Mon Sep 17 00:00:00 2001 From: jackfood Date: Sat, 16 Sep 2023 16:12:05 +0800 Subject: [PATCH] ~start.py --- ~start.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ~start.py diff --git a/~start.py b/~start.py new file mode 100644 index 0000000..0f95273 --- /dev/null +++ b/~start.py @@ -0,0 +1,33 @@ +import subprocess +import os +import time + +while True: + # Ask for user input + user_input = input("Enter your input (or type 'exit' to quit): ") + + if user_input.lower() == 'exit': + break # Exit the loop if the user types 'exit' + + # Write the user input to a file called '~prompt.txt' as UTF-8, creating a new one or overwriting if it exists + with open('~prompt.txt', 'w', encoding='utf-8') as file: + file.write(user_input) + + # Introduce a 0.2-second delay + time.sleep(0.2) + + # Path to the batch script + batch_script_path = r'D:\Python\~CodeInterpereterwithGPTTest\Scripts\aiengine.bat' + + # Start the batch script and wait for it to complete + process = subprocess.Popen(batch_script_path, shell=True) + process.wait() + + # Check if 'aianswer.txt' exists and read its contents + if os.path.exists('aianswer.txt'): + with open('aianswer.txt', 'r', encoding='utf-8') as file: + ai_response = file.read() + print("AI Response:") + print(ai_response) + else: + print("Error: 'aianswer.txt' does not exist.")