diff --git a/.github/workflows/build_msi_installer.yml b/.github/workflows/build_msi_installer.yml index 2feaf69ff80..5513f34ca82 100644 --- a/.github/workflows/build_msi_installer.yml +++ b/.github/workflows/build_msi_installer.yml @@ -59,7 +59,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,azureml-serving,executor-service]==$env:INPUT_VERSION" promptflow-tools env: INPUT_VERSION: ${{ github.event.inputs.version }} shell: pwsh diff --git a/src/promptflow/promptflow/_sdk/_service/app.py b/src/promptflow/promptflow/_sdk/_service/app.py index ddcda0cf633..f2f2484efa7 100644 --- a/src/promptflow/promptflow/_sdk/_service/app.py +++ b/src/promptflow/promptflow/_sdk/_service/app.py @@ -11,7 +11,12 @@ from flask_cors import CORS from werkzeug.exceptions import HTTPException -from promptflow._sdk._constants import PF_SERVICE_HOUR_TIMEOUT, PF_SERVICE_LOG_FILE, PF_SERVICE_MONITOR_SECOND +from promptflow._sdk._constants import ( + HOME_PROMPT_FLOW_DIR, + PF_SERVICE_HOUR_TIMEOUT, + PF_SERVICE_LOG_FILE, + PF_SERVICE_MONITOR_SECOND, +) from promptflow._sdk._service import Api from promptflow._sdk._service.apis.collector import trace_collector from promptflow._sdk._service.apis.connection import api as connection_api @@ -26,7 +31,7 @@ get_port_from_config, kill_exist_service, ) -from promptflow._sdk._utils import get_promptflow_sdk_version, overwrite_null_std_logger +from promptflow._sdk._utils import get_promptflow_sdk_version, overwrite_null_std_logger, read_write_by_user from promptflow._utils.thread_utils import ThreadWithContextVars overwrite_null_std_logger() @@ -69,7 +74,11 @@ def create_app(): # Enable log app.logger.setLevel(logging.INFO) # each env will have its own log file - log_file = get_current_env_pfs_file(PF_SERVICE_LOG_FILE) + if sys.executable.endswith("pfcli.exe"): + log_file = HOME_PROMPT_FLOW_DIR / PF_SERVICE_LOG_FILE + log_file.touch(mode=read_write_by_user(), exist_ok=True) + else: + log_file = get_current_env_pfs_file(PF_SERVICE_LOG_FILE) # Create a rotating file handler with a max size of 1 MB and keeping up to 1 backup files handler = RotatingFileHandler(filename=log_file, maxBytes=1_000_000, backupCount=1) formatter = logging.Formatter("[%(asctime)s][%(name)s][%(levelname)s] - %(message)s") diff --git a/src/promptflow/promptflow/_sdk/_service/entry.py b/src/promptflow/promptflow/_sdk/_service/entry.py index f37e6100d64..54e8cbcd519 100644 --- a/src/promptflow/promptflow/_sdk/_service/entry.py +++ b/src/promptflow/promptflow/_sdk/_service/entry.py @@ -22,7 +22,6 @@ get_started_service_info, is_port_in_use, kill_exist_service, - kill_service_get_from_original_port_file, ) from promptflow._sdk._utils import get_promptflow_sdk_version, print_pf_version from promptflow._utils.logger_utils import get_cli_sdk_logger # noqa: E402 @@ -89,9 +88,6 @@ def start_service(args): if args.debug: os.environ[PF_SERVICE_DEBUG] = "true" - # add this logic to stop pfs service which is start in the original port file. - kill_service_get_from_original_port_file() - def validate_port(port, force_start): if is_port_in_use(port): if force_start: diff --git a/src/promptflow/promptflow/_sdk/_service/utils/utils.py b/src/promptflow/promptflow/_sdk/_service/utils/utils.py index 14ddac036cc..1cdafa39912 100644 --- a/src/promptflow/promptflow/_sdk/_service/utils/utils.py +++ b/src/promptflow/promptflow/_sdk/_service/utils/utils.py @@ -60,7 +60,11 @@ def get_current_env_pfs_file(file_name): def get_port_from_config(create_if_not_exists=False): - port_file_path = get_current_env_pfs_file(PF_SERVICE_PORT_FILE) + if sys.executable.endswith("pfcli.exe"): + port_file_path = HOME_PROMPT_FLOW_DIR / PF_SERVICE_PORT_FILE + port_file_path.touch(mode=read_write_by_user(), exist_ok=True) + else: + port_file_path = get_current_env_pfs_file(PF_SERVICE_PORT_FILE) with open(port_file_path, "r", encoding=DEFAULT_ENCODING) as f: service_config = load_yaml(f) or {} port = service_config.get("service", {}).get("port", None) @@ -74,22 +78,13 @@ def get_port_from_config(create_if_not_exists=False): return port -def kill_service_get_from_original_port_file(): - if (HOME_PROMPT_FLOW_DIR / PF_SERVICE_PORT_FILE).exists(): - with open(HOME_PROMPT_FLOW_DIR / PF_SERVICE_PORT_FILE, "r", encoding=DEFAULT_ENCODING) as f: - service_config = load_yaml(f) or {} - port = service_config.get("service", {}).get("port", None) - if port: - if is_port_in_use(port): - logger.debug(f"Kill the deprecated port {port} got from service key in thr pfs.port file.") - kill_exist_service(port) - # delete original .promptflow/pfs.port - (HOME_PROMPT_FLOW_DIR / PF_SERVICE_PORT_FILE).unlink() - - def dump_port_to_config(port): - # Set port to ~/.promptflow/pfs/**_pf.port, if already have a port in file , will overwrite it. - port_file_path = get_current_env_pfs_file(PF_SERVICE_PORT_FILE) + if sys.executable.endswith("pfcli.exe"): + port_file_path = HOME_PROMPT_FLOW_DIR / PF_SERVICE_PORT_FILE + port_file_path.touch(mode=read_write_by_user(), exist_ok=True) + else: + # Set port to ~/.promptflow/pfs/**_pf.port, if already have a port in file , will overwrite it. + port_file_path = get_current_env_pfs_file(PF_SERVICE_PORT_FILE) with open(port_file_path, "r", encoding=DEFAULT_ENCODING) as f: service_config = load_yaml(f) or {} with open(port_file_path, "w", encoding=DEFAULT_ENCODING) as f: