Minor modification

This commit is contained in:
Heiko Joerg Schick
2023-09-05 21:24:20 +02:00
parent bc1e997708
commit ea21e18bee
+15 -13
View File
@@ -107,6 +107,8 @@ def print_config(config):
print("* Temperature : " + str(config["temperature"]))
print("* Max. Tokens : " + str(config["max_tokens"]))
print("* Safety : " + str(bool(config["safety"])))
print("* Shell : " + str(config["shell"]))
def get_os_friendly_name():
@@ -122,7 +124,7 @@ def get_os_friendly_name():
return os_name
def call_open_ai(config, shell, query):
def call_open_ai(config, query):
"""
Do we have a prompt from the user?
"""
@@ -131,7 +133,7 @@ def call_open_ai(config, shell, query):
sys.exit(-1)
# Load the correct prompt based on Shell and OS and append the user's prompt
prompt = get_full_prompt(query, shell)
prompt = get_full_prompt(query, config["shell"])
# Make the first line also the system prompt
system_prompt = prompt[1]
@@ -196,26 +198,26 @@ def prompt_user_input(config, response):
return user_input
def evaluate_input(config, shell, user_input, command):
def evaluate_input(config, user_input, command):
"""
Todo
"""
if user_input.upper() == "Y" or user_input == "":
if shell == "powershell.exe":
subprocess.run([shell, "/c", command], shell=False, check=True)
if config["shell"] == "powershell.exe":
subprocess.run([config["shell"], "/c", command], shell=False, check=True)
else:
# Unix: /bin/bash /bin/zsh: uses -c both Ubuntu and macOS should work, others might not
subprocess.run([shell, "-c", command], shell=False, check=True)
subprocess.run([config["shell"], "-c", command], shell=False, check=True)
if user_input.upper() == "M":
print("Modify prompt: ", end = '')
modded_query = input()
modded_response = call_open_ai(config, shell, modded_query)
modded_response = call_open_ai(config, modded_query)
check_for_issue(modded_response)
check_for_markdown(modded_response)
modded_user_input = prompt_user_input(config, modded_response)
print()
evaluate_input(config, shell, modded_user_input, modded_response)
evaluate_input(config, modded_user_input, modded_response)
if user_input.upper() == "C":
if os.name == "posix" and missing_posix_display():
@@ -249,21 +251,21 @@ def main():
if args.safety:
config["safety"] = args.safety
# Unix based SHELL (/bin/bash, /bin/zsh), otherwise assuming it's Windows
config["shell"] = os.environ.get("SHELL", "powershell.exe")
if args.config:
print_config(config)
# Unix based SHELL (/bin/bash, /bin/zsh), otherwise assuming it's Windows
shell = os.environ.get("SHELL", "powershell.exe")
#Enable color output on Windows using colorama
init()
res_command = call_open_ai(config, shell, user_prompt)
res_command = call_open_ai(config, user_prompt)
check_for_issue(res_command)
check_for_markdown(res_command)
user_input = prompt_user_input(config, res_command)
print()
evaluate_input(config, shell, user_input, res_command)
evaluate_input(config, user_input, res_command)
if __name__ == "__main__":
main()