From e08dd06d354b06812049f696c1aff07b5bec32f3 Mon Sep 17 00:00:00 2001 From: Sadra Yahyapour Date: Tue, 17 Sep 2024 02:19:53 +0330 Subject: [PATCH] minor changes and linting --- .github/workflows/release.yml | 2 +- .pre-commit-config.yaml | 18 +++++++++++ LICENSE | 1 - README.md | 60 ++++++++++------------------------- hey/cli.py | 15 +++++---- hey/configs/utils.py | 5 +-- hey/consts.py | 4 ++- hey/editor.py | 2 +- hey/openai.py | 10 +++--- media/badge-dark.svg | 2 +- media/badge-light.svg | 2 +- 11 files changed, 56 insertions(+), 65 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 927e7d7..59aa1b8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,4 +30,4 @@ jobs: run: python -m build - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..55bca71 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: + - repo: "https://github.com/pre-commit/pre-commit-hooks" + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.5.5 + hooks: + - id: ruff + args: [--fix, --select, I] + - id: ruff-format + - repo: https://github.com/asottile/pyupgrade + rev: v3.17.0 + hooks: + - id: pyupgrade + args: [--py38-plus] diff --git a/LICENSE b/LICENSE index 1d34172..8fa7698 100644 --- a/LICENSE +++ b/LICENSE @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/README.md b/README.md index fcf2613..a2b7a46 100644 --- a/README.md +++ b/README.md @@ -6,36 +6,32 @@ > :writing_hand: - Read the "Introducing Hey! - Your AI-powered Pair Programming Friend" article about the creation process, development phases, and a detailed overview of Hey. -Hey is a CLI-based AI assistant that is powered by the ChatGPT AI model versions supported by [MindsDB](https://mindsdb.com/). This project is designed for [Hashnode X MindsDB](https://hashnode.com/hackathons/mindsdb?source=hncounter-feed) hackathon. +Hey is a free CLI-based AI assistant that is powered by the LLMs. You can set which LLM service you want to connect Hey to. -You may need a MindsDB token to use Hey. You can generate one for your personal uses for free from [here](https://mdb.ai). You can set Hey to interact with any other LLM service URL though. You're not limited to mdb.ai. +> [!TIP] +> We recommend using the free tokens provided by MindsDB. You can generate one for your personal uses for free on [mdb.ai](https://mdb.ai). You can set Hey to interact with any other LLM service though. You're not limited to mdb.ai. It's a recommendation. ### Installation -Make sure you have `pip` and `python>=3.6` installed on your machine and follow the steps. +Make sure you have `pip` and `python>=3.8` installed on your machine and follow the steps. -
-

1. Setup the package

+#### 1. Setup the package -##### Option A - Download from PyPI archive +###### Option A - Download from PyPI ```sh pip install -U hey-mindsdb ``` -##### Option B - Download from GitHub archive +###### Option B - Download from the repository ```sh pip install git+http://github.com/lnxpy/hey.git ``` -> :warning:: Hey is POSIX-friendly. It might not work properly on Windows machines at the moment. +#### 2. Set the token +Once you got the package installed on your system, it's time to set the token into hey. Run the following command to set the token. -
- -
-

2. Set the HEY_TOKEN

