输入输出格式#

实验性功能

这是一个实验性功能,随时可能更改。了解更多

支持的类型#

Promptflow 在流中正式支持以下类型。

  • 输入:基本类型(intfloatboolstr)、dictTypedDictlist

  • 输出:基本类型(intfloatboolstr)、dictTypedDictdataclasslist

  • 初始化:基本类型(intfloatboolstr)、Connection(包括自定义连接)、ModelConfigurationTypedDictlist

如果用户在代码/YAML 中有不支持的类型,将引发验证错误。

YAML 支持#

以下是从 Python 类型到 YAML 类型的映射

Python 类型

YAML 类型

描述

int

int

整型

float

双精度浮点数

双精度浮点型

bool

bool

布尔型

str

字符串

字符串型

列表

列表

列表类型

dict

object

字典类型

TypedDict

object

类型化字典类型

dataclass

object

数据类类型

CustomConnection

连接

连接类型,将特别处理

OpenAIModelConfiguration

OpenAIModelConfiguration

模型配置类型,将特别处理

AzureOpenAIModelConfiguration

AzureOpenAIModelConfiguration

模型配置类型,将特别处理

以下是上述支持类型的 YAML 示例。

inputs:
  int_input:
    type: int
  float_input:
    type: double
  bool_input:
    type: bool
  string_input:
    type: string
  dict_input:
    type: object
  list_input:
    type: list
outputs:
  int_output:
    type: int
  float_output:
    type: double
  bool_output:
    type: bool
  string_output:
    type: string
  dict_output:
    type: object
  list_output:
    type: list
init:
  int_init:
    type: int
  float_init:
    type: double
  bool_init:
    type: bool
  string_init:
    type: string
  open_ai_connection:
    type: OpenAIConnection
  azure_open_ai_connection:
    type: AzureOpenAIConnection
  custom_connection:
    type: CustomConnection
  open_ai_model_config:
    type: OpenAIModelConfiguration
  azure_open_ai_model_config:
    type: AzureOpenAIModelConfiguration

不支持的类型示例#

# using unsupported types in flow will fail with validation error
class MyOwnClass:
  pass

class MyFlow:
    # not supported
    def __init__(self, my_own_obj: MyOwnClass):
        pass

# not supported
def my_flow(my_own_obj: MyOwnClass):
    pass

示例验证错误:“输入‘my_own_obj’是复杂的 Python 类型。请改用字典。”

流式传输#

流式传输在流中受支持,您只需在函数中返回一个生成器类型即可。参考 OpenAI 文档,了解如何使用纯 Python 代码实现:how_to_stream_completions

有关详细信息,请参考此流示例