Manage flows#

This documentation will walk you through how to manage your flow with CLI and SDK on Azure AI. The flow examples in this guide come from examples/flows/standard.

In general:

  • For CLI, you can run pfazure flow --help in the terminal to see help messages.

  • For SDK, you can refer to Promptflow Python Library Reference and check promptflow.azure.PFClient.flows for more flow operations.

Prerequisites

  • Refer to the prerequisites in Quick start.

  • Use the az login command in the command line to log in. This enables promptflow to access your credentials.

Let’s take a look at the following topics:

Create a flow#

To set the target workspace, you can either specify it in the CLI command or set default value in the Azure CLI. You can refer to Quick start for more information.

To create a flow to Azure from local flow directory, you can use

# create the flow 
pfazure flow create --flow <path-to-flow-folder> 

# create the flow with metadata
pfazure flow create --flow <path-to-flow-folder> --set display_name=<display-name> description=<description> tags.key1=value1

After the flow is created successfully, you can see the flow summary in the command line.

img

  1. Import the required libraries

from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential
# azure version promptflow apis
from promptflow.azure import PFClient
  1. Get 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()
  1. Get a handle to the workspace

# Get a handle to workspace
pf = PFClient(
    credential=credential,
    subscription_id="<SUBSCRIPTION_ID>",  # this will look like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    resource_group_name="<RESOURCE_GROUP>",
    workspace_name="<AML_WORKSPACE_NAME>",
)
  1. Create the flow


# specify flow path
flow = "./web-classification"

# create flow to Azure
flow = pf.flows.create_or_update(
    flow=flow,  # path to the flow folder
    display_name="my-web-classification",  # it will be "web-classification-{timestamp}" if not specified
    type="standard",  # it will be "standard" if not specified
)

On Azure portal, you can see the created flow in the flow list.

img

And the flow source folder on file share is Users/<alias>/promptflow/<flow-display-name>:

img

Note that if the flow display name is not specified, it will default to the flow folder name + timestamp. (e.g. web-classification-11-13-2023-14-19-10)

List flows#

List flows with default json format:

pfazure flow list --max-results 1

img

# reuse the pf client created in "create a flow" section
flows = pf.flows.list(max_results=1)