Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output token control to CLI interface #2225

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions gpt4all-bindings/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
import typer
from gpt4all import GPT4All

# Set default values
n_predict = 200

def getUserTokens(n_tokens_start):
print(f"Tokens = {n_tokens_start}")
try:
t_input = int(input("New max tokens? "))
except ValueError as ve:
print(f"Invalid entry; only positive integers are allowed\n")
return
if t_input > 0:
print(f"New tokens {t_input}")
global n_predict
n_predict = t_input
else:
print("Invalid entry; only positive integers are allowed")

MESSAGES = [
{"role": "system", "content": "You are a helpful assistant."},
Expand All @@ -25,13 +41,15 @@
"/reset": lambda messages: messages.clear(),
"/exit": lambda _: sys.exit(),
"/clear": lambda _: print("\n" * 100),
"/help": lambda _: print("Special commands: /reset, /exit, /help and /clear"),
"/help": lambda _: print("Special commands: /reset, /exit, /help, /tokens and /clear"),
"/tokens": lambda _: getUserTokens(n_predict),
}

VersionInfo = namedtuple('VersionInfo', ['major', 'minor', 'micro'])
VERSION_INFO = VersionInfo(1, 0, 2)
VERSION = '.'.join(map(str, VERSION_INFO)) # convert to string form, like: '1.2.3'


CLI_START_MESSAGE = f"""

██████ ██████ ████████ ██ ██ █████ ██ ██
Expand Down Expand Up @@ -117,7 +135,7 @@ def _old_loop(gpt4all_instance):
tokens_size=0,
n_past=0,
n_ctx=0,
n_predict=200,
n_predict=n_predict,
top_k=40,
top_p=0.9,
min_p=0.0,
Expand Down Expand Up @@ -153,7 +171,7 @@ def _new_loop(gpt4all_instance):
response_generator = gpt4all_instance.generate(
message,
# preferential kwargs for chat ux
max_tokens=200,
max_tokens=n_predict,
temp=0.9,
top_k=40,
top_p=0.9,
Expand Down