Minor modification
This commit is contained in:
@@ -107,6 +107,8 @@ def print_config(config):
|
|||||||
print("* Temperature : " + str(config["temperature"]))
|
print("* Temperature : " + str(config["temperature"]))
|
||||||
print("* Max. Tokens : " + str(config["max_tokens"]))
|
print("* Max. Tokens : " + str(config["max_tokens"]))
|
||||||
print("* Safety : " + str(bool(config["safety"])))
|
print("* Safety : " + str(bool(config["safety"])))
|
||||||
|
print("* Shell : " + str(config["shell"]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_os_friendly_name():
|
def get_os_friendly_name():
|
||||||
@@ -122,7 +124,7 @@ def get_os_friendly_name():
|
|||||||
|
|
||||||
return os_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?
|
Do we have a prompt from the user?
|
||||||
"""
|
"""
|
||||||
@@ -131,7 +133,7 @@ def call_open_ai(config, shell, query):
|
|||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Load the correct prompt based on Shell and OS and append the user's prompt
|
# 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
|
# Make the first line also the system prompt
|
||||||
system_prompt = prompt[1]
|
system_prompt = prompt[1]
|
||||||
@@ -196,26 +198,26 @@ def prompt_user_input(config, response):
|
|||||||
|
|
||||||
return user_input
|
return user_input
|
||||||
|
|
||||||
def evaluate_input(config, shell, user_input, command):
|
def evaluate_input(config, user_input, command):
|
||||||
"""
|
"""
|
||||||
Todo
|
Todo
|
||||||
"""
|
"""
|
||||||
if user_input.upper() == "Y" or user_input == "":
|
if user_input.upper() == "Y" or user_input == "":
|
||||||
if shell == "powershell.exe":
|
if config["shell"] == "powershell.exe":
|
||||||
subprocess.run([shell, "/c", command], shell=False, check=True)
|
subprocess.run([config["shell"], "/c", command], shell=False, check=True)
|
||||||
else:
|
else:
|
||||||
# Unix: /bin/bash /bin/zsh: uses -c both Ubuntu and macOS should work, others might not
|
# 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":
|
if user_input.upper() == "M":
|
||||||
print("Modify prompt: ", end = '')
|
print("Modify prompt: ", end = '')
|
||||||
modded_query = input()
|
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_issue(modded_response)
|
||||||
check_for_markdown(modded_response)
|
check_for_markdown(modded_response)
|
||||||
modded_user_input = prompt_user_input(config, modded_response)
|
modded_user_input = prompt_user_input(config, modded_response)
|
||||||
print()
|
print()
|
||||||
evaluate_input(config, shell, modded_user_input, modded_response)
|
evaluate_input(config, modded_user_input, modded_response)
|
||||||
|
|
||||||
if user_input.upper() == "C":
|
if user_input.upper() == "C":
|
||||||
if os.name == "posix" and missing_posix_display():
|
if os.name == "posix" and missing_posix_display():
|
||||||
@@ -249,21 +251,21 @@ def main():
|
|||||||
if args.safety:
|
if args.safety:
|
||||||
config["safety"] = 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:
|
if args.config:
|
||||||
print_config(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
|
#Enable color output on Windows using colorama
|
||||||
init()
|
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_issue(res_command)
|
||||||
check_for_markdown(res_command)
|
check_for_markdown(res_command)
|
||||||
user_input = prompt_user_input(config, res_command)
|
user_input = prompt_user_input(config, res_command)
|
||||||
print()
|
print()
|
||||||
evaluate_input(config, shell, user_input, res_command)
|
evaluate_input(config, user_input, res_command)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user