Skip to content

Commit

Permalink
minor changes and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
lnxpy committed Sep 16, 2024
1 parent 9dec823 commit 776d737
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
run: python -m build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@release/v1
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.

60 changes: 16 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,32 @@
> :writing_hand: - Read the <a href="https://blog.imsadra.me/introducing-hey-your-ai-powered-pair-programming-friend">"Introducing Hey! - Your AI-powered Pair Programming Friend"</a> 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 from MindsDB. 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. 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.

<details>
<summary><h4>1. Setup the package</h4></summary>
#### 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.

</details>

<details>
<summary><h4>2. Set the <code>HEY_TOKEN</code></h4></summary>

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
```
</details>

### Usage
Expand All @@ -45,34 +41,15 @@ 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.

```sh
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
Expand Down Expand Up @@ -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",
Expand All @@ -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).
<img src="media/badge-dark.svg#gh-dark-mode-only" width=350 height=90>
<img src="media/badge-light.svg#gh-light-mode-only" width=350 height=90>
15 changes: 8 additions & 7 deletions hey/cli.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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)
5 changes: 3 additions & 2 deletions hey/configs/utils.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 = (
Expand Down
4 changes: 3 additions & 1 deletion hey/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion hey/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions hey/openai.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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."
)


Expand Down
2 changes: 1 addition & 1 deletion media/badge-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion media/badge-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 776d737

Please sign in to comment.