Skip to content

Commit dcbcdd6

Browse files
committed
Requested changes
1 parent cf360fc commit dcbcdd6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

llama-cpp-2/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub enum NewLlamaChatMessageError {
219219
#[derive(Debug, thiserror::Error)]
220220
pub enum ApplyChatTemplateError {
221221
/// the buffer was too small.
222-
#[error("The buffer was too small. Please contact a maintainer")]
222+
#[error("The buffer was too small. Please contact a maintainer and we will update it.")]
223223
BuffSizeError,
224224
/// the string contained a null byte and thus could not be converted to a c string.
225225
#[error("{0}")]

llama-cpp-2/src/model.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct LlamaModel {
2626
}
2727

2828
/// A Safe wrapper around `llama_chat_message`
29-
#[derive(Debug)]
29+
#[derive(Debug, Eq, PartialEq, Clone)]
3030
pub struct LlamaChatMessage {
3131
role: CString,
3232
content: CString,
@@ -408,6 +408,8 @@ impl LlamaModel {
408408
/// Apply the models chat template to some messages.
409409
/// See https://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template
410410
///
411+
/// `tmpl` of None means to use the default template provided by llama.cpp for the model
412+
///
411413
/// # Errors
412414
/// There are many ways this can fail. See [`ApplyChatTemplateError`] for more information.
413415
#[tracing::instrument(skip_all)]
@@ -431,7 +433,7 @@ impl LlamaModel {
431433
})
432434
.collect();
433435
// Set the tmpl pointer
434-
let tmpl = tmpl.map(|v| CString::new(v));
436+
let tmpl = tmpl.map(CString::new);
435437
let tmpl_ptr = match tmpl {
436438
Some(str) => str?.as_ptr(),
437439
None => std::ptr::null(),
@@ -446,13 +448,14 @@ impl LlamaModel {
446448
buff.as_mut_ptr(),
447449
buff.len() as i32,
448450
);
449-
// This should never happen
451+
// A buffer twice the size should be sufficient for all models, if this is not the case for a new model, we can increase it
452+
// The error message informs the user to contact a maintainer
450453
if res > buff.len() as i32 {
451454
return Err(ApplyChatTemplateError::BuffSizeError);
452455
}
453456
String::from_utf8(buff.iter().filter(|c| **c > 0).map(|&c| c as u8).collect())
454-
};
455-
Ok(formatted_chat?)
457+
}?;
458+
Ok(formatted_chat)
456459
}
457460
}
458461

0 commit comments

Comments
 (0)