ContentTags serde-serialisable. CONTENT_TAGS_SYSTEM is the system message rendered at extraction time; INTENT_CLOSED_SET is the single source of truth for the enum values the grammar restricts. Grammar is strict: lowercase hyphen-joined topic 3+ chars (max enforced by max_tokens at call site), intent from the closed set, JSON-only output. Recursive topic-rest matches the existing GBNF style in this file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
1.6 KiB
Rust
40 lines
1.6 KiB
Rust
// Phase 9 content-tag extraction. Restricts the model output to a
|
|
// strict {topic, intent} JSON object where topic is a lowercase
|
|
// hyphen-joined slug of at least 3 chars (no upper bound is encoded
|
|
// in the grammar — max_tokens caps it in practice) and intent is one
|
|
// of the six closed-set values. Recursive `topic-rest` keeps the
|
|
// shape compatible with the existing GBNF style in this file.
|
|
pub const CONTENT_TAGS_GRAMMAR: &str = r##"
|
|
root ::= "{" ws "\"topic\":" ws topic-str ws "," ws "\"intent\":" ws intent ws "}" ws
|
|
topic-str ::= "\"" topic-char topic-char topic-char topic-rest "\""
|
|
topic-rest ::= "" | topic-char topic-rest
|
|
topic-char ::= [a-z0-9-]
|
|
intent ::= "\"planning\"" | "\"reflection\"" | "\"venting\"" | "\"capture\"" | "\"decision\"" | "\"question\""
|
|
ws ::= ([ \t\n] ws)?
|
|
"##;
|
|
|
|
pub const TASK_ARRAY_GRAMMAR: &str = r#"
|
|
root ::= "[" ws string ws "," ws string ws "," ws string rest3 ws "]"
|
|
rest3 ::= "" | "," ws string rest4
|
|
rest4 ::= "" | "," ws string rest5
|
|
rest5 ::= "" | "," ws string rest6
|
|
rest6 ::= "" | "," ws string
|
|
string ::= "\"" chars "\"" ws
|
|
chars ::= "" | char chars
|
|
char ::= [^"\\\n\r] | "\\" escape
|
|
escape ::= ["\\/bfnrt] | "u" hex hex hex hex
|
|
hex ::= [0-9a-fA-F]
|
|
ws ::= ([ \t\n\r] ws)?
|
|
"#;
|
|
|
|
pub const OPTIONAL_TASK_ARRAY_GRAMMAR: &str = r#"
|
|
root ::= "[" ws "]" | "[" ws string tail ws "]"
|
|
tail ::= "" | "," ws string tail
|
|
string ::= "\"" chars "\"" ws
|
|
chars ::= "" | char chars
|
|
char ::= [^"\\\n\r] | "\\" escape
|
|
escape ::= ["\\/bfnrt] | "u" hex hex hex hex
|
|
hex ::= [0-9a-fA-F]
|
|
ws ::= ([ \t\n\r] ws)?
|
|
"#;
|