promptflow.azure.operations 模块#

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

基类: WorkspaceTelemetryMixin, _ScopeDependentOperations

可以管理流的 FlowOperations。

不应直接实例化此类。相反,您应该创建一个 PFClient 实例,并且此操作作为实例的属性可用。

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

从本地源创建流到远程,或更新现有流的元数据。

更新流

要更新现有流,您只能更新流的显示名称、描述和标签。流名称是一个 GUID,可以通过两种方式找到

  • 在 Azure 中创建流后,可以在打印消息的“name”属性中找到它。

  • 在 Azure 门户中打开流,GUID 位于 URL 中。例如:https://ml.azure.com/prompts/flow/<workspace-id>/<flow-name>/xxx

参数:
  • flow (Union[str, Path, Flow]) – 要创建或更新的流的源。创建流时,填写本地流路径。更新流时,填写具有有效流名称的流对象,请参阅上面关于如何在 Azure 上查找流名称的文档字符串。

  • display_name (str) – 要创建的流的显示名称。如果未指定,则默认为流文件夹名称 + 时间戳。例如:“web-classification-10-27-2023-14-19-10”

  • type (str) – 要创建的流的类型。可以是 [“standard”, “evaluation”, “chat”] 之一。如果未指定,则默认为“standard”。

  • description (str) – 要创建的流的描述。默认为流 yaml 文件中的描述。

  • tags (Dict[str, str]) – 要创建的流的标签。默认为流 yaml 文件中的标签。

get(name: str) Flow#

从 Azure 获取流。

参数:

name (str) – 要获取的流的名称。

返回:

流。

返回类型:

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

从 Azure 列出流。

参数:
  • max_results (int) – 要返回的最大运行数,默认为 50,最大为 100

  • flow_type (Optional[FlowType]) – 流类型,默认为 None,表示所有流类型。其他支持的流类型为 [“standard”, “evaluation”, “chat”]。

  • list_view_type (ListViewType) – 列表视图类型,默认为 ListViewType.ACTIVE_ONLY

  • include_others (bool) – 是否列出远程工作区中其他用户拥有的流,默认为 False

返回:

流列表。

返回类型:

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

基类: WorkspaceTelemetryMixin, _ScopeDependentOperations

可以管理运行的 RunOperations。

不应直接实例化此类。相反,您应该创建一个 PFClient 实例,并且此操作作为实例的属性可用。

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

归档运行。

参数:

run (Union[str, Run]) – 运行名称或运行对象

返回:

运行对象

返回类型:

运行

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

取消运行。

参数:

run (Union[str, Run]) – 运行名称或运行对象

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

创建或更新运行。

参数:

run (Run) – 要创建或更新的运行对象。

返回:

已创建或更新的运行对象。

返回类型:

运行

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

下载运行数据,包括输入、输出、快照和其他运行信息。

注意

下载完成后,您可以使用 pf run create --source <run-info-local-folder> 将此运行注册为本地运行记录,然后您可以使用 pf run show/visualize 等命令检查此运行,就像从本地流创建的运行一样。

参数:
  • run (Union[str, Run]) – 运行名称或运行对象

  • output (Optional[str]) – 输出目录。默认为“~/.promptflow/.runs”文件夹。

  • overwrite (Optional[bool]) – 是否覆盖现有运行文件夹。默认为 False。

返回:

运行目录路径

返回类型:

str

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

获取运行。

参数:

run (Union[str, Run]) – 运行名称

返回:

运行对象

返回类型:

运行

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

从运行中获取详细信息。

注意

如果 all_results 设置为 True,则 max_results 将被覆盖为 sys.maxsize。

参数:
  • run (Union[str, Run]) – 运行名称或运行对象

  • max_results (int) – 返回的最大运行次数,默认为 100

  • all_results (bool) – 是否返回所有结果,默认为 False

抛出:

RunOperationParameterError – 如果 max_results 不是正整数。

返回:

详细信息数据框。

返回类型:

pandas.DataFrame

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

从运行中获取指标。

参数:

run (Union[str, Run]) – 运行或运行对象

返回:

指标

返回类型:

dict

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

列出工作区中的运行。

参数:
  • max_results (int) – 要返回的最大运行数,默认为 50,最大为 100

  • list_view_type (ListViewType) – 列表视图类型,默认为 ListViewType.ACTIVE_ONLY

返回:

运行列表。

返回类型:

List[Run]

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

恢复运行。

参数:

run (Union[str, Run]) – 运行名称或运行对象

返回:

运行对象

返回类型:

运行

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

流式传输运行日志。

参数:
  • run (Union[str, Run]) – 运行名称或运行对象

  • timeout (int) – 如果运行在一段比超时值更长的时间内保持相同状态且未生成新日志,则流操作将中止。默认超时值为 600 秒。

  • raise_on_error (bool) – 如果运行失败或取消,则抛出异常。

返回:

运行对象

返回类型:

运行

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

更新运行。可以更新显示名称、描述或标签。

注意

  • 显示名称和描述是字符串,标签是键值对的字典,键和值也都是字符串。

  • 标签是键值对的字典。更新标签将覆盖现有的键值对,但不会删除现有的键值对。

参数:
  • run (Union[str, Run]) – 运行名称或运行对象

  • display_name (Optional[str]) – 显示名称

  • description (Optional[str]) – 描述

  • tags (Optional[Dict[str, str]]) – 标签

抛出:

UpdateRunError – 如果未提供或提供了错误类型的值来更新运行。

返回:

运行对象

返回类型:

Optional[Run]

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

使用 Azure AI 门户可视化运行。

参数:

runs (Union[str, Run, List[str], List[Run]]) – 运行名称或运行对象列表。