- -Once you got the package installed on your system, it's time to add the token that you just copied from [mdb.ai](https://mdb.ai) into hey, use `hey auth` to add your token. - -> :warning:: Your token will not be echoed. +```sh +hey auth +```
### Usage @@ -45,26 +41,7 @@ There are different commands and sub-commands implemented once you install `hey` hey --help ``` -``` - - Usage: hey [OPTIONS] COMMAND [ARGS]... - - Hey is a pair-programming friend that interacts with ChatGPT and responds back in a pretty - style. ✨ - -╭─ Options ─────────────────────────────────────────────────────────────────────────────────────╮ -│ --no-style,--ns Don't style the output. │ -│ --version -V Show the current version of Hey. │ -│ --install-completion Install completion for the current shell. │ -│ --show-completion Show completion for the current shell, to copy it or │ -│ customize the installation. │ -│ --help Show this message and exit. │ -╰───────────────────────────────────────────────────────────────────────────────────────────────╯ -╭─ Commands ────────────────────────────────────────────────────────────────────────────────────╮ -│ ask Ask Hey directly in-command. │ -│ config Configuration management. │ -╰───────────────────────────────────────────────────────────────────────────────────────────────╯ -``` +#### TLDR; - If you want to use `Hey` in a fast and quick way, use the `ask` command. @@ -72,7 +49,7 @@ hey --help hey ask "explain the duality term in quantum physics." ``` -- If your question needs more explanations with code snippets, then just `hey`. +- If your question needs more explanations with code snippets maybe, then just `hey`. ```sh hey @@ -115,7 +92,6 @@ Here is more information about each configuration parameter. // how would you like `hey` to think? "loading_text": "Thinking..", - // thinking animation symbol // check out full list: python -m rich.spinner "loading_spinner": "dots", @@ -124,15 +100,11 @@ Here is more information about each configuration parameter. } ``` -### Tech Stack -- Infrastructures & Hosting - - [MindsDB](https://mdb.ai) - ### License Hey is being licensed under the [MIT License](https://github.com/lnxpy/hey/blob/main/LICENSE). -### Special Thanks to -[MindsDB](https://mindsdb.com) X [Hashnode](https://hashnode.com) for hosting this great hackathon. +### Shout-out to +Hey! was created for a hackathon partnering [MindsDB](https://mindsdb.com) X [Hashnode](https://hashnode.com). diff --git a/hey/cli.py b/hey/cli.py index 0b56890..4c1317b 100644 --- a/hey/cli.py +++ b/hey/cli.py @@ -1,18 +1,17 @@ +import getpass from datetime import datetime from typing import Annotated, Optional -import typer import keyring -import getpass +import typer from rich.markdown import Markdown from rich.panel import Panel from hey import __version__, console from hey.configs import cli, configs -from hey.consts import APP_NAME +from hey.consts import APP_NAME, HEY_TOKEN from hey.editor import open_tmp_editor from hey.openai import answer -from hey.consts import HEY_TOKEN_KEY app = typer.Typer() app.add_typer(cli.app, name="config") @@ -78,10 +77,12 @@ def ask( result = answer(user_input, no_style) console.print(result) + @app.command() def auth(): """ - Take HEY_TOKEN from user. + Set the token. """ - password = getpass.getpass("Copy and paste your token here, [Token will not be echoed] > ") - keyring.set_password("system",HEY_TOKEN_KEY,password) + + token = getpass.getpass("Token:") + keyring.set_password("system", HEY_TOKEN, token) diff --git a/hey/configs/utils.py b/hey/configs/utils.py index dd03799..5d522cf 100644 --- a/hey/configs/utils.py +++ b/hey/configs/utils.py @@ -1,7 +1,8 @@ import json import os -from hey.consts import CONFIG_FILE_PATH, BASE_CONFIG, APP_CONFIG_DIR + from hey import console +from hey.consts import APP_CONFIG_DIR, BASE_CONFIG, CONFIG_FILE_PATH def read_configs() -> dict: @@ -13,7 +14,7 @@ def read_configs() -> dict: if os.path.exists(CONFIG_FILE_PATH): try: - with open(CONFIG_FILE_PATH, "r") as file: + with open(CONFIG_FILE_PATH) as file: return json.loads(file.read()) except json.JSONDecodeError as e: error_message = ( diff --git a/hey/consts.py b/hey/consts.py index dd9b281..7ab457a 100644 --- a/hey/consts.py +++ b/hey/consts.py @@ -5,7 +5,9 @@ # App name APP_NAME = "Hey" -HEY_TOKEN_KEY = "HEY_TOKEN" + +# Token key name +HEY_TOKEN = "HEY_TOKEN" if platform.system().lower() == "windows": DEFAULT_EDITOR = os.environ.get("EDITOR", "notepad") diff --git a/hey/editor.py b/hey/editor.py index c7ebfd0..a0cb4da 100644 --- a/hey/editor.py +++ b/hey/editor.py @@ -17,7 +17,7 @@ def open_tmp_editor() -> str: subprocess.run([DEFAULT_EDITOR, temp_file_path]) - with open(temp_file_path, "r") as file: + with open(temp_file_path) as file: data = file.read() os.unlink(temp_file_path) diff --git a/hey/openai.py b/hey/openai.py index e0948ee..876592e 100644 --- a/hey/openai.py +++ b/hey/openai.py @@ -1,15 +1,13 @@ -import os import time -import keyring +import keyring from openai import OpenAI, OpenAIError from rich.console import Console from rich.markdown import Markdown from rich.panel import Panel from hey.configs import configs -from hey.consts import BASE_CONFIG -from hey.consts import HEY_TOKEN_KEY +from hey.consts import BASE_CONFIG, HEY_TOKEN from hey.exceptions import ConnectionIssue, TokenIsNotDefined @@ -18,12 +16,12 @@ def __init__(self) -> None: self.is_valid = False def validate(self) -> str: - token = keyring.get_password("system",HEY_TOKEN_KEY) + token = keyring.get_password("system", HEY_TOKEN) if token: self.is_valid = True return token raise TokenIsNotDefined( - "token is not defined, Use `hey auth` to set your token." + "token is not defined, Use `hey auth` to set the token." ) diff --git a/media/badge-dark.svg b/media/badge-dark.svg index c0d2f2f..a04511e 100644 --- a/media/badge-dark.svg +++ b/media/badge-dark.svg @@ -404,4 +404,4 @@ - \ No newline at end of file + diff --git a/media/badge-light.svg b/media/badge-light.svg index 768f0b7..b2fb271 100644 --- a/media/badge-light.svg +++ b/media/badge-light.svg @@ -197,4 +197,4 @@ - \ No newline at end of file +