Skip to content

Commit

Permalink
Linter fixes, dockblocks, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
dave1010 committed Dec 3, 2023
1 parent 93de76c commit 6f084ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 7 additions & 2 deletions clipea/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@


def clipea_main() -> None:
"""
Main function for the Clipea. It checks if the "llm" dependency is installed
and then prompts the user for input. It then routes the user's input
to the appropriate command in the router.
"""
if shutil.which("llm") is None:
sys.exit('Error: dependency "llm" not found. Run "clipea setup" to install')

USER_PROMPT = " ".join(sys.argv[1:])
router.commands_router(USER_PROMPT)
user_prompt = " ".join(sys.argv[1:])
router.commands_router(user_prompt)


if __name__ == "__main__":
Expand Down
13 changes: 7 additions & 6 deletions clipea/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def setup():
"""Checks if `llm` has an openai key and prompt to change it or create one"""
import llm.cli
import llm.cli # pylint: disable=import-outside-toplevel

should_setup = True
path = llm.cli.user_dir() / "keys.json"
Expand All @@ -22,7 +22,8 @@ def setup():
)
else:
print("An OpenAI key is already set-up, proceed if you want to change it.")
llm.cli.keys_set()
# Trigger key setting (llm uses Click)
llm.cli.keys_set() # pylint: disable=no-value-for-parameter


def clipea_execute_prompt(user_prompt: str):
Expand All @@ -40,8 +41,8 @@ def clipea_execute_prompt(user_prompt: str):
Args:
user_prompt (str): user command input
"""
from clipea import clipea_llm
from llm import Model, Response
from clipea import clipea_llm # pylint: disable=import-outside-toplevel
from llm import Model, Response # pylint: disable=import-outside-toplevel

llm_name: str = ''
if user_prompt.startswith('4 '):
Expand All @@ -50,7 +51,7 @@ def clipea_execute_prompt(user_prompt: str):

try:
model: Model = clipea_llm.init_llm(llm_name)
except Exception as e:
except Exception as e: # pylint: disable=broad-exception-caught
sys.exit(str(e))

user_data: str = cli.get_input()
Expand All @@ -64,7 +65,7 @@ def clipea_execute_prompt(user_prompt: str):
def alias():
"""Gives zsh's alias (automatic command buffering) commands to the user"""
shell: str = ENV["shell"]
if shell == "zsh" or shell == "-zsh":
if shell in ('zsh', '-zsh'):
command: str = f"alias '??'='source {CLIPEA_DIR}/clipea.zsh'"
user_prompt: str = f"Append this line to my {shell} startup file, \
watching out for quotes and escaping, then explain how to manually source it: {command}"
Expand Down
3 changes: 3 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Utils tests
"""
from clipea import utils


def test_anystr_force_str():
"""Basic test for anystr_force_str()"""
assert utils.anystr_force_str(b'hello') == 'hello'
assert utils.anystr_force_str('hello') == 'hello'

0 comments on commit 6f084ce

Please sign in to comment.