image.domain\agent_kit\agent_compiler.mbt
66.7% · 28 / 42 points · 53 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # Agent 编译器 Agent Compiler - 3
/// - 4
/// 意图 → 调用链编译 - 5
/// 描述 Intent → call chain compilation - 6
// Agent-Kit 编译器 — 意图序列 → ImgIR 管道 - 7
// compile: 将意图序列编译为 ImgIR IRPipeline - 8
- 9
///| - 10
pub fn compile(intents : Array[Intent]) -> @imgir.IRPipeline { - 11●
let mut pipeline = @imgir.IRPipeline::new() - 12
for intent in intents { - 13●
pipeline = apply_intent(pipeline, intent) - 14
} - 15
pipeline - 16
} - 17
- 18
///| - 19
fn apply_intent( - 20
pipeline : @imgir.IRPipeline, - 21
intent : Intent, - 22
) -> @imgir.IRPipeline { - 23●
match intent { - 24●
Denoise => pipeline.gaussian_blur(2, 1.0F) - 25●
EdgeDetect => pipeline.to_scalar_field().field_gradient() - 26○
Blur => pipeline.box_blur(2) - 27●
Sharpen => pipeline.sharpen(0.5F) - 28●
Grayscale => pipeline.to_gray() - 29○
Resize(w, h) => pipeline.resize(w, h) - 30●
Rotate => pipeline.rotate_90() - 31●
FlipH => pipeline.flip_h() - 32○
FlipV => pipeline.flip_v() - 33
Threshold(lo, hi) => - 34○
pipeline.to_scalar_field().field_clamp(lo, hi).scalar_field_to_image() - 35○
Mask(t) => pipeline.to_scalar_field().field_mask(t).scalar_field_to_image() - 36●
Identity => pipeline - 37
} - 38
} - 39
- 40
///| - 41
pub fn nl_to_pipeline(query : String) -> @imgir.IRPipeline { - 42●
let intents = nl_parse(query) - 43●
compile(intents) - 44
} - 45
- 46
///| - 47
pub fn nl_to_description(query : String) -> String { - 48●
let intents = nl_parse(query) - 49●
let intent_desc = nl_describe(intents) - 50●
let pipeline = compile(intents) - 51●
let pipeline_desc = @imgir.ir_describe(pipeline) - 52
"intents: \{intent_desc} | pipeline: \{pipeline_desc}" - 53
}