Skip to content

Commit

Permalink
Update pfazure/pfs version (#2629)
Browse files Browse the repository at this point in the history
# Description
- update pfazure version

![image](https://github.com/microsoft/promptflow/assets/26239730/1a140909-1611-4261-9865-01c3d5c95bff)



- pfs show promptflow version if installed from root, else devkit
version

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.

---------

Co-authored-by: Ying Chen <[email protected]>
  • Loading branch information
YingChen1996 and Ying Chen authored Apr 9, 2024
1 parent 9505d0d commit 0631a9e
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 86 deletions.
32 changes: 4 additions & 28 deletions src/promptflow-azure/promptflow/azure/_cli/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
# pylint: disable=wrong-import-position
import json
import time

from promptflow._cli._pf.help import show_privacy_statement, show_welcome_message
Expand All @@ -17,14 +16,7 @@
import logging # noqa: E402
import sys # noqa: E402

from promptflow._sdk._utils import ( # noqa: E402
get_promptflow_azure_version,
get_promptflow_core_version,
get_promptflow_devkit_version,
get_promptflow_sdk_version,
get_promptflow_tracing_version,
print_pf_version,
)
from promptflow._sdk._utils import print_pf_version, print_promptflow_version_dict_string # noqa: E402
from promptflow._utils.logger_utils import get_cli_sdk_logger # noqa: E402
from promptflow._utils.user_agent_utils import setup_user_agent_to_operation_context # noqa: E402
from promptflow.azure._cli._flow import add_parser_flow, dispatch_flow_commands # noqa: E402
Expand All @@ -47,7 +39,7 @@ def run_command(args):
for handler in logger.handlers:
handler.setLevel(logging.DEBUG)
if args.version:
print_pf_version(with_azure=True)
print_pf_version(with_azure=True, ignore_none=True)
elif args.action == "run":
dispatch_run_commands(args)
elif args.action == "flow":
Expand Down Expand Up @@ -123,24 +115,8 @@ def main():
"""Entrance of pf CLI."""
command_args = sys.argv[1:]
if len(command_args) == 1 and command_args[0] == "version":
version_dict = {"promptflow": get_promptflow_sdk_version()}
# check tracing version
version_tracing = get_promptflow_tracing_version()
if version_tracing:
version_dict["promptflow-tracing"] = version_tracing
# check azure version
version_azure = get_promptflow_azure_version()
if version_azure:
version_dict["promptflow-azure"] = version_azure
# check core version
version_core = get_promptflow_core_version()
if version_core:
version_dict["promptflow-core"] = version_core
# check devkit version
version_devkit = get_promptflow_devkit_version()
if version_devkit:
version_dict["promptflow-devkit"] = version_devkit
return json.dumps(version_dict, ensure_ascii=False, indent=2, sort_keys=True, separators=(",", ": ")) + "\n"
print_promptflow_version_dict_string(with_azure=True, ignore_none=True)
return
if len(command_args) == 0:
# print privacy statement & welcome message like azure-cli
show_privacy_statement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from azure.core.exceptions import HttpResponseError

from promptflow._constants import FlowType as FlowYamlType
from promptflow._proxy import ProxyFactory
from promptflow._sdk._constants import (
CLIENT_FLOW_TYPE_2_SERVICE_FLOW_TYPE,
MAX_LIST_CLI_RESULTS,
Expand Down Expand Up @@ -476,6 +475,8 @@ def _resolve_arm_id_or_upload_dependencies(self, flow: Flow, ignore_tools_json=F

@classmethod
def _try_resolve_code_for_flow(cls, flow: Flow, ops: OperationOrchestrator, ignore_tools_json=False) -> None:
from promptflow._proxy import ProxyFactory

if flow.path:
# remote path
if flow.path.startswith("azureml://datastores"):
Expand Down
4 changes: 3 additions & 1 deletion src/promptflow-core/promptflow/_utils/version_hint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def hint_for_update():
if LATEST_VERSION in cached_versions:
from packaging.version import parse

if parse(cached_versions[CURRENT_VERSION]) < parse(cached_versions[LATEST_VERSION]):
if cached_versions[CURRENT_VERSION] is None or parse(cached_versions[CURRENT_VERSION]) < parse(
cached_versions[LATEST_VERSION]
):
cached_versions[LAST_HINT_TIME] = str(datetime.datetime.now())
message = (
f"New prompt flow version available: promptflow-{cached_versions[LATEST_VERSION]}. Running "
Expand Down
12 changes: 6 additions & 6 deletions src/promptflow-devkit/promptflow/_cli/_pf/_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
check_pfs_service_status,
dump_port_to_config,
get_current_env_pfs_file,
get_pfs_version,
get_port_from_config,
get_started_service_info,
is_port_in_use,
is_run_from_built_binary,
kill_exist_service,
)
from promptflow._sdk._utils import get_promptflow_sdk_version
from promptflow._utils.logger_utils import get_cli_sdk_logger # noqa: E402
from promptflow.exceptions import UserErrorException

Expand Down Expand Up @@ -193,7 +193,7 @@ def validate_port(port, force_start):
app.logger.setLevel(logging.DEBUG)
else:
app.logger.setLevel(logging.INFO)
message = f"Start Prompt Flow Service on {port}, version: {get_promptflow_sdk_version()}."
message = f"Start Prompt Flow Service on {port}, version: {get_pfs_version()}."
app.logger.info(message)
print(message)
sys.stdout.flush()
Expand Down Expand Up @@ -259,20 +259,20 @@ def validate_port(port, force_start):
subprocess.Popen(cmd, stdout=subprocess.DEVNULL, start_new_session=True)
is_healthy = check_pfs_service_status(port)
if is_healthy:
message = f"Start Prompt Flow Service on port {port}, version: {get_promptflow_sdk_version()}."
message = f"Start Promptflow Service on port {port}, version: {get_pfs_version()}."
print(message)
logger.info(message)
else:
logger.warning(f"Pfs service start failed in {port}.")
logger.warning(f"Promptflow service start failed in {port}.")


def stop_service():
port = get_port_from_config()
if port is not None and is_port_in_use(port):
kill_exist_service(port)
message = f"Pfs service stop in {port}."
message = f"Promptflow service stop in {port}."
else:
message = "Pfs service is not started."
message = "Promptflow service is not started."
logger.debug(message)
print(message)

Expand Down
7 changes: 5 additions & 2 deletions src/promptflow-devkit/promptflow/_cli/_pf/_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ def upgrade_version(args):
from packaging.version import parse

from promptflow._constants import _ENV_PF_INSTALLER, CLI_PACKAGE_NAME
from promptflow._sdk._utils import get_promptflow_sdk_version
from promptflow._utils.version_hint_utils import get_latest_version
from promptflow._version import VERSION as local_version

installer = os.getenv(_ENV_PF_INSTALLER) or ""
installer = installer.upper()
print(f"installer: {installer}")
latest_version = get_latest_version(CLI_PACKAGE_NAME, installer=installer)
local_version = get_promptflow_sdk_version()
if not latest_version:
logger.warning("Failed to get the latest prompt flow version.")
return
elif parse(latest_version) <= parse(local_version):
elif local_version and parse(latest_version) <= parse(local_version):
logger.warning("You already have the latest prompt flow version: %s", local_version)
return

Expand Down Expand Up @@ -109,6 +110,8 @@ def upgrade_version(args):
importlib.reload(json)

version_result = subprocess.check_output(["pf", "version"], shell=platform.system() == "Windows")
# Remove ANSI codes which control color and format of text in the console output.
version_result = version_result.decode().replace("\x1b[0m", "").strip()
version_json = json.loads(version_result)
new_version = version_json["promptflow"]

Expand Down
28 changes: 2 additions & 26 deletions src/promptflow-devkit/promptflow/_cli/_pf/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
# pylint: disable=wrong-import-position
import json
import time

from promptflow._cli._pf._experiment import add_experiment_parser, dispatch_experiment_commands
Expand All @@ -28,13 +27,7 @@
from promptflow._cli._pf._upgrade import add_upgrade_parser, upgrade_version # noqa: E402
from promptflow._cli._pf.help import show_privacy_statement, show_welcome_message # noqa: E402
from promptflow._cli._user_agent import USER_AGENT # noqa: E402
from promptflow._sdk._utils import ( # noqa: E402
get_promptflow_core_version,
get_promptflow_devkit_version,
get_promptflow_sdk_version,
get_promptflow_tracing_version,
print_pf_version,
)
from promptflow._sdk._utils import print_pf_version, print_promptflow_version_dict_string # noqa: E402
from promptflow._utils.logger_utils import get_cli_sdk_logger # noqa: E402
from promptflow._utils.user_agent_utils import setup_user_agent_to_operation_context # noqa: E402

Expand Down Expand Up @@ -138,24 +131,7 @@ def main():
"""Entrance of pf CLI."""
command_args = sys.argv[1:]
if len(command_args) == 1 and command_args[0] == "version":
version_dict = {"promptflow": get_promptflow_sdk_version()}
# check tracing version
version_tracing = get_promptflow_tracing_version()
if version_tracing:
version_dict["promptflow-tracing"] = version_tracing
# check core version
version_core = get_promptflow_core_version()
if version_core:
version_dict["promptflow-core"] = version_core
# check devkit version
version_devkit = get_promptflow_devkit_version()
if version_devkit:
version_dict["promptflow-devkit"] = version_devkit

version_dict_string = (
json.dumps(version_dict, ensure_ascii=False, indent=2, sort_keys=True, separators=(",", ": ")) + "\n"
)
print(version_dict_string)
print_promptflow_version_dict_string()
return
if len(command_args) == 0:
# print privacy statement & welcome message like azure-cli
Expand Down
5 changes: 3 additions & 2 deletions src/promptflow-devkit/promptflow/_sdk/_service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@
from promptflow._sdk._service.utils.utils import (
FormattedException,
get_current_env_pfs_file,
get_pfs_version,
get_port_from_config,
is_run_from_built_binary,
kill_exist_service,
)
from promptflow._sdk._utils import get_promptflow_sdk_version, overwrite_null_std_logger, read_write_by_user
from promptflow._sdk._utils import overwrite_null_std_logger, read_write_by_user
from promptflow._utils.thread_utils import ThreadWithContextVars

overwrite_null_std_logger()


def heartbeat():
response = {"promptflow": get_promptflow_sdk_version()}
response = {"promptflow": get_pfs_version()}
return jsonify(response)


Expand Down
19 changes: 15 additions & 4 deletions src/promptflow-devkit/promptflow/_sdk/_service/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
PF_SERVICE_PORT_FILE,
)
from promptflow._sdk._errors import ConnectionNotFoundError, RunNotFoundError
from promptflow._sdk._utils import get_promptflow_sdk_version, read_write_by_user
from promptflow._sdk._utils import get_promptflow_devkit_version, get_promptflow_sdk_version, read_write_by_user
from promptflow._sdk._version import VERSION
from promptflow._utils.logger_utils import get_cli_sdk_logger
from promptflow._utils.yaml_utils import dump_yaml, load_yaml
Expand Down Expand Up @@ -155,6 +155,16 @@ def make_response_no_content():
return make_response("", 204)


def get_pfs_version():
"""Promptflow service show promptflow version if installed from root, else devkit version"""
version_promptflow = get_promptflow_sdk_version()
if version_promptflow:
return version_promptflow
else:
version_devkit = get_promptflow_devkit_version()
return version_devkit


def is_pfs_service_healthy(pfs_port) -> bool:
"""Check if pfs service is running and pfs version matches pf version."""
try:
Expand All @@ -164,15 +174,16 @@ def is_pfs_service_healthy(pfs_port) -> bool:
match = re.search(r'"promptflow":"(.*?)"', response.text)
if match:
version = match.group(1)
is_healthy = version == get_promptflow_sdk_version()
local_version = get_pfs_version()
is_healthy = version == local_version
if not is_healthy:
logger.warning(
f"Promptflow service is running on port {pfs_port}, but the version is not the same as "
f"promptflow sdk version {get_promptflow_sdk_version()}. The service version is {version}."
f"local sdk version {local_version}. The service version is {version}."
)
else:
is_healthy = False
logger.warning("/heartbeat response doesn't contain current pfs version.")
logger.warning("/heartbeat response doesn't contain current promptflow service version.")
return is_healthy
except Exception: # pylint: disable=broad-except
pass
Expand Down
37 changes: 25 additions & 12 deletions src/promptflow-devkit/promptflow/_sdk/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from keyring.errors import NoKeyringError
from marshmallow import ValidationError

import promptflow
from promptflow._constants import ENABLE_MULTI_CONTAINER_KEY, EXTENSION_UA, FLOW_DAG_YAML, FlowLanguage
from promptflow._core.entry_meta_generator import generate_flow_meta as _generate_flow_meta
from promptflow._sdk._constants import (
Expand Down Expand Up @@ -327,9 +326,11 @@ def incremental_print(log: str, printed: int, fileout) -> int:

def get_promptflow_sdk_version() -> str:
try:
import promptflow

return promptflow.__version__
except ImportError:
# if promptflow is installed from source, it does not have __version__ attribute
except (ImportError, AttributeError):
# if promptflow is not installed from root, it does not have __version__ attribute
return None


Expand Down Expand Up @@ -369,24 +370,36 @@ def get_promptflow_azure_version() -> Union[str, None]:
return None


def print_pf_version(with_azure: bool = False):
version_promptflow = get_promptflow_sdk_version()
if version_promptflow:
print("promptflow\t\t\t {}".format(version_promptflow))
def print_promptflow_version_dict_string(with_azure: bool = False, ignore_none: bool = False):
version_dict = {"promptflow": get_promptflow_sdk_version()}
# check tracing version
version_tracing = get_promptflow_tracing_version()
if version_tracing:
print("promptflow-tracing\t\t {}".format(version_tracing))
version_dict["promptflow-tracing"] = version_tracing
# check core version
version_core = get_promptflow_core_version()
if version_core:
print("promptflow-core\t\t\t {}".format(version_core))
version_dict["promptflow-core"] = version_core
# check devkit version
version_devkit = get_promptflow_devkit_version()
if version_devkit:
print("promptflow-devkit\t\t {}".format(version_devkit))
version_dict["promptflow-devkit"] = version_devkit

if with_azure:
# check azure version
version_azure = get_promptflow_azure_version()
if version_azure:
print("promptflow-azure\t\t {}".format(version_azure))
print()
version_dict["promptflow-azure"] = version_azure
if ignore_none:
version_dict = {k: v for k, v in version_dict.items() if v is not None}
version_dict_string = (
json.dumps(version_dict, ensure_ascii=False, indent=2, sort_keys=True, separators=(",", ": ")) + "\n"
)
print(version_dict_string)


def print_pf_version(with_azure: bool = False, ignore_none: bool = False):
print_promptflow_version_dict_string(with_azure, ignore_none)
print("Executable '{}'".format(os.path.abspath(sys.executable)))
print("Python ({}) {}".format(platform.system(), sys.version))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TestAzureCli:
def test_pf_azure_version(self, capfd):
run_pf_command("--version")
out, err = capfd.readouterr()
assert "0.0.1\n" in out
assert "0.0.1" in out

def test_run_show(self, mocker: MockFixture, operation_scope_args):
from promptflow.azure.operations._run_operations import RunOperations
Expand Down
2 changes: 1 addition & 1 deletion src/promptflow/tests/sdk_cli_test/e2etests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TestCli:
def test_pf_version(self, capfd):
run_pf_command("--version")
out, _ = capfd.readouterr()
assert "0.0.1\n" in out
assert "0.0.1" in out

def test_basic_flow_run(self, capfd) -> None:
# fetch std out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from promptflow._sdk._utils import get_promptflow_sdk_version
from promptflow._sdk._service.utils.utils import get_pfs_version

from ..utils import PFSOperations

Expand All @@ -17,4 +17,4 @@ def test_heartbeat(self, pfs_op: PFSOperations) -> None:
response_json = response.json
assert isinstance(response_json, dict)
assert "promptflow" in response_json
assert response_json["promptflow"] == get_promptflow_sdk_version()
assert response_json["promptflow"] == get_pfs_version()

0 comments on commit 0631a9e

Please sign in to comment.