Skip to content

Commit 67ea688

Browse files
committed
Test for LlamaSampler::chain_simple
1 parent aeb76dc commit 67ea688

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

llama-cpp-2/src/sampling.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,34 @@ impl LlamaSampler {
8484
}
8585

8686
/// Same as [`Self::chain`] with `no_perf = false`.
87+
///
88+
/// # Example
89+
/// ```rust
90+
/// use llama_cpp_2::token::{
91+
/// LlamaToken,
92+
/// data::LlamaTokenData,
93+
/// data_array::LlamaTokenDataArray
94+
/// };
95+
/// use llama_cpp_2::sampling::LlamaSampler;
96+
///
97+
/// let mut data_array = LlamaTokenDataArray::new(vec![
98+
/// LlamaTokenData::new(LlamaToken(0), 0., 0.),
99+
/// LlamaTokenData::new(LlamaToken(1), 1., 0.),
100+
/// LlamaTokenData::new(LlamaToken(2), 2., 0.),
101+
/// ], false);
102+
///
103+
/// data_array.apply_sampler(&mut LlamaSampler::chain_simple([
104+
/// LlamaSampler::temp(0.5),
105+
/// LlamaSampler::greedy(),
106+
/// ]));
107+
///
108+
/// assert_eq!(data_array.data[0].logit(), 0.);
109+
/// assert_eq!(data_array.data[1].logit(), 2.);
110+
/// assert_eq!(data_array.data[2].logit(), 4.);
111+
///
112+
/// assert_eq!(data_array.data.len(), 3);
113+
/// assert_eq!(data_array.selected_token(), Some(LlamaToken(2)));
114+
/// ```
87115
#[must_use]
88116
pub fn chain_simple(samplers: impl IntoIterator<Item = Self>) -> Self {
89117
Self::chain(samplers, false)

0 commit comments

Comments
 (0)