diff --git a/yolo.py b/yolo.py index 575f48e..961a036 100755 --- a/yolo.py +++ b/yolo.py @@ -140,14 +140,14 @@ def get_os_friendly_name(): return os_name -def get_system_prompt(user_prompt, shell): +def get_system_prompt(shell): """ - Retrieves and constructs a system prompt by replacing placeholders + Retrieves and constructs a system prompt by replacing placeholders in a predefined template with specific values. - The function finds the absolute path of the currently executing file - and, based on this path, identifies the directory of PROMPT_FILE. - It reads the file and replaces the placeholders {shell} and {os} + The function finds the absolute path of the currently executing file + and, based on this path, identifies the directory of PROMPT_FILE. + It reads the file and replaces the placeholders {shell} and {os} with the provided shell parameter and the friendly name of the operating system, respectively. Parameters @@ -160,7 +160,7 @@ def get_system_prompt(user_prompt, shell): Returns ------- str - The system prompt, constructed from the template prompt in PROMPT_FILE + The system prompt, constructed from the template prompt in PROMPT_FILE with the shell and OS placeholders replaced with actual values. """ yolo_path = os.path.abspath(__file__) @@ -171,22 +171,23 @@ def get_system_prompt(user_prompt, shell): system_prompt = open(prompt_file,"r").read() system_prompt = system_prompt.replace("{shell}", shell) system_prompt = system_prompt.replace("{os}", get_os_friendly_name()) - + return system_prompt def chat_completion(client, query, config): """ Generate a chat-based completion for a given query using a specified model. - + This function sends a user query to a chat model and returns the generated response. - + Parameters: client (object): The client object to interact with the chat service. query (str): The user's query to send to the chat model. config (dict): Configuration settings for the chat service, which should include: - "shell" (str): Type of shell to use in the system prompt. - "model" (str): The specific model to use for the chat completion. - - "temperature" (float): Sampling temperature to use for the response generation (higher values mean the model will take more risks). + - "temperature" (float): Sampling temperature to use for the response generation (higher + values mean the model will take more risks). - "max_tokens" (int): Maximum number of tokens to generate in the chat response. Returns: @@ -198,8 +199,8 @@ def chat_completion(client, query, config): if query == "": print ("No user prompt specified.") sys.exit(-1) - - system_prompt = get_system_prompt(query, config["shell"]) + + system_prompt = get_system_prompt(config["shell"]) # Ensure query is a question if query[-1:] != "?" and query[-1:] != ".": @@ -213,7 +214,7 @@ def chat_completion(client, query, config): ], temperature=config["temperature"], max_tokens=config["max_tokens"]) - + return response def check_for_issue(response): @@ -273,6 +274,7 @@ def missing_posix_display(): return display == b'\n' +# TODO: Change the output according the configuration def prompt_user_input(config, response): """ Print the command proposal in blue and prompt the user for next action based on the safety @@ -336,6 +338,7 @@ def evaluate_input(config, user_input, command): # Unix: /bin/bash /bin/zsh: uses -c both Ubuntu and macOS should work, others might not subprocess.run([config["shell"], "-c", command], shell=False, check=True) + # TODO: change call_open_ai function if user_input.upper() == "M": print("Modify prompt: ", end = '') modded_query = input() @@ -391,7 +394,7 @@ def main(): result = chat_completion(client, user_prompt, config) check_for_issue(result) check_for_markdown(result) - + user_input = prompt_user_input(config, result) print() evaluate_input(config, user_input, result)