forked from microsoft/TaskWeaver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
54 lines (47 loc) · 1.32 KB
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import click
from taskweaver.cli.util import require_workspace
@click.command()
@require_workspace()
@click.option(
"--host",
"-h",
default="localhost",
help="Host to run TaskWeaver web server",
type=str,
show_default=True,
)
@click.option("--port", "-p", default=8080, help="Port to run TaskWeaver web server", type=int, show_default=True)
@click.option(
"--debug",
"-d",
is_flag=True,
default=False,
help="Run TaskWeaver web server in debug mode",
show_default=True,
)
@click.option(
"--open/--no-open",
"-o/-n",
is_flag=True,
default=True,
help="Open TaskWeaver web server in browser",
show_default=True,
)
def web(host: str, port: int, debug: bool, open: bool):
"""Start TaskWeaver web server"""
from taskweaver.chat.web import start_web_service
if not debug:
# debug mode will restart app iteratively, skip the plugin listing
# display_enabled_examples_plugins()
pass
def post_app_start():
if open:
click.secho("launching web browser...", fg="green")
open_url = f"http://{'localhost' if host == '0.0.0.0' else host}:{port}"
click.launch(open_url)
start_web_service(
host,
port,
is_debug=debug,
post_app_start=post_app_start if open else None,
)