开发标准流#

通过本文档,你可以学习如何从头开始编写流 YAML 文件来开发标准流。你可以在流 YAML 架构中找到关于流 YAML 架构的更多信息。

流输入数据#

流输入数据是您希望在流中处理的数据。

你可以在流 YAML 文件的 inputs 部分添加流输入。

inputs:
  url:
    type: string
    default: https://www.microsoft.com/en-us/d/xbox-wireless-controller-stellar-shift-special-edition/94fbjc7h0h6h

在创作页面展开“输入”部分时,您可以设置和查看流输入,包括输入架构(名称和类型)和输入值。

flow_input

对于如上截图所示的 Web 分类示例,流输入是字符串类型的 URL。有关 Python 工具中更多输入类型,请参阅输入类型

使用不同工具开发流#

在一个流中,你可以使用不同类型的工具。我们现在支持内置工具,如LLMPythonPrompt,以及第三方工具,如Serp API向量搜索等。

根据需要添加工具#

你可以在流 yaml 的 nodes 部分添加工具节点。例如,下面的 yaml 展示了如何在流中添加一个 Python 工具节点。

nodes:
- name: fetch_text_content_from_url
  type: python
  source:
    type: code
    path: fetch_text_content_from_url.py
  inputs:
    url: ${inputs.url}

通过选择最顶部的工具卡片,您将向流中添加一个新的工具节点。

add_tool

编辑工具#

您只需打开源文件进行编辑即可修改工具。例如,我们提供了以下一个简单的 Python 工具代码。

from promptflow.core import tool

# The inputs section will change based on the arguments of the tool function, after you save the code
# Adding type to arguments and return value will help the system show the types properly
# Please update the function name/signature per need
@tool
def my_python_tool(input1: str) -> str:
  return 'hello ' + input1

我们还提供了以下 LLM 工具提示。

Please summarize the following text in one paragraph. 100 words.
Do not add any information that is not in the text.
Text: {{text}}
Summary:

当新的工具节点添加到流中时,默认情况下它会以随机名称附加在扁平视图的底部。在每个工具节点卡片顶部都有一个工具栏,用于调整工具节点。你可以向上或向下移动它,也可以删除或重命名它。对于 Python 工具节点,你可以通过点击代码文件来编辑工具代码。对于 LLM 工具节点,你可以通过点击提示文件来编辑工具提示并调整连接、API 等输入参数。edit_tool

创建连接#

详情请参阅创建必要的连接

设置流输出#

当流很复杂时,您可以设置流输出并在一个地方检查多个节点的输出,而不是检查每个节点的输出。此外,流输出有助于:

  • 在一个表格中检查批量测试结果。

  • 定义评估接口映射。

  • 设置部署响应架构。

您可以在流 yaml 的 outputs 部分添加流输出。链接方式与 LLM 节点相同,使用${convert_to_dict.output.category}category流输出与上游节点convert_to_dictcategory值链接。

outputs:
  category:
    type: string
    reference: ${convert_to_dict.output.category}
  evidence:
    type: string
    reference: ${convert_to_dict.output.evidence}

首先定义流输出架构,然后从下拉列表中选择您想要设置为流输出的节点。由于convert_to_dict的输出是一个带有两个键:categoryevidence的字典,您需要手动将categoryevidence分别追加到每个键。然后运行流,过一段时间后,您可以在表格中查看流输出。

flow_output