promptflow.operations module#

class promptflow.operations.ConnectionOperations(**kwargs)#

Bases: TelemetryMixin

ConnectionOperations.

create_or_update(connection: Type[_Connection], **kwargs)#

Create or update a connection.

Parameters:

connection (_Connection) – Run object to create or update.

delete(name: str) None#

Delete a connection entity.

Parameters:

name (str) – Name of the connection.

get(name: str, **kwargs) _Connection#

Get a connection entity.

Parameters:

name (str) – Name of the connection.

Returns:

connection object retrieved from the database.

Return type:

_Connection

list(max_results: int = 50, all_results: bool = False) List[_Connection]#

List connections.

Parameters:
  • max_results (int) – Max number of results to return.

  • all_results (bool) – Return all results.

Returns:

List of run objects.

Return type:

List[_Connection]

class promptflow.operations.FlowOperations(client, **kwargs)#

Bases: TelemetryMixin

FlowOperations.

build(flow: Union[str, PathLike], *, output: Union[str, PathLike], format: str = 'docker', variant: str = None, **kwargs)#

Build flow to other format.

Parameters:
  • flow (Union[str, PathLike]) – path to the flow directory or flow dag to export

  • format (str) – export format, support “docker” and “executable” only for now

  • output (Union[str, PathLike]) – output directory

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

Returns:

no return

Return type:

None

infer_signature(entry: Union[Callable, FlexFlow, Flow, Prompty], **kwargs) dict#

Extract signature for a callable class or a function or a flow. Signature indicates the ports of a flex flow using the callable as entry.

For flex flow:

If entry is a callable function, the signature includes inputs and outputs. If entry is a callable class, the signature includes inputs, outputs, and init.

For prompty flow:

The signature includes inputs, outputs, and init. Init refers to PromptyModelConfiguration.

For dag flow:

The signature includes inputs and outputs.

Type of each port is inferred from the type hints of the callable and follows type system of json schema. Given flow accepts json input in batch run and serve, we support only a part of types for those ports. Complicated types must be decorated with dataclasses.dataclass. Errors will be raised if annotated types are not supported.

Parameters:

entry (Callable) – entry of the flow, should be a method name relative to code

Returns:

signature of the flow

Return type:

dict

save(entry: Union[str, Callable], code: Optional[Union[str, PathLike]] = None, path: Optional[Union[str, PathLike]] = None, *, python_requirements_txt: str = None, image: str = None, signature: dict = None, sample: Union[str, PathLike, dict] = None, **kwargs) NoReturn#

Save a callable class or a function as a flex flow.

Parameters:
  • entry (Union[str, Callable]) – entry of the flow. If entry is a string, code will be required and entry should be a method name relative to code, like “module.method”. If entry is a callable class or a function, code must be left None.

  • code (Union[str, PathLike]) – path to the code directory. Will be copied to the target directory. If entry is a callable, code must be left None and the parent directory of the entry source will be used as code.

  • path (Union[str, PathLike]) – target directory to create the flow. If specified, it must be an empty or non-existent directory; if not specified, will update the flow definition yaml file in code.

  • python_requirements_txt (str) – path to the python requirements file. If not specified, will use requirements.txt if existed in code directory.

  • image (str) – image to run the flow. Will use default image if not specified.

  • signature (dict) – signature of the flow, indicates the input and output ports of the flow

  • sample (dict) – sample input data for the flow. Will be used for swagger generation in flow serve.

Returns:

no return

Return type:

None

test(flow: Union[str, PathLike], *, inputs: dict = None, variant: str = None, node: str = None, environment_variables: dict = None, init: Optional[dict] = None, **kwargs) dict#

Test flow or node.

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

  • inputs (dict) – Input data for the flow test

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

  • node (str) – If specified it will only test this node, else it will test the flow.

  • 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.

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

Returns:

The result of flow or node

Return type:

dict

validate(flow: Union[str, PathLike], *, raise_error: bool = False, **kwargs) ValidationResult#

Validate flow.

Parameters:
  • flow (Union[str, PathLike]) – path to the flow directory or flow dag to export

  • raise_error (bool) – whether raise error when validation failed

Returns:

a validation result object

Return type:

ValidationResult

class promptflow.operations.RunOperations(client, **kwargs)#

Bases: TelemetryMixin

RunOperations.

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

Archive a run.

Parameters:

name (str) – Name of the run.

Returns:

archived run object.

Return type:

Run

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

delete(name: str) None#

Delete run permanently. Caution: This operation will delete the run permanently from your local disk. Both run entity and output data will be deleted.

Parameters:

name – run name to delete

Returns:

None

get(name: str) Run#

Get a run entity.

Parameters:

name (str) – Name of the run.

Returns:

run object retrieved from the database.

Return type:

Run

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

Get the details from the run.

Note

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

Parameters:
  • name (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(name: Union[str, Run]) Dict[str, Any]#

Get run metrics.

Parameters:

name (str) – name of the run.

Returns:

Run metrics.

Return type:

Dict[str, Any]

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

List runs.

Parameters:
  • max_results (Optional[int]) – Max number of results to return. Default: MAX_RUN_LIST_RESULTS.

  • list_view_type – View type for including/excluding (for example) archived runs. Default: ACTIVE_ONLY.

Returns:

List of run objects.

Return type:

List[Run]

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

Restore a run.

Parameters:

name (str) – Name of the run.

Returns:

restored run object.

Return type:

Run

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

Stream run logs to the console.

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

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

Returns:

Run object.

Return type:

Run

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

Update run status.

Parameters:
  • name – run name

  • display_name – display name to update

  • description – description to update

  • tags – tags to update

  • kwargs – other fields to update, fields not supported will be directly dropped.

Returns:

updated run object

Return type:

Run

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

Visualize run(s).

Parameters:

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