new-block
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNew Block Creation
新块创建
Read first for the full guide.
docs/platform/block-sdk-guide.md请先阅读获取完整指南。
docs/platform/block-sdk-guide.mdSteps
步骤
- Provider config (if external service): create with
_config.pyProviderBuilder - Block file in (from
backend/blocks/):autogpt_platform/backend/- Generate a UUID once with , then hard-code that string as
uuid.uuid4()(IDs must be stable across imports)id - and
Input(BlockSchema)classesOutput(BlockSchema) - that
async def runs output fieldsyield
- Generate a UUID once with
- Files: use with
store_media_file()for outputs"for_block_output" - Test:
poetry run pytest 'backend/blocks/test/test_block.py::test_available_blocks[MyBlock]' -xvs - Format:
poetry run format
- 提供者配置(若对接外部服务):创建包含的
ProviderBuilder文件_config.py - 块文件(位于下的
autogpt_platform/backend/目录中):backend/blocks/- 使用生成一个UUID,然后将该字符串硬编码为
uuid.uuid4()(ID在导入过程中必须保持稳定)id - 定义和
Input(BlockSchema)类Output(BlockSchema) - 编写方法,通过
async def run返回输出字段yield
- 使用
- 文件处理:对于输出内容,使用带有参数的
"for_block_output"方法store_media_file() - 测试:执行进行测试
poetry run pytest 'backend/blocks/test/test_block.py::test_available_blocks[MyBlock]' -xvs - 格式化:执行格式化代码
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 outputs
for_block_output
- 分析接口:输入/输出能否与图中的其他块良好衔接?
- 使用顶层导入,避免鸭子类型
- 块输出务必使用参数
for_block_output