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:
- 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:
- 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:
- 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:
- 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: