CLI Improvements (#1021)

* Add gpt4all-bindings/cli/README.md

* Unify version information
- Was previously split; base one on the other
- Add VERSION_INFO as the "source of truth":
  - Modelled after sys.version_info.
  - Implemented as a tuple, because it's much easier for (partial)
    programmatic comparison.
- Previous API is kept intact.

* Add gpt4all-bindings/cli/developer_notes.md
- A few notes on what's what, especially regarding docs

* Add gpt4all-bindings/python/docs/gpt4all_cli.md
- The CLI user documentation

* Bump CLI version to 0.3.5

* Finalise docs & add to index.md
- Amend where necessary
- Fix typo in gpt4all_cli.md
- Mention and add link to CLI doc in index.md

* Add docstings to gpt4all-bindings/cli/app.py

* Better 'groovy' link & fix typo
- Documentation: point to the Hugging Face model card for 'groovy'
- Correct typo in app.py
This commit is contained in:
cosmic-snow
2023-06-23 21:09:31 +02:00
committed by GitHub
parent aed7b43143
commit ee26e8f271
5 changed files with 282 additions and 3 deletions

View File

@@ -0,0 +1,44 @@
# GPT4All Command-Line Interface (CLI)
GPT4All on the command-line.
## Documentation
<https://docs.gpt4all.io/gpt4all_cli.html>
## Quickstart
The CLI is based on the `gpt4all` Python bindings and the `typer` package.
The following shows one way to get started with the CLI, the documentation has more information.
Typically, you will want to replace `python` with `python3` on _Unix-like_ systems and `py -3` on
_Windows_. Also, it's assumed you have all the necessary Python components already installed.
The CLI is a self-contained Python script named [app.py] ([download][app.py-download]). As long as
its package dependencies are present, you can download and run it from wherever you like.
[app.py]: https://github.com/nomic-ai/gpt4all/blob/main/gpt4all-bindings/cli/app.py
[app.py-download]: https://raw.githubusercontent.com/nomic-ai/gpt4all/main/gpt4all-bindings/cli/app.py
```shell
# optional but recommended: create and use a virtual environment
python -m venv gpt4all-cli
```
_Windows_ and _Unix-like_ systems differ slightly in how you activate a _virtual environment_:
- _Unix-like_, typically: `. gpt4all-cli/bin/activate`
- _Windows_: `gpt4all-cli\Scripts\activate`
Then:
```shell
# pip-install the necessary packages; omit '--user' if using a virtual environment
python -m pip install --user --upgrade gpt4all typer
# run the CLI
python app.py repl
```
By default, it will automatically download the `groovy` model to `.cache/gpt4all/` in your user
directory, if necessary.
If you have already saved a model beforehand, specify its path with the `-m`/`--model` argument,
for example:
```shell
python app.py repl --model /home/user/my-gpt4all-models/GPT4All-13B-snoozy.ggmlv3.q4_0.bin
```

View File

@@ -1,9 +1,17 @@
"""GPT4All CLI
The GPT4All CLI is a self-contained script based on the `gpt4all` and `typer` packages. It offers a
REPL to communicate with a language model similar to the chat GUI application, but more basic.
"""
import sys
import typer
from collections import namedtuple
from typing_extensions import Annotated
from gpt4all import GPT4All
MESSAGES = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello there."},
@@ -17,7 +25,9 @@ SPECIAL_COMMANDS = {
"/help": lambda _: print("Special commands: /reset, /exit, /help and /clear"),
}
VERSION = "0.3.4"
VersionInfo = namedtuple('VersionInfo', ['major', 'minor', 'micro'])
VERSION_INFO = VersionInfo(0, 3, 5)
VERSION = '.'.join(map(str, VERSION_INFO)) # convert to string form, like: '1.2.3'
CLI_START_MESSAGE = f"""
@@ -47,6 +57,7 @@ def repl(
typer.Option("--n-threads", "-t", help="Number of threads to use for chatbot"),
] = None,
):
"""The CLI read-eval-print loop."""
gpt4all_instance = GPT4All(model)
# if threads are passed, set them
@@ -103,7 +114,8 @@ def repl(
@app.command()
def version():
print("gpt4all-cli v0.3.4")
"""The CLI version command."""
print(f"gpt4all-cli v{VERSION}")
if __name__ == "__main__":

View File

@@ -0,0 +1,25 @@
# Developing the CLI
## Documentation
Documentation can be found in three places:
- `app.py` docstrings & comments
- a Readme: `gpt4all-bindings/cli/README.md`
- the actual CLI documentation: `gpt4all-bindings/python/docs/gpt4all_cli.md`
The _docstrings_ are meant for programmatic use. Since the CLI is primarily geared towards users and
not to build on top, they're kept terse.
The _Readme_ is mostly meant for users and includes:
- a link to the _CLI documentation_ (on the [website])
- a Quickstart section with some guidance on how to get started with a sane setup
The _CLI documentation_ and other documentation are located in the above mentioned `docs/` folder.
They're in Markdown format and built for the [website]. Of the three, they should be the most
detailed.
[website]: https://docs.gpt4all.io/gpt4all_cli.html
## Versioning
The version number should now follow the `gpt4all` PyPI package, so compatibility is more clear.
The one place to change it is the `namedtuple` called `VERSION_INFO`.