Benign rust 286 installs Download

llama-cpp-gbnf 0.19.0

“Standalone, model-free GBNF grammar validator built on llama.cpp's real parser”

Release published within seven daysRust test marker or harness
SHA-25644787177755a2c82f2936d1e6c39ac597b20ecdfbd1d739d7323cb80b1e662f0

Evidence

imports std::ffi::NulError gbnf_validation_error.rs · lines 1–27
1use std::ffi::NulError;
2
3#[derive(Debug, thiserror::Error, PartialEq, Eq)]
⋯7 lines
11 #[error("grammar root name contains an interior NUL byte")]
12 RootContainsNul(#[source] NulError),
13 #[error("grammar has a syntax error and could not be parsed")]
14 SyntaxError,
15 #[error("grammar defines no rules")]
16 EmptyRuleSet,
17 #[error("grammar does not define the root symbol {root:?}")]
18 RootSymbolMissing { root: String },
19 #[error("grammar is left-recursive and cannot be compiled by llama.cpp")]
⋯8 lines
imports std::ffi::c_char validate_gbnf.rs · lines 1–22
1use std::ffi::{CString, c_char};
2use std::ptr;
3
4use llama_cpp_ffi_status::FfiContractError;
5use llama_cpp_ffi_status::FfiStatusError;
6use llama_cpp_ffi_status::read_and_free_cpp_string;
7
8use llama_cpp_bindings_sys::LLAMA_RS_GBNF_VALIDATION_EMPTY_RULE_SET;
9use llama_cpp_bindings_sys::LLAMA_RS_GBNF_VALIDATION_LEFT_RECURSION;
10use llama_cpp_bindings_sys::LLAMA_RS_GBNF_VALIDATION_OK;
11use llama_cpp_bindings_sys::LLAMA_RS_GBNF_VALIDATION_ROOT_SYMBOL_MISSING;
12use llama_cpp_bindings_sys::LLAMA_RS_GBNF_VALIDATION_SYNTAX_ERROR;
13use llama_cpp_bindings_sys::LLAMA_RS_GBNF_VALIDATION_THREW_CXX_EXCEPTION;
14use llama_cpp_bindings_sys::llama_rs_gbnf_validation_status;
15use llama_cpp_bindings_sys::llama_rs_validate_gbnf;
16use llama_cpp_bindings_sys::llama_vocab;
17
18use crate::gbnf_validation_error::GbnfValidationError;
19
20fn validation_status_to_result(
21 status: llama_rs_gbnf_validation_status,
22 root: &str,
Marks text as an agent directive validate_gbnf.rs · lines 60–63
60:43… _EXCEPTION => {
61 let message = unsafe {
62 read_and_free_cpp_string(
63 …
imports super::validate_gbnf validate_gbnf.rs · lines 99–125
99:5… };
100
101 validation_status_to_result(status, root, out_error)
102}
103
104#[cfg(test)]
105mod tests {
106 use std::ffi::CString;
107
108 use llama_cpp_ffi_status::FfiContractError;
109 use llama_cpp_ffi_status::FfiStatusError;
110
111 use super::validate_gbnf;
112 use super::validation_status_to_result;
113 use crate::gbnf_validation_error::GbnfValidationError;
114 use llama_cpp_bindings_sys::LLAMA_RS_GBNF_VALIDATION_THREW_CXX_EXCEPTION;
115
116 #[test]
117 fn valid_grammar_is_accepted() {
118 assert_eq!(
119 validate_gbnf(None, r#"root ::= "yes" | "no""#, "root"),
120 Ok(())
⋯5 lines
assert! macro validate_gbnf.rs · lines 200–206
200:64… ar engine exploded".as_ptr())
201 };
202 assert!(!out_error.is_null());
203
204 assert_eq!(
205 validation_status_to_result(
206 …

No evidence locations were recorded for this file. Raw result

Keyboard shortcuts on this page: j for the next sample, k for the previous one, x to go back to the feed, d to download the original bytes, r to re-queue the sample for analysis.