promptflow.azure module#

class promptflow.azure.PFClient(credential: Optional[TokenCredential] = None, subscription_id: Optional[str] = None, resource_group_name: Optional[str] = None, workspace_name: Optional[str] = None, **kwargs)#

Bases: object

A client class to interact with Promptflow service.

Use this client to manage promptflow resources, e.g. runs.

Parameters:
  • credential (TokenCredential) – Credential to use for authentication, optional

  • subscription_id (Optional[str]) – Azure subscription ID, optional for registry assets only, optional

  • resource_group_name (Optional[str]) – Azure resource group, optional for registry assets only, optional

  • workspace_name (Optional[str]) – Workspace to use in the client, optional for non workspace dependent operations only, optional.

  • kwargs (dict) – A dictionary of additional configuration parameters.

property flows#

Return the flow operation object that can manage flows.

classmethod from_config(credential: TokenCredential, *, path: Optional[Union[str, PathLike]] = None, file_name=None, **kwargs) PFClient#

Return a PFClient object connected to Azure Machine Learning workspace.

Reads workspace configuration from a file. Throws an exception if the config file can’t be found.

The method provides a simple way to reuse the same workspace across multiple Python notebooks or projects. Users can save the workspace Azure Resource Manager (ARM) properties using the [workspace.write_config](https://aka.ms/ml-workspace-class) method, and use this method to load the same workspace in different Python notebooks or projects without retyping the workspace ARM properties.

Parameters:
  • credential (TokenCredential) – The credential object for the workspace.

  • path (Union[os.PathLike, str]) – The path to the config file or starting directory to search. The parameter defaults to starting the search in the current directory. optional

  • file_name (str) – Allows overriding the config file name to search for when path is a directory path. (Default value = None)

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

Get the details from the run including inputs and outputs.

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]) dict#

Print run metrics to the console.

Parameters:

run (Union[str, Run]) – Run object or name of the run.

Returns:

The run’s metrics

Return type:

dict

property ml_client#

Return a client to interact with Azure ML services.

run(flow: Optional[Union[str, PathLike]] = None, *, data: Optional[Union[str, PathLike]] = None, run: Optional[Union[str, Run]] = None, column_mapping: Optional[dict] = None, variant: Optional[str] = None, connections: Optional[dict] = None, environment_variables: Optional[dict] = None, name: Optional[str] = None, display_name: Optional[str] = None, tags: Optional[Dict[str, str]] = None, resume_from: Optional[Union[str, Run]] = None, code: Optional[Union[str, PathLike]] = None, init: Optional[dict] = None, **kwargs) Run#

Run flow against provided data or run.

Note

at least one of data or run must be provided.

Data can be local file or remote path. - Example: - data = “path/to/local/file” - data = “azureml:data_name:data_version” - data = “azureml://datastores/datastore_name/path/to/file” - data = “https://example.com/data.jsonl”

Column mapping is a mapping from flow input name to specified values. If specified, the flow will be executed with provided value for specified inputs. The value can be:

  • from data:
    • data.col1

  • from run:
    • run.inputs.col1: if need reference run’s inputs

    • run.output.col1: if need reference run’s outputs

  • Example:
    • {"ground_truth": "${data.answer}", "prediction": "${run.outputs.answer}"}

Parameters:
  • flow (Union[str, PathLike]) – path to flow directory to run evaluation

  • data (Union[str, PathLike]) – pointer to test data (of variant bulk runs) for eval runs

  • run (Union[str, Run]) – flow run id or flow run, keep lineage between current run and variant runs, batch outputs can be referenced as ${run.outputs.col_name} in inputs_mapping

  • column_mapping (dict) – define a data flow logic to map input data.

  • variant (str) – Node & variant name in format of ${node_name.variant_name}, will use default variant if not specified.

  • connections (dict) – Overwrite node level connections with provided value. Example: {"node1": {"connection": "new_connection", "deployment_name": "gpt-35-turbo"}}

  • environment_variables (dict) – Environment variables to set by specifying a property path and value. Example: {"key1": "${my_connection.api_key}", "key2"="value2"} The value reference to connection keys will be resolved to the actual value, and all environment variables specified will be set into os.environ.

  • name (str) – Name of the run.

  • display_name (str) – Display name of the run.

  • tags (Dict[str, str]) – Tags of the run.

  • resume_from (str) – Create run resume from an existing run.

  • code (Union[str, PathLike]) – Path to the code directory to run.

  • init (dict) – Initialization parameters for flex flow, only supported when flow is callable class.

Returns:

flow run info.

Return type:

Run

property runs#

Return the run operation object that can manage runs.

stream(run: Union[str, Run], raise_on_error: bool = True) Run#

Stream run logs to the console.

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

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

Returns:

flow run info.

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

Visualize run(s).

Parameters:

run (Union[str, Run]) – Run object or name of the run.

Subpackages#