<jupyter_start><jupyter_code># setup pf client and execution path

from promptflow import PFClient
import json
import os

pf = PFClient()

root = os.path.join(os.getcwd(), "../")
flow = os.path.join(root, "maths-to-code")
data = os.path.join(flow, "math_data.jsonl")
eval_flow = os.path.join(root, "../evaluation/eval-accuracy-maths-to-code")
# start batch run of maths-to-code
base_run = pf.run(
    flow = flow, 
    data = data, 
    column_mapping={"math_question": "${data.question}"},
    display_name="maths_to_code_batch_run",
    stream=True
)
# Show output of flow run
pf.get_details(base_run)
# evaluate against the batch run and groundtruth data
eval_run = pf.run(
    flow = eval_flow, 
    data = data, 
    run = base_run,
    column_mapping={"groundtruth": "${data.answer}", "prediction": "${run.outputs.answer}"},
    display_name="maths_to_code_eval_run",
    stream=True
)

pf.get_details(eval_run)
# Get metrics of the evaluation flow run
pf.get_metrics(eval_run)
# Visualize the flow run and evaluation run with HTML
pf.visualize([base_run, eval_run])<jupyter_output><empty_output><jupyter_text>Run on AzureIf you want to run and evaluate your flow on Azure, you can using following example to setup your Azure ML workspace<jupyter_code>from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential

# init credential
try:
    credential = DefaultAzureCredential()
    # Check if given credential can get token successfully.
    credential.get_token("https://management.azure.com/.default")
except Exception as ex:
    # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work
    credential = InteractiveBrowserCredential()
from promptflow.azure import PFClient

try:
    pf = PFClient.from_config(credential=credential)
except Exception as ex:
    # NOTE: Update following workspace information if not correctly configure before
    client_config = {
        "subscription_id": "<SUBSCRIPTION_ID>",
        "resource_group": "<RESOURCE_GROUP>",
        "workspace_name": "<AML_WORKSPACE_NAME>",
    }

    if client_config["subscription_id"].startswith("<"):
        print(
            "please update your <SUBSCRIPTION_ID> <RESOURCE_GROUP> <AML_WORKSPACE_NAME> in notebook cell"
        )
        raise ex
    else:  # write and reload from config file
        import json, os

        config_path = "../.azureml/config.json"
        os.makedirs(os.path.dirname(config_path), exist_ok=True)
        with open(config_path, "w") as fo:
            fo.write(json.dumps(client_config))
        pf = PFClient.from_config(credential=credential, path=config_path)

print(pf)

# NOTE: note that you need to replace <open_ai_connection> and <gpt-35-turbo> with your own connection and deployment name in your Azure Machine Learning workspace
connection_mapping = {"code_gen": {"connection": "<my_azure_open_ai_connection>", "deployment_name": "<gpt-35-turbo>"}}
# batch run of maths to code

base_run = pf.run(
    flow = flow,
    data = data,
    column_mapping = {"math_question": "${data.question}"},
    connections = connection_mapping,
    stream = True,
)
# get output of flow run
pf.get_details(base_run)
# evaluation run against base run

eval_run = pf.run(
    flow = eval_flow, 
    data = data, 
    run = base_run,
    column_mapping={"groundtruth": "${data.answer}", "prediction": "${run.outputs.answer}"},
    stream = True,
)

# get output of evaluation run
pf.get_details(eval_run)
metrics = pf.get_metrics(eval_run)
print(json.dumps(metrics, indent=4))<jupyter_output>{
    "accuracy": 0.9,
    "error_rate": 0.1
}