Fixed simple pylint warnings

This commit is contained in:
2024-08-19 19:29:59 +02:00
parent 0a5769f8a0
commit 9610525ecb
+17 -14
View File
@@ -140,14 +140,14 @@ def get_os_friendly_name():
return os_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. in a predefined template with specific values.
The function finds the absolute path of the currently executing file The function finds the absolute path of the currently executing file
and, based on this path, identifies the directory of PROMPT_FILE. and, based on this path, identifies the directory of PROMPT_FILE.
It reads the file and replaces the placeholders {shell} and {os} 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. with the provided shell parameter and the friendly name of the operating system, respectively.
Parameters Parameters
@@ -160,7 +160,7 @@ def get_system_prompt(user_prompt, shell):
Returns Returns
------- -------
str 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. with the shell and OS placeholders replaced with actual values.
""" """
yolo_path = os.path.abspath(__file__) 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 = open(prompt_file,"r").read()
system_prompt = system_prompt.replace("{shell}", shell) system_prompt = system_prompt.replace("{shell}", shell)
system_prompt = system_prompt.replace("{os}", get_os_friendly_name()) system_prompt = system_prompt.replace("{os}", get_os_friendly_name())
return system_prompt return system_prompt
def chat_completion(client, query, config): def chat_completion(client, query, config):
""" """
Generate a chat-based completion for a given query using a specified model. 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. This function sends a user query to a chat model and returns the generated response.
Parameters: Parameters:
client (object): The client object to interact with the chat service. client (object): The client object to interact with the chat service.
query (str): The user's query to send to the chat model. query (str): The user's query to send to the chat model.
config (dict): Configuration settings for the chat service, which should include: config (dict): Configuration settings for the chat service, which should include:
- "shell" (str): Type of shell to use in the system prompt. - "shell" (str): Type of shell to use in the system prompt.
- "model" (str): The specific model to use for the chat completion. - "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. - "max_tokens" (int): Maximum number of tokens to generate in the chat response.
Returns: Returns:
@@ -198,8 +199,8 @@ def chat_completion(client, query, config):
if query == "": if query == "":
print ("No user prompt specified.") print ("No user prompt specified.")
sys.exit(-1) sys.exit(-1)
system_prompt = get_system_prompt(query, config["shell"]) system_prompt = get_system_prompt(config["shell"])
# Ensure query is a question # Ensure query is a question
if query[-1:] != "?" and query[-1:] != ".": if query[-1:] != "?" and query[-1:] != ".":
@@ -213,7 +214,7 @@ def chat_completion(client, query, config):
], ],
temperature=config["temperature"], temperature=config["temperature"],
max_tokens=config["max_tokens"]) max_tokens=config["max_tokens"])
return response return response
def check_for_issue(response): def check_for_issue(response):
@@ -273,6 +274,7 @@ def missing_posix_display():
return display == b'\n' return display == b'\n'
# TODO: Change the output according the configuration
def prompt_user_input(config, response): def prompt_user_input(config, response):
""" """
Print the command proposal in blue and prompt the user for next action based on the safety 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 # 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) subprocess.run([config["shell"], "-c", command], shell=False, check=True)
# TODO: change call_open_ai function
if user_input.upper() == "M": if user_input.upper() == "M":
print("Modify prompt: ", end = '') print("Modify prompt: ", end = '')
modded_query = input() modded_query = input()
@@ -391,7 +394,7 @@ def main():
result = chat_completion(client, user_prompt, config) result = chat_completion(client, user_prompt, config)
check_for_issue(result) check_for_issue(result)
check_for_markdown(result) check_for_markdown(result)
user_input = prompt_user_input(config, result) user_input = prompt_user_input(config, result)
print() print()
evaluate_input(config, user_input, result) evaluate_input(config, user_input, result)