- explicit Package manifest with pinned marqdo-ext-http dependency - public ai.infer/classify/select API over ordinary data - layered lib: bytes, strict JSON, contract subset, context, protocol, transport, orchestration - white-box regression entry for internal modules
2.0 KiB
import
| import | ||||
|---|---|---|---|---|
|
@exec methods
便捷函数都复用同一个 infer、同一输出契约、同一预算与错误族;它们不是新的 执行模型,也不读取文档或执行任何内容。
校验标签
params(标签, 名称, 上限)
类别 = 类型(标签)
if 类别 != "List"
return {ok: false, message: 名称 + " 必须是 List"}
end
if 长度(标签) == 0 or 长度(标签) > 上限
return {ok: false, message: 名称 + " 数量超出范围"}
end
下标 = 0
while 下标 < 长度(标签)
if 类型(标签[下标]) != "Text" or 长度(text.codepoints(标签[下标])) == 0
return {ok: false, message: 名称 + " 元素必须是非空 Text"}
end
位置 = 下标 + 1
while 位置 < 长度(标签)
if 标签[位置] == 标签[下标]
return {ok: false, message: 名称 + " 元素不能重复"}
end
位置 = 位置 + 1
end
下标 = 下标 + 1
end
return {ok: true}
分类契约
params(标签)
return {"type": "object", "properties": {"label": {"type": "string", "enum": 标签}}, "required": ["label"], "additionalProperties": false}
选择契约
params(候选)
return {"type": "object", "properties": {"status": {"type": "string", "enum": ["selected", "insufficient", "clarify"]}, "keys": {"type": "array", "items": {"type": "string", "enum": 候选}, "maxItems": 8}, "reason": {"type": "string", "maxLength": 300}}, "required": ["status", "keys", "reason"], "additionalProperties": false}
分类
params(上下文, 输入, 标签, 选项)
检查 = 校验标签(标签, "labels", 64)
if not 检查.ok
return infer.失败("ai.input_invalid", 检查.message)
end
return infer.推理(上下文, 输入, 分类契约(标签), 选项)
选择
params(上下文, 输入, 候选, 选项)
检查 = 校验标签(候选, "candidates", 64)
if not 检查.ok
return infer.失败("ai.input_invalid", 检查.message)
end
return infer.推理(上下文, 输入, 选择契约(候选), 选项)