Skip to content

Commit

Permalink
add cli options for host and port for app
Browse files Browse the repository at this point in the history
  • Loading branch information
rchan26 committed Jun 14, 2024
1 parent babb1d3 commit 93ec979
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
10 changes: 10 additions & 0 deletions reginald/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"streaming": "Whether to use streaming for the chat interaction.",
"slack_app_token": "Slack app token for the bot.",
"slack_bot_token": "Slack bot token for the bot.",
"host": "Host to listen on.",
"port": "Port to listen on.",
}

cli = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]})
Expand Down Expand Up @@ -261,6 +263,12 @@ def app(
device: Annotated[
str, typer.Option(envvar="LLAMA_INDEX_DEVICE", help=HELP_TEXT["device"])
] = DEFAULT_ARGS["device"],
host: Annotated[
str, typer.Option(envvar="REGINALD_HOST", help=HELP_TEXT["host"])
] = DEFAULT_ARGS["host"],
port: Annotated[
int, typer.Option(envvar="REGINALD_PORT", help=HELP_TEXT["port"])
] = DEFAULT_ARGS["port"],
) -> None:
"""
Sets up the response model and then creates a
Expand All @@ -273,6 +281,8 @@ def app(
set_up_logging_config(level=20)
main(
cli="app",
host=host,
port=port,
model=model,
model_name=model_name,
mode=mode,
Expand Down
2 changes: 2 additions & 0 deletions reginald/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
"is_path": False,
"n_gpu_layers": 0,
"device": "auto",
"host": "0.0.0.0",
"port": 8000,
}
14 changes: 12 additions & 2 deletions reginald/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from fastapi import FastAPI
from pydantic import BaseModel

from reginald.defaults import DEFAULT_ARGS
from reginald.models.setup_llm import setup_llm


Expand Down Expand Up @@ -43,8 +44,17 @@ async def channel_mention(query: Query):
return app


def run_reginald_app(**kwargs) -> None:
def run_reginald_app(
host: str | None = DEFAULT_ARGS["host"],
port: int | None = DEFAULT_ARGS["port"],
**kwargs
) -> None:
if host is None:
host = DEFAULT_ARGS["host"]
if port is None:
port = DEFAULT_ARGS["port"]

# set up response model
response_model = setup_llm(**kwargs)
app: FastAPI = create_reginald_app(response_model)
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host=host, port=port)
6 changes: 5 additions & 1 deletion reginald/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def main(
which_index: str | None = None,
slack_app_token: str | None = None,
slack_bot_token: str | None = None,
host: str | None = None,
port: int | None = None,
**kwargs,
):
# initialise logging
Expand Down Expand Up @@ -40,7 +42,9 @@ def main(
elif cli == "app":
from reginald.models.app import run_reginald_app

run_reginald_app(data_dir=data_dir, which_index=which_index, **kwargs)
run_reginald_app(
host=host, port=port, data_dir=data_dir, which_index=which_index, **kwargs
)
elif cli == "chat":
import warnings

Expand Down

0 comments on commit 93ec979

Please sign in to comment.