Skip to content

Commit

Permalink
Pass subscription/resource_group/workspace settings define in custome…
Browse files Browse the repository at this point in the history
…r folder repo to PF SDK (#3406)

# Description

Pass subscription/resource_group/workspace settings in the config file
to the _retrieve_tool_func_result function call to fix
#2876. There's another PR
to read related files in the vscode extension repo.


![image](https://github.com/microsoft/promptflow/assets/14858674/724d950d-eb24-418b-9b0c-605979c5eb36)


# All Promptflow Contribution checklist:
- [x] **The pull request does not introduce [breaking changes].**
- [x] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [x] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [x] **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
- [x] Title of the pull request is clear and informative.
- [x] 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: Zhongming Lin <zholin@microsoft.com>
  • Loading branch information
linningmii and linzhp committed Jun 14, 2024
1 parent e0a60ef commit 4f542cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/promptflow-devkit/promptflow/_sdk/_utilities/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from inspect import isfunction
from os import PathLike
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union, TypedDict
from urllib.parse import urlparse

import keyring
Expand Down Expand Up @@ -534,11 +534,18 @@ def _generate_tool_meta(
return res


def _retrieve_tool_func_result(func_call_scenario: str, function_config: Dict):
FunctionConfig = TypedDict("FunctionConfig", {
"func_path": str,
"func_kwargs": Dict,
"azureml_workspace": Optional[AzureMLWorkspaceTriad],
}, total=False)


def _retrieve_tool_func_result(func_call_scenario: str, function_config: FunctionConfig):
"""Retrieve tool func result according to func_call_scenario.
:param func_call_scenario: function call scenario
:param function_config: function config in tool meta. Should contain'func_path' and 'func_kwargs'.
:param function_config: function config in tool meta. Should contain 'func_path' and 'func_kwargs'.
:return: func call result according to func_call_scenario.
"""
from promptflow._core.tools_manager import retrieve_tool_func_result
Expand All @@ -550,7 +557,13 @@ def _retrieve_tool_func_result(func_call_scenario: str, function_config: Dict):
# TODO: move this method to a common place.
from promptflow._cli._utils import get_workspace_triad_from_local

workspace_triad = get_workspace_triad_from_local()
azureml_workspace = function_config.get("azureml_workspace", None)
workspace_triad = AzureMLWorkspaceTriad(
subscription_id=azureml_workspace["subscription_id"],
resource_group_name=azureml_workspace["resource_group_name"],
workspace_name=azureml_workspace["workspace_name"]
) if azureml_workspace is not None else get_workspace_triad_from_local()

if workspace_triad.subscription_id and workspace_triad.resource_group_name and workspace_triad.workspace_name:
result = retrieve_tool_func_result(func_call_scenario, func_path, func_kwargs, workspace_triad._asdict())
# if no workspace triple available, just skip.
Expand Down
2 changes: 1 addition & 1 deletion src/promptflow/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ markers = [
omit = [
# omit anything in a _restclient directory anywhere
"*/_restclient/*",
]
]

0 comments on commit 4f542cd

Please sign in to comment.