promptflow.azure.operations module#

class promptflow.azure.operations.FlowOperations(operation_scope: OperationScope, operation_config: OperationConfig, all_operations: OperationsContainer, credential, service_caller: FlowServiceCaller, workspace: Workspace, **kwargs: Dict)#

Bases: WorkspaceTelemetryMixin, _ScopeDependentOperations

FlowOperations that can manage flows.

You should not instantiate this class directly. Instead, you should create a PFClient instance and this operation is available as the instance’s attribute.

create_or_update(flow: Union[str, Path, Flow], display_name: str = None, type: str = None, **kwargs) Flow#

Create a flow to remote from local source, or update the metadata of an existing flow.

Update a flow

To update an existing flow, you can only update the display name, description, and tags of the flow. The flow name is a guid that can be found from 2 ways:

  • After creating a flow to azure, it can be found in the printed message in “name” attribute.

  • Open a flow in azure portal, the guid is in the url. e.g. https://ml.azure.com/prompts/flow/<workspace-id>/<flow-name>/xxx

Parameters:
  • flow (Union[str, Path, Flow]) – The source of the flow to create or update. When creating a flow, fill with the local flow path. When updating a flow, fill with the flow object with a valid flow name, see above docstring about how to find a flow name on azure.

  • display_name (str) – The display name of the flow to create. Default to be flow folder name + timestamp if not specified. e.g. “web-classification-10-27-2023-14-19-10”

  • type (str) – The type of the flow to create. One of [“standard”, evaluation”, “chat”]. Default to be “standard” if not specified.

  • description (str) – The description of the flow to create. Default to be the description in flow yaml file.

  • tags (Dict[str, str]) – The tags of the flow to create. Default to be the tags in flow yaml file.

get(name: str) Flow#

Get a flow from azure.

Parameters:

name (str) – The name of the flow to get.

Returns:

The flow.

Return type:

Flow

list(max_results: int = 50, flow_type: Optional[FlowType] = None, list_view_type: ListViewType = ListViewType.ACTIVE_ONLY, include_others: bool = False, **kwargs) List[Flow]#

List flows from azure.

Parameters:
  • max_results (int) – The max number of runs to return, defaults to 50, max is 100

  • flow_type (Optional[FlowType]) – The flow type, defaults to None, which means all flow types. Other supported flow types are [“standard”, “evaluation”, “chat”].

  • list_view_type (ListViewType) – The list view type, defaults to ListViewType.ACTIVE_ONLY

  • include_others (bool) – Whether to list flows owned by other users in the remote workspace, defaults to False

Returns:

The list of flows.

Return type:

List[Flow]

class promptflow.azure.operations.RunOperations(operation_scope: OperationScope, operation_config: OperationConfig, all_operations: OperationsContainer, flow_operations: FlowOperations, trace_operations: TraceOperations, credential, service_caller: FlowServiceCaller, workspace: Workspace, **kwargs: Dict)#

Bases: WorkspaceTelemetryMixin, _ScopeDependentOperations

RunOperations that can manage runs.

You should not instantiate this class directly. Instead, you should create an PFClient instance and this operation is available as the instance’s attribute.

archive(run: Union[str, Run]) Run#

Archive a run.

Parameters:

run (Union[str, Run]) – The run name or run object

Returns:

The run object

Return type:

Run

cancel(run: Union[str, Run], **kwargs) None#

Cancel a run.

Parameters:

run (Union[str, Run]) – The run name or run object

create_or_update(run: Run, **kwargs) Run#

Create or update a run.

Parameters:

run (Run) – Run object to create or update.

Returns:

Run object created or updated.

Return type:

Run

download(run: Union[str, Run], output: Optional[Union[str, Path]] = None, overwrite: Optional[bool] = False) str#

Download the data of a run, including input, output, snapshot and other run information.

Note

After the download is finished, you can use pf run create --source <run-info-local-folder> to register this run as a local run record, then you can use commands like pf run show/visualize to inspect the run just like a run that was created from local flow.

Parameters:
  • run (Union[str, Run]) – The run name or run object

  • output (Optional[str]) – The output directory. Default to be default to be “~/.promptflow/.runs” folder.

  • overwrite (Optional[bool]) – Whether to overwrite the existing run folder. Default to be False.

Returns:

The run directory path

Return type:

str

get(run: Union[str, Run], **kwargs) Run#

Get a run.

Parameters:

run (Union[str, Run]) – The run name

Returns:

The run object

Return type:

Run

get_details(run: Union[str, Run], max_results: int = 100, all_results: bool = False, **kwargs) DataFrame#

Get the details from the run.

Note

If all_results is set to True, max_results will be overwritten to sys.maxsize.

Parameters:
  • run (Union[str, Run]) – The run name or run object

  • max_results (int) – The max number of runs to return, defaults to 100

  • all_results (bool) – Whether to return all results, defaults to False

Raises:

RunOperationParameterError – If max_results is not a positive integer.

Returns:

The details data frame.

Return type:

pandas.DataFrame

get_metrics(run: Union[str, Run], **kwargs) dict#

Get the metrics from the run.

Parameters:

run (Union[str, Run]) – The run or the run object

Returns:

The metrics

Return type:

dict

list(max_results: int = 50, list_view_type: ListViewType = ListViewType.ACTIVE_ONLY, **kwargs) List[Run]#

List runs in the workspace.

Parameters:
  • max_results (int) – The max number of runs to return, defaults to 50, max is 100

  • list_view_type (ListViewType) – The list view type, defaults to ListViewType.ACTIVE_ONLY

Returns:

The list of runs.

Return type:

List[Run]

restore(run: Union[str, Run]) Run#

Restore a run.

Parameters:

run (Union[str, Run]) – The run name or run object

Returns:

The run object

Return type:

Run

stream(run: Union[str, Run], raise_on_error: bool = True, timeout: int = 600, **kwargs) Run#

Stream the logs of a run.

Parameters:
  • run (Union[str, Run]) – The run name or run object

  • timeout (int) – If the run stays in the same status and produce no new logs in a period longer than the timeout value, the stream operation will abort. Default timeout value is 600 seconds.

  • raise_on_error (bool) – Raises an exception if a run fails or canceled.

Returns:

The run object

Return type:

Run

update(run: Union[str, Run], display_name: Optional[str] = None, description: Optional[str] = None, tags: Optional[Dict[str, str]] = None) Optional[Run]#

Update a run. May update the display name, description or tags.

Note

  • Display name and description are strings, and tags is a dictionary of key-value pairs, both key and value are also strings.

  • Tags is a dictionary of key-value pairs. Updating tags will overwrite the existing key-value pair, but will not delete the existing key-value pairs.

Parameters:
  • run (Union[str, Run]) – The run name or run object

  • display_name (Optional[str]) – The display name

  • description (Optional[str]) – The description

  • tags (Optional[Dict[str, str]]) – The tags

Raises:

UpdateRunError – If nothing or wrong type values provided to update the run.

Returns:

The run object

Return type:

Optional[Run]

visualize(runs: Union[str, Run, List[str], List[Run]], **kwargs) None#

Visualize run(s) using Azure AI portal.

Parameters:

runs (Union[str, Run, List[str], List[Run]]) – Names of the runs, or list of run objects.