在流中引用外部文件/文件夹#

有时,对于流引用来说,预先存在的代码资产至关重要。在大多数情况下,您可以通过将 Python 包导入流中来实现此目的。但是,如果 Python 包不可用或创建包很麻烦,您仍然可以使用流配置中的额外包含功能引用位于当前流文件夹之外的外部文件或文件夹。

此功能提供了一种高效的机制,可以列出流文件夹之外的相对文件或文件夹路径,将它们无缝集成到您的 flow.dag.yaml 中。例如

additional_includes:
- ../web-classification/classify_with_llm.jinja2
- ../web-classification/convert_to_dict.py
- ../web-classification/fetch_text_content_from_url.py
- ../web-classification/prepare_examples.py
- ../web-classification/summarize_text_content.jinja2
- ../web-classification/summarize_text_content__variant_1.jinja2

您可以将 additional_includes 字段添加到 flow.dag.yaml 中。此字段的值是相对于流文件夹的相对文件/文件夹路径列表。

与工具节点入口的常见定义一样,您可以在 flow.dag.yaml 中仅使用文件名定义工具节点入口,无需再次指定相对路径。例如

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

工具节点“fetch_text_content_from_url”的入口文件“fetch_text_content_from_url.py”位于“../web-classification/fetch_text_content_from_url.py”中,如 additional_includes 字段中指定。这同样适用于“summarize_text_content”工具节点。

注意:

  1. 如果您在 additional_includes 字段中指定的不同文件夹中有两个同名文件,并且文件名也被指定为工具节点的入口,则系统将引用它在 additional_includes 字段中遇到的最后一个文件。

  1. 如果流文件夹中的文件与 additional_includes 字段中指定的文件同名,系统将优先使用 additional_includes 字段中列出的文件。以下面的 YAML 结构为例

additional_includes:
- ../web-classification/prepare_examples.py
- ../tmp/prepare_examples.py
...
nodes:
- name: summarize_text_content
  use_variants: true
- name: prepare_examples
  type: python
  source:
    type: code
    path: prepare_examples.py
  inputs: {}

在这种情况下,系统将使用“../tmp/prepare_examples.py”作为工具节点“prepare_examples”的入口文件。即使流文件夹中存在名为“prepare_examples.py”的文件,系统仍将使用 additional_includes 字段中指定的“../tmp/prepare_examples.py”文件。

提示:额外包含功能可以显著简化您的工作流程,因为它无需手动处理这些引用。

  1. 要亲身体验此功能,请使用我们的示例 flow-with-additional-includes 进行练习。

  2. 您可以了解更多关于 “额外包含”流在转换为云时的操作方式