[BUG] Local execution and Azure execution have different formats for nested init values
Describe the bug When passing a complex object in the init parameters of a flex flow, the type passed to the class is different on local machine (pf run create) and in Azure (pfazure run create).
How To Reproduce the bug Steps to reproduce the behavior, how frequent can you experience the bug:
- Create a flex flow class with an init method that takes a dictionary as an input value. The following will raise an exception with the type of the argument.
class Flow:
def __init__(
self,
string_parameter: str,
dict_parameter={},
):
# NOTE: I am using an exception to easily output data at the flow level
raise Exception(f"Type of string_parameter: {type(string_parameter)}\nType of dict_parameter: {type(dict_parameter)}")
- Define a run.yml file with init values for both of the parameters as follows:
init:
string_parameter: "hello world"
dict_parameter:
foo: "bar"
- Run it locally
pf run create -f <run_yaml_file>.ymland get the following exception:First error message is: Failed to initialize flow entry with '{'string_parameter': 'hello world', 'dict_parameter': {'foo': 'bar'}}', ex:'Type of string_parameter: <class 'str'>\nType of dict_parameter: <class 'ruamel.yaml.comments.CommentedMap'>." - Run it in azure with
pfazure run crate -f <run_yaml_file>.ymland get the following exception:First error message is: Failed to initialize flow entry with '{'string_parameter': 'hello world', 'dict_parameter': {'foo': 'bar'}}', ex:'Type of string_parameter: <class 'str'>\nType of dict_parameter: <class 'str'>."
For the local run, type(dict_parameter)==<class 'ruamel.yaml.comments.CommentedMap'>, while for the run in Azure type(dict_parameter)==<class 'str'>.
In azure the value of dict_parameter is a string serialized python dictionary. In order to parse this, you need to replace ' with " and then json deserialize it, like follows:
if type(dict_parameter) is str:
# convert a str(dict) to a json string
dict_parameter = dict_parameter.replace("'", '"')
dict_parameter = json.loads(dict_parameter)
Expected behavior I would suspect both environments to parse and pass their configuration values the same way. It is a lot easier to handle code wise to have it passed as a dictionary (or yaml commented map). This is how local works and I would suspect Azure version to work the same.
Running Information
macOS 14.6.1 (23G93)
{
"promptflow": "1.13.0",
"promptflow-azure": "1.13.0",
"promptflow-core": "1.13.0",
"promptflow-devkit": "1.13.0",
"promptflow-tracing": "1.13.0"
}
Executable '/**/.venv/bin/python3.11'
Python (Darwin) 3.11.4 (v3.11.4:d2340ef257, Jun 6 2023, 19:15:51) [Clang 13.0.0 (clang-1300.0.29.30)]
Adding to this, this becomes a much bigger deal for some of the helper types of input like "AzureOpenAIModelConfiguration". Where locally you pass the name and it autoresolves into the full connection information, but in Azure it is passed as just a string with the name of the connection.
I then tried to get the connection using the following to no avail
from promptflow.client import PFClient
pf_client = PFClient()
main_connection = pf_client.connections.get(model_config["connection"])
Hi, we're sending this friendly reminder because we haven't heard back from you in 30 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 7 days of this comment, the issue will be automatically closed. Thank you!