File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -278,7 +278,7 @@ impl LlamaSampler {
278
278
/// # Panics
279
279
/// If either of ``grammar_str`` or ``grammar_root`` contain null bytes.
280
280
#[ must_use]
281
- pub fn grammar ( model : & LlamaModel , grammar_str : & str , grammar_root : & str ) -> Self {
281
+ pub fn grammar ( model : & LlamaModel , grammar_str : & str , grammar_root : & str ) -> Option < Self > {
282
282
let grammar_str = CString :: new ( grammar_str) . unwrap ( ) ;
283
283
let grammar_root = CString :: new ( grammar_root) . unwrap ( ) ;
284
284
@@ -289,7 +289,12 @@ impl LlamaSampler {
289
289
grammar_root. as_ptr ( ) ,
290
290
)
291
291
} ;
292
- Self { sampler }
292
+
293
+ if sampler. is_null ( ) {
294
+ None
295
+ } else {
296
+ Some ( Self { sampler } )
297
+ }
293
298
}
294
299
295
300
/// Lazy grammar sampler, introduced in <https://github.com/ggerganov/llama.cpp/pull/9639>
@@ -306,7 +311,7 @@ impl LlamaSampler {
306
311
grammar_root : & str ,
307
312
trigger_words : impl IntoIterator < Item = impl AsRef < [ u8 ] > > ,
308
313
trigger_tokens : & [ LlamaToken ] ,
309
- ) -> Self {
314
+ ) -> Option < Self > {
310
315
let grammar_str = CString :: new ( grammar_str) . unwrap ( ) ;
311
316
let grammar_root = CString :: new ( grammar_root) . unwrap ( ) ;
312
317
@@ -331,9 +336,13 @@ impl LlamaSampler {
331
336
trigger_tokens. len ( ) ,
332
337
)
333
338
} ;
334
-
335
- Self { sampler }
336
- }
339
+
340
+ if sampler. is_null ( ) {
341
+ None
342
+ } else {
343
+ Some ( Self { sampler } )
344
+ }
345
+ }
337
346
338
347
/// DRY sampler, designed by p-e-w, as described in:
339
348
/// <https://github.com/oobabooga/text-generation-webui/pull/5677>, porting Koboldcpp
You can’t perform that action at this time.
0 commit comments