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