Added constant for prompt file

This commit is contained in:
Heiko Joerg Schick
2023-09-05 22:38:19 +02:00
parent a3e4209d1e
commit 8e8b1c4181
+6 -5
View File
@@ -20,6 +20,7 @@ from termcolor import colored
from colorama import init from colorama import init
CONFIG_FILE = "yolo.yaml" CONFIG_FILE = "yolo.yaml"
PROMPT_FILE = "yolo.prompt"
def read_yaml_config() -> any: def read_yaml_config() -> any:
""" """
@@ -126,10 +127,10 @@ def get_os_friendly_name():
def get_full_prompt(user_prompt, shell): def get_full_prompt(user_prompt, shell):
""" """
Constructs a full prompt string by appending the user's prompt to a predefined prompt template Constructs a full prompt string by appending the user's prompt to a predefined prompt template
located in the 'yolo.prompt' file. located in the PROMPT_FILE file.
The function finds the absolute path of the currently executing file, and based on this path, The function finds the absolute path of the currently executing file, and based on this path,
identifies the directory of 'yolo.prompt'. It reads this file, replaces placeholders {shell} identifies the directory of PROMPT_FILE. It reads this file, replaces placeholders {shell}
and {os} in the text file with a passed shell parameter and the friendly name of the operating and {os} in the text file with a passed shell parameter and the friendly name of the operating
system respectively. The user prompt is then appended to this pre-prompt. If the resulting system respectively. The user prompt is then appended to this pre-prompt. If the resulting
prompt does not end with a question mark or a period, a question mark is added at last. prompt does not end with a question mark or a period, a question mark is added at last.
@@ -139,19 +140,19 @@ def get_full_prompt(user_prompt, shell):
user_prompt : str user_prompt : str
The prompt supplied by the user to be appended to the pre-prompt. The prompt supplied by the user to be appended to the pre-prompt.
shell : str shell : str
The shell information to be inserted in the place of {shell} placeholder in 'yolo.prompt'. The shell information to be inserted in the place of {shell} placeholder in PROMPT_FILE.
Returns Returns
------- -------
str str
The full prompt, constructed from the template prompt in 'yolo.prompt', The full prompt, constructed from the template prompt in PROMPT_FILE,
user-provided shell info, the OS name, and the user-supplied prompt string. user-provided shell info, the OS name, and the user-supplied prompt string.
""" """
yolo_path = os.path.abspath(__file__) yolo_path = os.path.abspath(__file__)
prompt_path = os.path.dirname(yolo_path) prompt_path = os.path.dirname(yolo_path)
## Load the prompt and prep it ## Load the prompt and prep it
prompt_file = os.path.join(prompt_path, "yolo.prompt") prompt_file = os.path.join(prompt_path, PROMPT_FILE)
pre_prompt = open(prompt_file,"r").read() pre_prompt = open(prompt_file,"r").read()
pre_prompt = pre_prompt.replace("{shell}", shell) pre_prompt = pre_prompt.replace("{shell}", shell)
pre_prompt = pre_prompt.replace("{os}", get_os_friendly_name()) pre_prompt = pre_prompt.replace("{os}", get_os_friendly_name())