Add backend option help

This commit is contained in:
Jeff Epler 2023-09-24 10:56:28 -05:00
parent 9f5f181a3c
commit 350c0a3d70
No known key found for this signature in database
GPG key ID: D5BF15AB975AB4DE
5 changed files with 44 additions and 3 deletions

View file

@ -32,5 +32,5 @@ repos:
rev: v2.17.0
hooks:
- id: pylint
additional_dependencies: [click,dataclasses_json,httpx,lorem-text,'textual>=0.18.0',websockets,tiktoken]
additional_dependencies: [click,dataclasses_json,httpx,lorem-text,simple-parsing,'textual>=0.18.0',tiktoken,websockets]
args: ['--source-roots', 'src']

View file

@ -26,6 +26,7 @@ dependencies = [
"httpx",
"lorem-text",
"platformdirs",
"simple_parsing",
"textual>=0.18.0",
"tiktoken",
"websockets",

View file

@ -22,9 +22,13 @@ class Lorem:
@dataclass
class Parameters:
delay_mu: float = 0.035
"""Average delay between tokens"""
delay_sigma: float = 0.02
"""Standard deviation of token delay"""
paragraph_lo: int = 1
"""Minimum response paragraph count"""
paragraph_hi: int = 5
"""Maximum response paragraph count (inclusive)"""
def __init__(self):
self.parameters = self.Parameters()

View file

@ -72,6 +72,7 @@ class ChatGPT:
@dataclass
class Parameters:
model: str = "gpt-3.5-turbo"
"""The model to use. The most common alternative value is 'gpt-4'."""
max_request_tokens: int = 1024
"""The approximate greatest number of tokens to send in a request. When the session is long, the system prompt and 1 or more of the most recent interaction steps are sent."""

View file

@ -8,10 +8,11 @@ import importlib
import pathlib
import pkgutil
import subprocess
from dataclasses import dataclass, fields
from dataclasses import MISSING, dataclass, fields
import click
import platformdirs
from simple_parsing.docstring import get_attribute_docstring
from . import commands # pylint: disable=no-name-in-module
from .session import Session
@ -88,7 +89,33 @@ def set_system_message(ctx, param, value): # pylint: disable=unused-argument
def set_backend(ctx, param, value): # pylint: disable=unused-argument
ctx.obj.api = get_api(value)
try:
ctx.obj.api = get_api(value)
except ModuleNotFoundError as e:
raise click.BadParameter(str(e))
def backend_help(ctx, param, value): # pylint: disable=unused-argument
if ctx.resilient_parsing or not value:
return
if ctx.obj.api is None:
set_backend(ctx, "--backend", "chatgpt")
api = ctx.obj.api
if not hasattr(api, "parameters"):
click.utils.echo(f"{api.__class__.__name__} does not support parameters")
else:
click.utils.echo(f"{api.__class__.__name__} accepts the following parameters")
for f in fields(api.parameters):
default = f.default if f.default_factory is MISSING else f.default_factory()
doc = get_attribute_docstring(type(api.parameters), f.name).docstring_below
newline_doc = f"\n {doc}" if doc else ""
click.utils.echo(
f"""\
-B {f.name}:{f.type.__name__} (default: {default}){newline_doc}"""
)
ctx.exit()
def set_backend_option(ctx, param, opts): # pylint: disable=unused-argument
@ -155,6 +182,14 @@ def uses_new_session(f):
expose_value=False,
is_eager=True,
)(f)
f = click.option(
"--backend-help",
is_flag=True,
is_eager=True,
callback=backend_help,
expose_value=False,
help="Show information about backend options",
)(f)
f = click.option(
"--backend-option",
"-B",