Added missing function docstring
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/env python3
|
"""
|
||||||
|
TODO: Description
|
||||||
|
|
||||||
# MIT License
|
Sources:
|
||||||
# Copyright (c) 2023 wunderwuzzi23
|
— https://github.com/wunderwuzzi23/yolo-ai-cmdbot
|
||||||
# Greetings from Seattle!
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -18,8 +19,9 @@ from termcolor import colored
|
|||||||
from colorama import init
|
from colorama import init
|
||||||
|
|
||||||
def read_config() -> any:
|
def read_config() -> any:
|
||||||
## Find the executing directory (e.g. in case an alias is set)
|
"""
|
||||||
## So we can find the config file
|
Find the executing directory (e.g. in case an alias is set), so we can find the config file.
|
||||||
|
"""
|
||||||
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)
|
||||||
|
|
||||||
@@ -29,8 +31,9 @@ def read_config() -> any:
|
|||||||
|
|
||||||
# Construct the prompt
|
# Construct the prompt
|
||||||
def get_full_prompt(user_prompt, shell):
|
def get_full_prompt(user_prompt, shell):
|
||||||
## Find the executing directory (e.g. in case an alias is set)
|
"""
|
||||||
## So we can find the prompt.txt file
|
Construct the prompt, finding the executing directiory so we can find the prompt.txty file.
|
||||||
|
"""
|
||||||
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)
|
||||||
|
|
||||||
@@ -48,6 +51,9 @@ def get_full_prompt(user_prompt, shell):
|
|||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
|
"""
|
||||||
|
Print usage information.
|
||||||
|
"""
|
||||||
print("Yolo v0.2.1 - by @wunderwuzzi23")
|
print("Yolo v0.2.1 - by @wunderwuzzi23")
|
||||||
print()
|
print()
|
||||||
print("Usage: yolo [-a] list the current directory information")
|
print("Usage: yolo [-a] list the current directory information")
|
||||||
@@ -62,7 +68,9 @@ def print_usage():
|
|||||||
|
|
||||||
|
|
||||||
def get_os_friendly_name():
|
def get_os_friendly_name():
|
||||||
# Get OS Name
|
"""
|
||||||
|
Get the name of the operating system.
|
||||||
|
"""
|
||||||
os_name = platform.system()
|
os_name = platform.system()
|
||||||
|
|
||||||
if os_name == "Linux":
|
if os_name == "Linux":
|
||||||
@@ -75,6 +83,10 @@ def get_os_friendly_name():
|
|||||||
return os_name
|
return os_name
|
||||||
|
|
||||||
def set_api_key():
|
def set_api_key():
|
||||||
|
"""
|
||||||
|
Set the OpenAI API key.
|
||||||
|
"""
|
||||||
|
|
||||||
# Two options for the user to specify they openai api key.
|
# Two options for the user to specify they openai api key.
|
||||||
#1. Place a ".env" file in same directory as this with the line:
|
#1. Place a ".env" file in same directory as this with the line:
|
||||||
# OPENAI_API_KEY="<yourkey>"
|
# OPENAI_API_KEY="<yourkey>"
|
||||||
@@ -123,7 +135,9 @@ if __name__ == "__main__":
|
|||||||
user_prompt = " ".join(arguments)
|
user_prompt = " ".join(arguments)
|
||||||
|
|
||||||
def call_open_ai(query):
|
def call_open_ai(query):
|
||||||
# do we have a prompt from the user?
|
"""
|
||||||
|
Do we have a prompt from the user?
|
||||||
|
"""
|
||||||
if query == "":
|
if query == "":
|
||||||
print ("No user prompt specified.")
|
print ("No user prompt specified.")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
@@ -152,22 +166,33 @@ def call_open_ai(query):
|
|||||||
init()
|
init()
|
||||||
|
|
||||||
def check_for_issue(response):
|
def check_for_issue(response):
|
||||||
|
"""
|
||||||
|
Todo
|
||||||
|
"""
|
||||||
prefixes = ("sorry", "i'm sorry", "the question is not clear", "i'm", "i am")
|
prefixes = ("sorry", "i'm sorry", "the question is not clear", "i'm", "i am")
|
||||||
if response.lower().startswith(prefixes):
|
if response.lower().startswith(prefixes):
|
||||||
print(colored("There was an issue: "+response, 'red'))
|
print(colored("There was an issue: "+response, 'red'))
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
def check_for_markdown(response):
|
def check_for_markdown(response):
|
||||||
# odd corner case, sometimes ChatCompletion returns markdown
|
"""
|
||||||
|
Odd corner case, sometimes ChatCompletion returns markdown
|
||||||
|
"""
|
||||||
if response.count("```",2):
|
if response.count("```",2):
|
||||||
print(colored("The proposed command contains markdown, so I did not execute the response directly: \n", 'red')+response)
|
print(colored("The proposed command contains markdown, so I did not execute the response directly: \n", 'red')+response)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
def missing_posix_display():
|
def missing_posix_display():
|
||||||
|
"""
|
||||||
|
Todo
|
||||||
|
"""
|
||||||
display = subprocess.check_output("echo $DISPLAY", shell=True)
|
display = subprocess.check_output("echo $DISPLAY", shell=True)
|
||||||
return display == b'\n'
|
return display == b'\n'
|
||||||
|
|
||||||
def prompt_user_input(response):
|
def prompt_user_input(response):
|
||||||
|
"""
|
||||||
|
Todo
|
||||||
|
"""
|
||||||
print("Command: " + colored(response, 'blue'))
|
print("Command: " + colored(response, 'blue'))
|
||||||
#print(config["safety"])
|
#print(config["safety"])
|
||||||
|
|
||||||
@@ -183,6 +208,9 @@ def prompt_user_input(response):
|
|||||||
return "Y"
|
return "Y"
|
||||||
|
|
||||||
def evaluate_input(user_input, command):
|
def evaluate_input(user_input, command):
|
||||||
|
"""
|
||||||
|
Todo
|
||||||
|
"""
|
||||||
if user_input.upper() == "Y" or user_input == "":
|
if user_input.upper() == "Y" or user_input == "":
|
||||||
if shell == "powershell.exe":
|
if shell == "powershell.exe":
|
||||||
subprocess.run([shell, "/c", command], shell=False)
|
subprocess.run([shell, "/c", command], shell=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user