new-block

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

New Block Creation

新块创建

Read
docs/platform/block-sdk-guide.md
first for the full guide.
请先阅读
docs/platform/block-sdk-guide.md
获取完整指南。

Steps

步骤

  1. Provider config (if external service): create
    _config.py
    with
    ProviderBuilder
  2. Block file in
    backend/blocks/
    (from
    autogpt_platform/backend/
    ):
    • Generate a UUID once with
      uuid.uuid4()
      , then hard-code that string as
      id
      (IDs must be stable across imports)
    • Input(BlockSchema)
      and
      Output(BlockSchema)
      classes
    • async def run
      that
      yield
      s output fields
  3. Files: use
    store_media_file()
    with
    "for_block_output"
    for outputs
  4. Test:
    poetry run pytest 'backend/blocks/test/test_block.py::test_available_blocks[MyBlock]' -xvs
  5. Format:
    poetry run format
  1. 提供者配置(若对接外部服务):创建包含
    ProviderBuilder
    _config.py
    文件
  2. 块文件(位于
    autogpt_platform/backend/
    下的
    backend/blocks/
    目录中):
    • 使用
      uuid.uuid4()
      生成一个UUID,然后将该字符串硬编码
      id
      (ID在导入过程中必须保持稳定)
    • 定义
      Input(BlockSchema)
      Output(BlockSchema)
    • 编写
      async def run
      方法,通过
      yield
      返回输出字段
  3. 文件处理:对于输出内容,使用带有
    "for_block_output"
    参数的
    store_media_file()
    方法
  4. 测试:执行
    poetry run pytest 'backend/blocks/test/test_block.py::test_available_blocks[MyBlock]' -xvs
    进行测试
  5. 格式化:执行
    poetry run format
    格式化代码

Rules

规则

  • Analyze interfaces: do inputs/outputs connect well with other blocks in a graph?
  • Use top-level imports, avoid duck typing
  • Always use
    for_block_output
    for block outputs
  • 分析接口:输入/输出能否与图中的其他块良好衔接?
  • 使用顶层导入,避免鸭子类型
  • 块输出务必使用
    for_block_output
    参数