diff --git a/.github/workflows/build_msi_installer.yml b/.github/workflows/build_msi_installer.yml index cf2152e2e06..e8c09b5bd19 100644 --- a/.github/workflows/build_msi_installer.yml +++ b/.github/workflows/build_msi_installer.yml @@ -66,7 +66,7 @@ jobs: - name: Install stable promptflow if: ${{ github.event.inputs.version != null && github.event.inputs.version != '' }} run: | - pip install promptflow[azure,executable]==$env:INPUT_VERSION promptflow-tools + pip install "promptflow[azure,executable]==$env:INPUT_VERSION" promptflow-tools env: INPUT_VERSION: ${{ github.event.inputs.version }} shell: pwsh diff --git a/src/promptflow/promptflow/_sdk/_service/entry.py b/src/promptflow/promptflow/_sdk/_service/entry.py index 9cec481fbfa..a06f751374c 100644 --- a/src/promptflow/promptflow/_sdk/_service/entry.py +++ b/src/promptflow/promptflow/_sdk/_service/entry.py @@ -9,6 +9,8 @@ import subprocess import sys +import waitress + from promptflow._cli._utils import _get_cli_activity_name from promptflow._constants import PF_NO_INTERACTIVE_LOGIN from promptflow._sdk._constants import LOGGER_NAME @@ -70,7 +72,7 @@ def start_service(args): # User Agent will be set based on header in request, so not set globally here. os.environ[PF_NO_INTERACTIVE_LOGIN] = "true" port = args.port - get_app() + app, _ = create_app() def validate_port(port, force_start): if is_port_in_use(port): @@ -88,31 +90,39 @@ def validate_port(port, force_start): port = get_port_from_config(create_if_not_exists=True) validate_port(port, args.force) # Set host to localhost, only allow request from localhost. - cmd = [ - sys.executable, - "-m", - "waitress", - "--host", - "127.0.0.1", - f"--port={port}", - "--call", - "promptflow._sdk._service.entry:get_app", - ] - if args.synchronous: - subprocess.call(cmd) - else: - # Start a pfs process using detach mode - if platform.system() == "Windows": - os.spawnv(os.P_DETACH, sys.executable, cmd) - else: - os.system(" ".join(["nohup"] + cmd + ["&"])) - is_healthy = check_pfs_service_status(port) - if is_healthy: + if sys.executable.endswith("pfcli.exe"): + # For msi installer, use sdk api to start pfs since it's not supported to invoke waitress by cli directly + # after packaged by Pyinstaller. app.logger.info( f"Start Prompt Flow Service on http://localhost:{port}, version: {get_promptflow_sdk_version()}" ) + waitress.serve(app, host="127.0.0.1", port=port) else: - app.logger.warning(f"Pfs service start failed in {port}.") + cmd = [ + sys.executable, + "-m", + "waitress", + "--host", + "127.0.0.1", + f"--port={port}", + "--call", + "promptflow._sdk._service.entry:get_app", + ] + if args.synchronous: + subprocess.call(cmd) + else: + # Start a pfs process using detach mode + if platform.system() == "Windows": + os.spawnv(os.P_DETACH, sys.executable, cmd) + else: + os.system(" ".join(["nohup"] + cmd + ["&"])) + is_healthy = check_pfs_service_status(port) + if is_healthy: + app.logger.info( + f"Start Prompt Flow Service on http://localhost:{port}, version: {get_promptflow_sdk_version()}" + ) + else: + app.logger.warning(f"Pfs service start failed in {port}.") def main(): diff --git a/src/promptflow/promptflow/_sdk/_service/utils/utils.py b/src/promptflow/promptflow/_sdk/_service/utils/utils.py index 8969d4a2971..caaad27b98b 100644 --- a/src/promptflow/promptflow/_sdk/_service/utils/utils.py +++ b/src/promptflow/promptflow/_sdk/_service/utils/utils.py @@ -119,9 +119,8 @@ def is_pfs_service_healthy(pfs_port) -> bool: def check_pfs_service_status(pfs_port, time_delay=5, time_threshold=30) -> bool: - wait_time = time_delay - time.sleep(time_delay) - is_healthy = is_pfs_service_healthy(pfs_port) + wait_time = 0 + is_healthy = False while is_healthy is False and time_threshold > wait_time: logger.info( f"Pfs service is not ready. It has been waited for {wait_time}s, will wait for at most "