image.domain\agent_kit\agent_intent.mbt

79.4% · 27 / 34 points · 79 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

  1. 1///|
  2. 2/// # Agent 意图识别 Agent Intent Recognition
  3. 3///
  4. 4/// 自然语言 → 结构化意图
  5. 5/// 描述 Natural language → structured intent
  6. 6// Agent-Kit 意图类型 — 自然语言操作意图
  7. 7// Intent: 从自然语言查询中提取的操作意图
  8. 8
  9. 9///|
  10. 10/// `#non_exhaustive` 表示未来可能添加新构造器
  11. 11#derive(Eq, @debug.Debug)
  12. 12#non_exhaustive
  13. 13pub(all) enum Intent {
  14. 14 Denoise
  15. 15 EdgeDetect
  16. 16 Blur
  17. 17 Sharpen
  18. 18 Grayscale
  19. 19 Resize(Int32, Int32)
  20. 20 Rotate
  21. 21 FlipH
  22. 22 FlipV
  23. 23 Threshold(Float, Float)
  24. 24 Mask(Float)
  25. 25 Identity
  26. 26}
  27. 27
  28. 28///|
  29. 29pub extend Intent with Eq::{not_equal, equal}
  30. 30
  31. 31///|
  32. 32pub extend Intent with @debug.Debug::{to_repr}
  33. 33
  34. 34///|
  35. 35pub fn Intent::to_string(self : Intent) -> String {
  36. 36● match self {
  37. 37● Denoise => "denoise"
  38. 38● EdgeDetect => "edge_detect"
  39. 39● Blur => "blur"
  40. 40● Sharpen => "sharpen"
  41. 41● Grayscale => "grayscale"
  42. 42○ Resize(_, _) => "resize"
  43. 43● Rotate => "rotate"
  44. 44● FlipH => "flip_horizontal"
  45. 45○ FlipV => "flip_vertical"
  46. 46○ Threshold(_, _) => "threshold"
  47. 47○ Mask(_) => "mask"
  48. 48● Identity => "identity"
  49. 49 }
  50. 50}
  51. 51
  52. 52///|
  53. 53pub fn Intent::keyword(self : Intent) -> Array[String] {
  54. 54● match self {
  55. 55● Denoise => ["denoise", "noise", "clean", "smooth"]
  56. 56● EdgeDetect => ["edge", "edges", "contour", "gradient", "outline"]
  57. 57● Blur => ["blur", "soft", "hazy"]
  58. 58● Sharpen => ["sharpen", "sharp", "crisp", "enhance"]
  59. 59● Grayscale => ["gray", "grayscale", "grey", "monochrome"]
  60. 60○ Resize(_, _) => ["resize", "scale", "shrink", "enlarge"]
  61. 61● Rotate => ["rotate", "turn", "spin"]
  62. 62● FlipH => ["flip", "mirror", "reflect"]
  63. 63● FlipV => ["flip_vertical", "upside_down"]
  64. 64○ Threshold(_, _) => ["threshold", "binarize", "binary"]
  65. 65○ Mask(_) => ["mask", "hide", "select"]
  66. 66● Identity => ["identity", "noop", "pass"]
  67. 67 }
  68. 68}
  69. 69
  70. 70///|
  71. 71pub fn Intent::matches(self : Intent, word : String) -> Bool {
  72. 72● let lowered = word.to_lower()
  73. 73● for kw in self.keyword() {
  74. 74● if lowered.contains(kw) {
  75. 75● return true
  76. 76 }
  77. 77 }
  78. 78 false
  79. 79}