Skip to content

Commit 5c8fb8a

Browse files
SystemclusterMarcusDunn
authored andcommitted
Add support for non-u32 enum types generated by bindgen
1 parent ab4da04 commit 5c8fb8a

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

llama-cpp-2/src/grammar.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl ParseState {
269269
rest = r;
270270
rule.push(llama_grammar_element {
271271
type_: llama_cpp_sys_2::LLAMA_GRETYPE_CHAR,
272-
value: c,
272+
value: c as _,
273273
});
274274
}
275275
rest = Self::consume_whitespace_and_comments(&rest[1..], nested);
@@ -292,14 +292,14 @@ impl ParseState {
292292
};
293293
rule.push(llama_grammar_element {
294294
type_: gre_type,
295-
value: c,
295+
value: c as _,
296296
});
297297
if rest.starts_with("-]") {
298298
let (c, r) = Self::parse_char(rest)?;
299299
rest = r;
300300
rule.push(llama_grammar_element {
301301
type_: llama_cpp_sys_2::LLAMA_GRETYPE_CHAR_RNG_UPPER,
302-
value: c,
302+
value: c as _,
303303
});
304304
}
305305
}
@@ -386,7 +386,7 @@ impl ParseState {
386386
error,
387387
})?;
388388

389-
Ok((value, rest))
389+
Ok((value as llama_gretype, rest))
390390
}
391391

392392
fn parse_char(rest: &str) -> Result<(llama_gretype, &str), GrammarParseError> {
@@ -401,17 +401,17 @@ impl ParseState {
401401
'x' => Self::parse_hex(rest, 2),
402402
'u' => Self::parse_hex(rest, 4),
403403
'U' => Self::parse_hex(rest, 8),
404-
't' => Ok((u32::from('\t'), rest)),
405-
'r' => Ok((u32::from('\r'), rest)),
406-
'n' => Ok((u32::from('\n'), rest)),
407-
'\\' => Ok((u32::from('\\'), rest)),
408-
'"' => Ok((u32::from('"'), rest)),
409-
'[' => Ok((u32::from('['), rest)),
410-
']' => Ok((u32::from(']'), rest)),
404+
't' => Ok((u32::from('\t') as llama_gretype, rest)),
405+
'r' => Ok((u32::from('\r') as llama_gretype, rest)),
406+
'n' => Ok((u32::from('\n') as llama_gretype, rest)),
407+
'\\' => Ok((u32::from('\\') as llama_gretype, rest)),
408+
'"' => Ok((u32::from('"') as llama_gretype, rest)),
409+
'[' => Ok((u32::from('[') as llama_gretype, rest)),
410+
']' => Ok((u32::from(']') as llama_gretype, rest)),
411411
c => Err(GrammarParseError::UnknownEscape { escape: c }),
412412
}
413413
} else if let Some(c) = rest.chars().next() {
414-
Ok((u32::from(c), &rest[c.len_utf8()..]))
414+
Ok((u32::from(c) as llama_gretype, &rest[c.len_utf8()..]))
415415
} else {
416416
Err(GrammarParseError::UnexpectedEndOfInput {
417417
parse_stage: "char",

llama-cpp-2/src/model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ impl Drop for LlamaModel {
332332
#[derive(Debug, Eq, Copy, Clone, PartialEq)]
333333
pub enum VocabType {
334334
/// Byte Pair Encoding
335-
BPE = llama_cpp_sys_2::LLAMA_VOCAB_TYPE_BPE,
335+
BPE = llama_cpp_sys_2::LLAMA_VOCAB_TYPE_BPE as _,
336336
/// Sentence Piece Tokenizer
337-
SPM = llama_cpp_sys_2::LLAMA_VOCAB_TYPE_SPM,
337+
SPM = llama_cpp_sys_2::LLAMA_VOCAB_TYPE_SPM as _,
338338
}
339339

340340
/// There was an error converting a `llama_vocab_type` to a `VocabType`.

llama-cpp-2/src/token_type.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
#[allow(clippy::module_name_repetitions)]
77
pub enum LlamaTokenType {
88
/// An undefined token type.
9-
Undefined = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_UNDEFINED,
9+
Undefined = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_UNDEFINED as _,
1010
/// A normal token type.
11-
Normal = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_NORMAL,
11+
Normal = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_NORMAL as _,
1212
/// An unknown token type.
13-
Unknown = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_UNKNOWN,
13+
Unknown = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_UNKNOWN as _,
1414
/// A control token type.
15-
Control = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_CONTROL,
15+
Control = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_CONTROL as _,
1616
/// A user defined token type.
17-
UserDefined = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_USER_DEFINED,
17+
UserDefined = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_USER_DEFINED as _,
1818
/// An unused token type.
19-
Unused = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_UNUSED,
19+
Unused = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_UNUSED as _,
2020
/// A byte token type.
21-
Byte = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_BYTE,
21+
Byte = llama_cpp_sys_2::LLAMA_TOKEN_TYPE_BYTE as _,
2222
}
2323

2424
/// A safe wrapper for converting potentially deceptive `llama_token_type` values into
@@ -52,7 +52,7 @@ impl TryFrom<llama_cpp_sys_2::llama_token_type> for LlamaTokenType {
5252
llama_cpp_sys_2::LLAMA_TOKEN_TYPE_USER_DEFINED => Ok(LlamaTokenType::UserDefined),
5353
llama_cpp_sys_2::LLAMA_TOKEN_TYPE_UNUSED => Ok(LlamaTokenType::Unused),
5454
llama_cpp_sys_2::LLAMA_TOKEN_TYPE_BYTE => Ok(LlamaTokenType::Byte),
55-
_ => Err(LlamaTokenTypeFromIntError::UnknownValue(value)),
55+
_ => Err(LlamaTokenTypeFromIntError::UnknownValue(value as _)),
5656
}
5757
}
5858
}

0 commit comments

Comments
 (0)