返回顶部
b

baml-codegenBAML代码生成

Use when generating BAML code for type-safe LLM extraction, classification, RAG, or agent workflows - creates complete .baml files with types, functions, clients, tests, and framework integrations from natural language requirements. Queries official BoundaryML repositories via MCP for real-time patterns. Supports multimodal inputs (images, audio), Python/TypeScript/Ruby/Go, 10+ frameworks, 50-70% token optimization, 95%+ compilation success.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 2.0.0
安全检测
已通过
1,363
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

baml-codegen

BAML 代码生成

生成类型安全的LLM提取代码。在创建结构化输出、分类、RAG或智能体工作流时使用。

黄金法则

  • - 切勿编辑 bamlclient/ - 100%自动生成,每次执行 baml-cli generate 时覆盖;检查 bamlsrc/generators.baml 中的 outputtype(python、typescript、ruby、go)
  • 始终编辑 bamlsrc/ - 所有BAML代码的真实来源
  • 修改后运行 baml-cli generate - 为目标语言重新生成类型化客户端代码

核心理念(TL;DR)

  • - 模式即提示词 - 先定义数据模型,编译器注入类型
  • 类型优于字符串 - 使用枚举/类/联合类型,而非字符串解析
  • 模糊解析是BAML的职责 - BAML从混乱的LLM输出中提取有效JSON
  • 转译器而非库 - 编写 .baml → 生成本地代码(Python/TypeScript/Ruby/Go),无运行时依赖
  • 测试驱动提示 - 使用VS Code游乐场或 baml-cli test 进行迭代

工作流

分析 → 模式匹配(MCP)→ 验证 → 生成 → 测试 → 交付
↓ [如有错误] 错误恢复(MCP)→ 重试

BAML语法

元素示例
class Invoice { total float @description(金额) @assert(this > 0) @alias(amt) }
枚举
enum Category { Tech @alias(technology) @description(科技行业), Finance, Other } | | 函数 | function Extract(text: string, img: image?) -> Invoice { client GPT5 prompt #{{ text }} {{ img }} {{ ctx.output_format }}# } | | 客户端 | client GPT5 { provider openai options { model gpt-5 } retry_policy Exponential } | | 回退 | client Resilient { provider fallback options { strategy [FastModel, SlowModel] } } |

类型

  • - 基本类型:string、int、float、bool | 多模态:image、audio
  • 容器:Type[](数组)、Type?(可选)、map(键值对)
  • 复合类型:Type1 | Type2(联合类型)、嵌套类
  • 注解:@description(...)、@assert(condition)、@alias(json_name)、@check(name, condition)

提供商

openai、anthropic、gemini、vertex、bedrock、ollama + 通过 openai-generic 兼容任何OpenAI兼容提供商

模式类别

模式用例模型框架标记
提取非结构化 → 结构化GPT-5fastapi、next.js
分类
分类任务 | GPT-5-mini | any | | RAG | 带引用的回答 | GPT-5 | langgraph | | 智能体 | 多步推理 | GPT-5 | langgraph | | 视觉 | 图像/音频数据提取 | GPT-5-Vision | multimodal |

弹性机制

  • - 重试策略:retrypolicy Exp { maxretries 3 strategy { type exponential_backoff } }
  • 回退客户端:链式模型 [FastCheap, SlowReliable] 实现成本/可靠性权衡

MCP指示器

  • - 从baml-examples找到模式 | 根据BoundaryML/baml验证 | 使用文档修复错误 | MCP不可用,使用回退方案

输出产物

  1. 1. BAML代码 - 完整的 .baml 文件(类型、函数、客户端、重试策略)
  2. 测试 - 100%函数覆盖率的pytest/Jest测试
  3. 集成 - 框架特定的客户端代码(LangGraph节点、FastAPI端点、Next.js API路由)
  4. 元数据 - 使用的模式、token数量、成本估算

参考文档

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 baml-codegen-1776353352 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 baml-codegen-1776353352 技能

通过命令行安装

skillhub install baml-codegen-1776353352

下载

⬇ 下载 baml-codegen v2.0.0(免费)

文件大小: 60.53 KB | 发布时间: 2026-4-17 14:28

v2.0.0 最新 2026-4-17 14:28
From Foundry: Use when generating BAML code for type-safe LLM extraction, classification, RAG,

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部