Skip to content

Commit

Permalink
Fix pf version (#2588)
Browse files Browse the repository at this point in the history
# Description


![image](https://github.com/microsoft/promptflow/assets/2208599/97791a4c-c107-4440-aeaa-86cbb1c148aa)

![image](https://github.com/microsoft/promptflow/assets/2208599/b2604121-6405-4e40-a59b-4b7ee0546165)

Fix tests, user agents.
And change _entities/flow -> _entities/flows for backward compatibility.

Here is the matrix of updated promptflow UAs

* `pf cli`: promptflow-cli/`DEVKIT VERSION`
* `from promptflow.client import PFClient`: promptflow-sdk/`DEVKIT
VERSION`
* `pfazure cli`: promptflow-azure-cli/`AZURE VERSION`
* `from promptflow.azure import PFClient`: promptflow-azure-sdk/`AZURE
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.

---------

Signed-off-by: Brynn Yin <[email protected]>
Co-authored-by: Brynn Yin <[email protected]>
Co-authored-by: Clement Wang <[email protected]>
  • Loading branch information
3 people authored Apr 2, 2024
1 parent 7237647 commit 2771dcf
Show file tree
Hide file tree
Showing 46 changed files with 161 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

VERSION = "0.0.1"
from promptflow.azure._version import VERSION

USER_AGENT = "{}/{}".format("promptflow-azure-cli", VERSION)
2 changes: 1 addition & 1 deletion src/promptflow-azure/promptflow/azure/_cli/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import time

from promptflow._cli._pf.help import show_privacy_statement, show_welcome_message
from promptflow._cli._user_agent import USER_AGENT
from promptflow._cli._utils import _get_cli_activity_name, cli_exception_and_telemetry_handler, get_client_info_for_cli
from promptflow.azure._cli._user_agent import USER_AGENT

# Log the start time
start_time = time.perf_counter()
Expand Down
3 changes: 2 additions & 1 deletion src/promptflow-azure/promptflow/azure/_pf_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from promptflow._sdk._constants import MAX_SHOW_DETAILS_RESULTS
from promptflow._sdk._errors import RunOperationParameterError
from promptflow._sdk._user_agent import USER_AGENT
from promptflow._sdk._utils import generate_yaml_entry
from promptflow._sdk.entities import Run
from promptflow._utils.user_agent_utils import ClientUserAgentUtil, setup_user_agent_to_operation_context
Expand All @@ -22,6 +21,8 @@
from promptflow.azure.operations._trace_operations import TraceOperations
from promptflow.exceptions import UserErrorException

from ._user_agent import USER_AGENT


class PFClient:
"""A client class to interact with Promptflow service.
Expand Down
7 changes: 7 additions & 0 deletions src/promptflow-azure/promptflow/azure/_user_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

from promptflow.azure._version import VERSION

USER_AGENT = "{}/{}".format("promptflow-azure-sdk", VERSION)
9 changes: 9 additions & 0 deletions src/promptflow-azure/promptflow/azure/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

import importlib.metadata

__version__ = importlib.metadata.version("promptflow-azure")

VERSION: str = __version__
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _update_azure_flow(self, flow: Flow, display_name, **kwargs):
@staticmethod
def _validate_flow_creation_parameters(source, flow_display_name=None, flow_type=None, **kwargs):
"""Validate the parameters for flow creation operation."""
from promptflow._sdk.entities._flow import FlexFlow
from promptflow._sdk.entities._flows import FlexFlow
from promptflow.client import load_flow as load_local_flow

# validate the source folder
Expand Down Expand Up @@ -256,7 +256,7 @@ def _validate_flow_creation_parameters(source, flow_display_name=None, flow_type
@staticmethod
def _validate_flow_schema(source, display_name=None, type=None, **kwargs):
"""Validate the flow schema."""
from promptflow._sdk.entities._flow import Flow
from promptflow._sdk.entities._flows import Flow

params_override = copy.deepcopy(kwargs)
if display_name is not None:
Expand Down
4 changes: 4 additions & 0 deletions src/promptflow-core/promptflow/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ class ConnectionProviderConfig:
AZUREML = "azureml"


AZURE_WORKSPACE_REGEX_FORMAT = (
"^azureml:[/]{1,2}subscriptions/([^/]+)/resource(groups|Groups)/([^/]+)"
"(/providers/Microsoft.MachineLearningServices)?/workspaces/([^/]+)$"
)
CONNECTION_DATA_CLASS_KEY = "DATA_CLASS"

FLEX_FLOW_PUBLIC_NAME = "flex"
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def init_from_provider_config(cls, provider_config: str, credential=None):
try:
from promptflow._sdk._connection_provider._local_connection_provider import LocalConnectionProvider
except ImportError as e:
raise MissingRequiredPackage(
message="Please install 'promptflow-devkit' to use local connection."
) from e
raise MissingRequiredPackage(message="Please install 'promptflow' to use local connection.") from e
return LocalConnectionProvider()
if provider_config.startswith(ConnectionProviderConfig.AZUREML):
from promptflow.core._connection_provider._workspace_connection_provider import WorkspaceConnectionProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re

from promptflow._constants import PF_NO_INTERACTIVE_LOGIN
from promptflow._sdk._constants import AZURE_WORKSPACE_REGEX_FORMAT
from promptflow._constants import AZURE_WORKSPACE_REGEX_FORMAT
from promptflow._utils.user_agent_utils import ClientUserAgentUtil
from promptflow.core._errors import MalformedConnectionProviderConfig, MissingRequiredPackage
from promptflow.exceptions import ValidationException
Expand Down
2 changes: 2 additions & 0 deletions src/promptflow-core/promptflow/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
import importlib.metadata

__version__ = importlib.metadata.version("promptflow-core")

VERSION: str = __version__
26 changes: 25 additions & 1 deletion src/promptflow-devkit/promptflow/_cli/_pf/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
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 get_promptflow_sdk_version, print_pf_version # 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._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 @@ -132,6 +139,23 @@ def main():
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

version_dict_string = (
json.dumps(version_dict, ensure_ascii=False, indent=2, sort_keys=True, separators=(",", ": ")) + "\n"
)
Expand Down
2 changes: 1 addition & 1 deletion src/promptflow-devkit/promptflow/_cli/_user_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
from promptflow._version import VERSION
from promptflow._sdk._version import VERSION

USER_AGENT = "{}/{}".format("promptflow-cli", VERSION)
2 changes: 1 addition & 1 deletion src/promptflow-devkit/promptflow/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
set_context,
transpose,
)
from promptflow._version import VERSION
from promptflow._sdk._version import VERSION
from promptflow.core._serving.response_creator import ResponseCreator
from promptflow.core._serving.swagger import generate_swagger
from promptflow.core._serving.utils import (
Expand Down
6 changes: 2 additions & 4 deletions src/promptflow-devkit/promptflow/_sdk/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ConnectionAuthMode,
ConnectionType,
CustomStrongTypeConnectionConfigs,
AZURE_WORKSPACE_REGEX_FORMAT
)

LOGGER_NAME = "promptflow"
Expand Down Expand Up @@ -119,10 +120,7 @@ def _prepare_home_dir() -> Path:
WORKSPACE_LINKED_DATASTORE_NAME = "workspaceblobstore"
LINE_NUMBER = "line_number"
AZUREML_PF_RUN_PROPERTIES_LINEAGE = "azureml.promptflow.input_run_id"
AZURE_WORKSPACE_REGEX_FORMAT = (
"^azureml:[/]{1,2}subscriptions/([^/]+)/resource(groups|Groups)/([^/]+)"
"(/providers/Microsoft.MachineLearningServices)?/workspaces/([^/]+)$"
)
AZURE_WORKSPACE_REGEX_FORMAT = AZURE_WORKSPACE_REGEX_FORMAT
DEFAULT_ENCODING = "utf-8"
LOCAL_STORAGE_BATCH_SIZE = 1
LOCAL_SERVICE_PORT = 5000
Expand Down
4 changes: 2 additions & 2 deletions src/promptflow-devkit/promptflow/_sdk/_load_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .entities import Run
from .entities._connection import CustomConnection, _Connection
from .entities._experiment import Experiment, ExperimentTemplate
from .entities._flow import Flow
from .entities._flows import Flow

logger = get_cli_sdk_logger()

Expand Down Expand Up @@ -79,7 +79,7 @@ def load_flow(
An exception is raised if the file does not exist.
:type source: Union[PathLike, str]
:return: A Flow object
:rtype: ~promptflow._sdk.entities._flow.Flow
:rtype: ~promptflow._sdk.entities._flows.Flow
"""
return Flow.load(source, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion src/promptflow-devkit/promptflow/_sdk/_mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from promptflow._sdk._constants import DAG_FILE_NAME
from promptflow._sdk._orchestrator import remove_additional_includes
from promptflow._sdk._utils import _merge_local_code_and_additional_includes
from promptflow._sdk.entities._flow import Flow
from promptflow._sdk.entities._flows import Flow
from promptflow.core._serving.flow_invoker import FlowInvoker

__all__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from promptflow._constants import FlowLanguage
from promptflow._sdk._constants import ContextAttributeKey, FlowRunProperties
from promptflow._sdk.entities._flow import Flow
from promptflow._sdk.entities._flows import Flow
from promptflow._sdk.entities._run import Run
from promptflow._sdk.operations._local_storage_operations import LocalStorageOperations
from promptflow._utils.context_utils import _change_working_dir
Expand All @@ -23,7 +23,7 @@

from .._configuration import Configuration
from .._load_functions import load_flow
from ..entities._flow import FlexFlow
from ..entities._flows import FlexFlow
from .utils import SubmitterHelper, variant_overwrite_context

logger = LoggerFactory.get_logger(name=__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from promptflow._internal import ConnectionManager
from promptflow._proxy import ProxyFactory
from promptflow._sdk._constants import PROMPT_FLOW_DIR_NAME
from promptflow._sdk.entities._flow import Flow, FlowContext
from promptflow._sdk.entities._flows import Flow, FlowContext
from promptflow._sdk.operations._local_storage_operations import LoggerOperations
from promptflow._utils.async_utils import async_run_allowing_running_loop
from promptflow._utils.context_utils import _change_working_dir
Expand All @@ -30,7 +30,7 @@
from promptflow.storage._run_storage import DefaultRunStorage

from .._configuration import Configuration
from ..entities._flow import FlexFlow
from ..entities._flows import FlexFlow
from .utils import (
SubmitterHelper,
print_chat_output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from promptflow._sdk._errors import InvalidFlowError, RunOperationError
from promptflow._sdk._load_functions import load_flow
from promptflow._sdk._utils import _merge_local_code_and_additional_includes
from promptflow._sdk.entities._flow import FlexFlow, Flow
from promptflow._sdk.entities._flows import FlexFlow, Flow
from promptflow._utils.flow_utils import dump_flow_dag, load_flow_dag
from promptflow._utils.logger_utils import FileHandler, get_cli_sdk_logger
from promptflow.contracts.flow import Flow as ExecutableFlow
Expand Down
2 changes: 1 addition & 1 deletion src/promptflow-devkit/promptflow/_sdk/_pf_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ._user_agent import USER_AGENT
from ._utils import generate_yaml_entry
from .entities import Run
from .entities._flow import FlexFlow
from .entities._flows import FlexFlow
from .operations import RunOperations
from .operations._connection_operations import ConnectionOperations
from .operations._experiment_operations import ExperimentOperations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from promptflow._sdk._utils import get_promptflow_sdk_version, read_write_by_user
from promptflow._utils.logger_utils import get_cli_sdk_logger
from promptflow._utils.yaml_utils import dump_yaml, load_yaml
from promptflow._version import VERSION
from promptflow._sdk._version import VERSION
from promptflow.exceptions import PromptflowException, UserErrorException

logger = get_cli_sdk_logger()
Expand Down
2 changes: 1 addition & 1 deletion src/promptflow-devkit/promptflow/_sdk/_user_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
from promptflow._version import VERSION
from promptflow._sdk._version import VERSION

USER_AGENT = "{}/{}".format("promptflow-sdk", VERSION)
56 changes: 53 additions & 3 deletions src/promptflow-devkit/promptflow/_sdk/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,63 @@ def incremental_print(log: str, printed: int, fileout) -> int:
def get_promptflow_sdk_version() -> str:
try:
return promptflow.__version__
except AttributeError:
except ImportError:
# if promptflow is installed from source, it does not have __version__ attribute
return "0.0.1"
return None


def get_promptflow_tracing_version() -> Union[str, None]:
try:
from promptflow.tracing._version import __version__

return __version__
except ImportError:
return None


def get_promptflow_core_version() -> Union[str, None]:
try:
from promptflow.core._version import __version__

return __version__
except ImportError:
return None


def get_promptflow_devkit_version() -> Union[str, None]:
try:
from promptflow._sdk._version import __version__

return __version__
except ImportError:
return None


def get_promptflow_azure_version() -> Union[str, None]:
try:
from promptflow.azure._version import __version__

return __version__
except ImportError:
return None


def print_pf_version():
print("promptflow\t\t\t {}".format(get_promptflow_sdk_version()))
version_promptflow = get_promptflow_sdk_version()
if version_promptflow:
print("promptflow\t\t\t {}".format(version_promptflow))
version_tracing = get_promptflow_tracing_version()
if version_tracing:
print("promptflow-tracing\t\t {}".format(version_tracing))
version_core = get_promptflow_core_version()
if version_core:
print("promptflow-core\t\t\t {}".format(version_core))
version_devkit = get_promptflow_devkit_version()
if version_devkit:
print("promptflow-devkit\t\t {}".format(version_devkit))
version_azure = get_promptflow_azure_version()
if version_azure:
print("promptflow-azure\t\t {}".format(version_azure))
print()
print("Executable '{}'".format(os.path.abspath(sys.executable)))
print("Python ({}) {}".format(platform.system(), sys.version))
Expand Down
9 changes: 9 additions & 0 deletions src/promptflow-devkit/promptflow/_sdk/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

import importlib.metadata

__version__ = importlib.metadata.version("promptflow-devkit")

VERSION: str = __version__
2 changes: 1 addition & 1 deletion src/promptflow-devkit/promptflow/_sdk/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from ._run import Run
from ._validation import ValidationResult
from ._flow import FlowContext
from ._flows import FlowContext

__all__ = [
# region: Connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from promptflow._sdk._configuration import Configuration
from promptflow._sdk._constants import NODES
from promptflow._sdk.entities import FlowContext
from promptflow._sdk.entities._flow import Flow
from promptflow._sdk.entities._flows import Flow
from promptflow._utils.flow_utils import load_flow_dag, parse_variant
from promptflow._utils.yaml_utils import dump_yaml
from promptflow.contracts.flow import Node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def __call__(self, *args, **kwargs):

def invoke(self, inputs: dict) -> "LineResult":
"""Invoke a flow and get a LineResult object."""
from promptflow._sdk.entities._flow._flow_context_resolver import FlowContextResolver
from promptflow._sdk.entities._flows._flow_context_resolver import FlowContextResolver

invoker = FlowContextResolver.resolve(flow=self)
result = invoker._invoke(
Expand Down
2 changes: 1 addition & 1 deletion src/promptflow-devkit/promptflow/_sdk/entities/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def _flow_type(self) -> str:

from promptflow._constants import FlowType
from promptflow._sdk._load_functions import load_flow
from promptflow._sdk.entities._flow import FlexFlow
from promptflow._sdk.entities._flows import FlexFlow

flow_obj = load_flow(source=self.flow)
if isinstance(flow_obj, FlexFlow):
Expand Down
Loading

0 comments on commit 2771dcf

Please sign in to comment.