Skip to content

Commit 44d56af

Browse files
authored
Merge branch 'utilityai:main' into main
2 parents 25cf052 + 648cceb commit 44d56af

File tree

10 files changed

+90
-17
lines changed

10 files changed

+90
-17
lines changed

.github/workflows/llama-cpp-rs-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: Set up Docker Buildx
5252
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb
5353
- name: Build
54-
uses: docker/build-push-action@v5
54+
uses: docker/build-push-action@v6
5555
with:
5656
file: test-build.Dockerfile
5757
target: base-cuda

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ hf-hub = { version = "0.3.2" }
1616
criterion = "0.5.1"
1717
pprof = "0.13.0"
1818
bindgen = "0.69.4"
19-
cc = "1.0.99"
19+
cc = "1.0.100"
2020
anyhow = "1.0.86"
2121
clap = "4.5.4"
2222
encoding_rs = "0.8.34"

embeddings/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "embeddings"
3-
version = "0.1.59"
3+
version = "0.1.61"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
llama-cpp-2 = { path = "../llama-cpp-2", version = "0.1.59" }
9+
llama-cpp-2 = { path = "../llama-cpp-2", version = "0.1.61" }
1010
hf-hub = { workspace = true }
1111
clap = { workspace = true , features = ["derive"] }
1212
anyhow = { workspace = true }

llama-cpp-2/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "llama-cpp-2"
33
description = "llama.cpp bindings for Rust"
4-
version = "0.1.59"
4+
version = "0.1.61"
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
repository = "https://github.com/utilityai/llama-cpp-rs"
@@ -10,7 +10,7 @@ repository = "https://github.com/utilityai/llama-cpp-rs"
1010

1111
[dependencies]
1212
enumflags2 = "0.7.10"
13-
llama-cpp-sys-2 = { path = "../llama-cpp-sys-2", version = "0.1.59" }
13+
llama-cpp-sys-2 = { path = "../llama-cpp-sys-2", version = "0.1.61" }
1414
thiserror = { workspace = true }
1515
tracing = { workspace = true }
1616

llama-cpp-2/src/context/params.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,46 @@ impl LlamaContextParams {
339339
self.context_params.embeddings = embedding;
340340
self
341341
}
342+
343+
/// Set the evaluation callback.
344+
///
345+
/// # Examples
346+
///
347+
/// ```no_run
348+
/// extern "C" fn cb_eval_fn(
349+
/// t: *mut llama_cpp_sys_2::ggml_tensor,
350+
/// ask: bool,
351+
/// user_data: *mut std::ffi::c_void,
352+
/// ) -> bool {
353+
/// false
354+
/// }
355+
///
356+
/// use llama_cpp_2::context::params::LlamaContextParams;
357+
/// let params = LlamaContextParams::default();
358+
/// params.with_cb_eval(Some(cb_eval_fn));
359+
/// ```
360+
pub fn with_cb_eval(
361+
mut self,
362+
cb_eval: llama_cpp_sys_2::ggml_backend_sched_eval_callback,
363+
) -> Self {
364+
self.context_params.cb_eval = cb_eval;
365+
self
366+
}
367+
368+
/// Set the evaluation callback user data.
369+
///
370+
/// # Examples
371+
///
372+
/// ```no_run
373+
/// use llama_cpp_2::context::params::LlamaContextParams;
374+
/// let params = LlamaContextParams::default();
375+
/// let user_data = std::ptr::null_mut();
376+
/// params.with_cb_eval_user_data(user_data);
377+
/// ```
378+
pub fn with_cb_eval_user_data(mut self, cb_eval_user_data: *mut std::ffi::c_void) -> Self {
379+
self.context_params.cb_eval_user_data = cb_eval_user_data;
380+
self
381+
}
342382
}
343383

344384
/// Default parameters for `LlamaContext`. (as defined in llama.cpp by `llama_context_default_params`)

llama-cpp-2/src/grammar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ impl ParseState {
294294
type_: gre_type,
295295
value: c as _,
296296
});
297-
if rest.starts_with("-]") {
298-
let (c, r) = Self::parse_char(rest)?;
297+
if rest.starts_with("-") && rest.get(1..).is_some_and(|r| !r.starts_with("]")) {
298+
let (c, r) = Self::parse_char(&rest[1..])?;
299299
rest = r;
300300
rule.push(llama_grammar_element {
301301
type_: llama_cpp_sys_2::LLAMA_GRETYPE_CHAR_RNG_UPPER,

llama-cpp-2/src/grammar/tests.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,36 @@ fn check_parse_simple() {
5555
parse_state
5656
);
5757
}
58+
59+
#[test]
60+
fn check_parse_char_range() {
61+
let parse_state = ParseState::from_str(r#"root ::= [a-zA-Z]"#).unwrap();
62+
assert_eq!(
63+
ParseState {
64+
symbol_ids: BTreeMap::from([("root".to_string(), 0),]),
65+
rules: vec![vec![
66+
llama_grammar_element {
67+
type_: llama_cpp_sys_2::LLAMA_GRETYPE_CHAR,
68+
value: 'a' as u32
69+
},
70+
llama_grammar_element {
71+
type_: llama_cpp_sys_2::LLAMA_GRETYPE_CHAR_RNG_UPPER,
72+
value: 'z' as u32
73+
},
74+
llama_grammar_element {
75+
type_: llama_cpp_sys_2::LLAMA_GRETYPE_CHAR_ALT,
76+
value: 'A' as u32
77+
},
78+
llama_grammar_element {
79+
type_: llama_cpp_sys_2::LLAMA_GRETYPE_CHAR_RNG_UPPER,
80+
value: 'Z' as u32
81+
},
82+
llama_grammar_element {
83+
type_: llama_cpp_sys_2::LLAMA_GRETYPE_END,
84+
value: 0
85+
}
86+
]]
87+
},
88+
parse_state
89+
);
90+
}

llama-cpp-sys-2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "llama-cpp-sys-2"
33
description = "Low Level Bindings to llama.cpp"
4-
version = "0.1.59"
4+
version = "0.1.61"
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
repository = "https://github.com/utilityai/llama-cpp-rs"

simple/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "simple"
3-
version = "0.1.59"
3+
version = "0.1.61"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
llama-cpp-2 = { path = "../llama-cpp-2", version = "0.1.59" }
9+
llama-cpp-2 = { path = "../llama-cpp-2", version = "0.1.61" }
1010
hf-hub = { workspace = true }
1111
clap = { workspace = true , features = ["derive"] }
1212
anyhow = { workspace = true }

0 commit comments

Comments
 (0)