Repository: microsoft/promptflow
File: src/promptflow-evals/promptflow/evals/evaluate/_eval_run.py (Python)

Code before:

from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

from promptflow.evals._version import VERSION
from promptflow._sdk.entities import Run

LOGGER = logging.getLogger(__name__)


# Handle optional import. The azure libraries are only present if
# promptflow-azure is installed.
try:
    from azure.ai.ml.entities._credentials import AccountKeyConfiguration
    from azure.ai.ml.entities._datastore.datastore import Datastore
    from azure.storage.blob import BlobServiceClient
except (ModuleNotFoundError, ImportError):
    # If the above mentioned modules cannot be imported, we are running
    # in local mode and MLClient in the constructor will be None, so
    # we will not arrive to Azure-dependent code.
    LOGGER.warning(
        "azure-ai-ml cannot be imported. "
        "The results will be saved locally, but will not be logged to Azure. "
        "To log results to azure please install promptflow-evals with the command "
        "pip install promptflow-evals[azure]"
        )


@dataclasses.dataclass
class RunInfo:
    """
    A holder for run info, needed for logging.
    """

    run_id: str
    experiment_id: str
    run_name: str

    @staticmethod
    def generate(run_name: Optional[str]) -> 'RunInfo':
        """
        Generate the new RunInfo instance with the RunID and Experiment ID.

        **Note:** This code is used when we are in failed state and cannot get a run.
        :param run_name: The name of a run.
        :type run_name: str
        """
        return RunInfo(
            str(uuid.uuid4()),
            str(uuid.uuid4()),
            run_name or ""

Review comment (suggestion):
Maybe polish the message a little bit:

```suggestion
LOGGER.warning(
    "Could not import azure-ai-ml. Results will be saved locally but not logged to Azure.\n"
    "To log results to Azure, install promptflow-evals with:\n"
    "    \"pip install promptflow-evals[azure]\""
)
```

Code after:
from typing import Any, Dict, Optional, Set
from urllib.parse import urlparse

from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

from promptflow.evals._version import VERSION
from promptflow._sdk.entities import Run

LOGGER = logging.getLogger(__name__)


# Handle optional import. The azure libraries are only present if
# promptflow-azure is installed.
try:
    from azure.ai.ml.entities._credentials import AccountKeyConfiguration
    from azure.ai.ml.entities._datastore.datastore import Datastore
    from azure.storage.blob import BlobServiceClient
except (ModuleNotFoundError, ImportError):
    # If the above mentioned modules cannot be imported, we are running
    # in local mode and MLClient in the constructor will be None, so
    # we will not arrive to Azure-dependent code.

    # We are logging the import failure only if debug logging level is set because:
    # - If the project configuration was not provided this import is not needed.
    # - If the project configuration was provided, the error will be raised by PFClient.
    LOGGER.debug("promptflow.azure is not installed.")


@dataclasses.dataclass
class RunInfo:
    """
    A holder for run info, needed for logging.
    """

    run_id: str
    experiment_id: str
    run_name: str

    @staticmethod
    def generate(run_name: Optional[str]) -> 'RunInfo':
        """
        Generate the new RunInfo instance with the RunID and Experiment ID.

        **Note:** This code is used when we are in failed state and cannot get a run.
        :param run_name: The name of a run.
        :type run_name: str
        """
        return RunInfo(
            str(uuid.uuid4()),
            str(uuid.uuid4()),