Skip to content

Commit

Permalink
Removing private util depenency (#3121)
Browse files Browse the repository at this point in the history
# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# 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.
  • Loading branch information
singankit authored May 6, 2024
1 parent e53bf7f commit 39abb83
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/promptflow-evals/promptflow/evals/evaluate/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,40 @@
import logging
import json
import os
import re
import tempfile
from collections import namedtuple
from pathlib import Path

import mlflow

from promptflow._sdk._constants import Local2Cloud
from promptflow._sdk._utilities.general_utils import extract_workspace_triad_from_trace_provider
from promptflow._utils.async_utils import async_run_allowing_running_loop
from promptflow.azure.operations._async_run_uploader import AsyncRunUploader

LOGGER = logging.getLogger(__name__)

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

AzureMLWorkspaceTriad = namedtuple("AzureMLWorkspace", ["subscription_id", "resource_group_name", "workspace_name"])


def extract_workspace_triad_from_trace_provider(trace_provider: str):
match = re.match(AZURE_WORKSPACE_REGEX_FORMAT, trace_provider)
if not match or len(match.groups()) != 5:
raise ValueError(
"Malformed trace provider string, expected azureml://subscriptions/<subscription_id>/"
"resourceGroups/<resource_group>/providers/Microsoft.MachineLearningServices/"
f"workspaces/<workspace_name>, got {trace_provider}"
)
subscription_id = match.group(1)
resource_group_name = match.group(3)
workspace_name = match.group(5)
return AzureMLWorkspaceTriad(subscription_id, resource_group_name, workspace_name)


def load_jsonl(path):
with open(path, "r", encoding="utf-8") as f:
Expand Down Expand Up @@ -50,7 +72,6 @@ def _write_properties_to_run_history(properties: dict) -> None:


def _azure_pf_client(trace_destination):
from promptflow._sdk._utilities.general_utils import extract_workspace_triad_from_trace_provider
from promptflow.azure._cli._utils import _get_azure_pf_client

ws_triad = extract_workspace_triad_from_trace_provider(trace_destination)
Expand All @@ -64,8 +85,6 @@ def _azure_pf_client(trace_destination):


def _get_mlflow_tracking_uri(trace_destination):
from promptflow._sdk._utilities.general_utils import extract_workspace_triad_from_trace_provider

azure_pf_client = _azure_pf_client(trace_destination)
ws_triad = extract_workspace_triad_from_trace_provider(trace_destination)

Expand Down

0 comments on commit 39abb83

Please sign in to comment.