Skip to content

Commit

Permalink
handle msi pfs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ying Chen committed Mar 2, 2024
1 parent 1da05a7 commit e88e234
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_msi_installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/promptflow/promptflow/_sdk/_service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 0 additions & 4 deletions src/promptflow/promptflow/_sdk/_service/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
27 changes: 11 additions & 16 deletions src/promptflow/promptflow/_sdk/_service/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit e88e234

Please sign in to comment.