Spaces:
Runtime error
Runtime error
Upload serving/grammar.gbnf with huggingface_hub
Browse files- serving/grammar.gbnf +44 -0
serving/grammar.gbnf
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GBNF Grammar for AEC AI Reader Output
|
| 2 |
+
# Forces LLM output to be valid JSON in one of 5 schemas
|
| 3 |
+
# Used with llama.cpp --grammar flag for constrained decoding
|
| 4 |
+
|
| 5 |
+
root ::= "{" ws "\"output_type\"" ws ":" ws output-type ws "," ws "\"output\"" ws ":" ws output-body ws "}"
|
| 6 |
+
|
| 7 |
+
output-type ::= "\"tool_call\"" | "\"tool_chain\"" | "\"clarify\"" | "\"refuse\"" | "\"critique\""
|
| 8 |
+
|
| 9 |
+
output-body ::= tool-call-body | tool-chain-body | clarify-body | refuse-body | critique-body
|
| 10 |
+
|
| 11 |
+
# --- tool_call: single tool invocation ---
|
| 12 |
+
tool-call-body ::= "{" ws "\"name\"" ws ":" ws string ws "," ws "\"parameters\"" ws ":" ws object ws "}"
|
| 13 |
+
|
| 14 |
+
# --- tool_chain: array of steps ---
|
| 15 |
+
tool-chain-body ::= "[" ws tool-step (ws "," ws tool-step)* ws "]"
|
| 16 |
+
tool-step ::= "{" ws "\"step\"" ws ":" ws integer ws "," ws "\"tool\"" ws ":" ws string ws "," ws "\"params\"" ws ":" ws object ws step-extras ws "}"
|
| 17 |
+
step-extras ::= ("," ws "\"purpose\"" ws ":" ws string)?
|
| 18 |
+
|
| 19 |
+
# --- clarify: missing params + question ---
|
| 20 |
+
clarify-body ::= "{" ws "\"missing_parameters\"" ws ":" ws string-array ws "," ws "\"pertanyaan\"" ws ":" ws string ws "}"
|
| 21 |
+
|
| 22 |
+
# --- refuse: reason + message ---
|
| 23 |
+
refuse-body ::= "{" ws "\"reason\"" ws ":" ws refuse-reason ws "," ws "\"pesan\"" ws ":" ws string ws "}"
|
| 24 |
+
refuse-reason ::= "\"out_of_scope\"" | "\"tool_limitation\"" | "\"impossible\""
|
| 25 |
+
|
| 26 |
+
# --- critique: problem + suggestion + optional proceed ---
|
| 27 |
+
critique-body ::= "{" ws "\"masalah\"" ws ":" ws string ws "," ws "\"saran\"" ws ":" ws string ws critique-proceed ws "}"
|
| 28 |
+
critique-proceed ::= ("," ws "\"jika_tetap_lanjut\"" ws ":" ws (tool-call-body | "null"))?
|
| 29 |
+
|
| 30 |
+
# --- Primitives ---
|
| 31 |
+
string ::= "\"" ([^"\\] | "\\" .)* "\""
|
| 32 |
+
integer ::= [0-9]+
|
| 33 |
+
number ::= "-"? [0-9]+ ("." [0-9]+)?
|
| 34 |
+
boolean ::= "true" | "false"
|
| 35 |
+
null ::= "null"
|
| 36 |
+
|
| 37 |
+
value ::= string | number | boolean | null | object | array
|
| 38 |
+
object ::= "{" ws (pair (ws "," ws pair)*)? ws "}"
|
| 39 |
+
pair ::= string ws ":" ws value
|
| 40 |
+
array ::= "[" ws (value (ws "," ws value)*)? ws "]"
|
| 41 |
+
string-array ::= "[" ws (string (ws "," ws string)*)? ws "]"
|
| 42 |
+
number-array ::= "[" ws (number (ws "," ws number)*)? ws "]"
|
| 43 |
+
|
| 44 |
+
ws ::= [ \t\n]*
|