@@ -113,7 +113,11 @@ impl LlamaModel {
113
113
/// # Errors
114
114
///
115
115
/// See [`TokenToStringError`] for more information.
116
- pub fn token_to_str ( & self , token : LlamaToken , special : Special ) -> Result < String , TokenToStringError > {
116
+ pub fn token_to_str (
117
+ & self ,
118
+ token : LlamaToken ,
119
+ special : Special ,
120
+ ) -> Result < String , TokenToStringError > {
117
121
self . token_to_str_with_size ( token, 32 , special)
118
122
}
119
123
@@ -122,7 +126,11 @@ impl LlamaModel {
122
126
/// # Errors
123
127
///
124
128
/// See [`TokenToStringError`] for more information.
125
- pub fn token_to_bytes ( & self , token : LlamaToken , special : Special ) -> Result < Vec < u8 > , TokenToStringError > {
129
+ pub fn token_to_bytes (
130
+ & self ,
131
+ token : LlamaToken ,
132
+ special : Special ,
133
+ ) -> Result < Vec < u8 > , TokenToStringError > {
126
134
self . token_to_bytes_with_size ( token, 32 , special)
127
135
}
128
136
@@ -131,9 +139,17 @@ impl LlamaModel {
131
139
/// # Errors
132
140
///
133
141
/// See [`TokenToStringError`] for more information.
134
- pub fn tokens_to_str ( & self , tokens : & [ LlamaToken ] , special : Special ) -> Result < String , TokenToStringError > {
142
+ pub fn tokens_to_str (
143
+ & self ,
144
+ tokens : & [ LlamaToken ] ,
145
+ special : Special ,
146
+ ) -> Result < String , TokenToStringError > {
135
147
let mut builder = String :: with_capacity ( tokens. len ( ) * 4 ) ;
136
- for str in tokens. iter ( ) . copied ( ) . map ( |t| self . token_to_str ( t, special) ) {
148
+ for str in tokens
149
+ . iter ( )
150
+ . copied ( )
151
+ . map ( |t| self . token_to_str ( t, special) )
152
+ {
137
153
builder += & str?;
138
154
}
139
155
Ok ( builder)
@@ -451,12 +467,14 @@ impl LlamaModel {
451
467
content : c. content . as_ptr ( ) ,
452
468
} )
453
469
. collect ( ) ;
470
+
454
471
// Set the tmpl pointer
455
472
let tmpl = tmpl. map ( CString :: new) ;
456
- let tmpl_ptr = match tmpl {
457
- Some ( str) => str?. as_ptr ( ) ,
473
+ let tmpl_ptr = match & tmpl {
474
+ Some ( str) => str. as_ref ( ) . map_err ( |e| e . clone ( ) ) ?. as_ptr ( ) ,
458
475
None => std:: ptr:: null ( ) ,
459
476
} ;
477
+
460
478
let formatted_chat = unsafe {
461
479
let res = llama_cpp_sys_2:: llama_chat_apply_template (
462
480
self . model . as_ptr ( ) ,
0 commit comments