pub struct LlamaModel {
pub model: NonNull<llama_model>,
/* private fields */
}Fields§
§model: NonNull<llama_model>Implementations§
Source§impl LlamaModel
impl LlamaModel
pub fn vocab_ptr(&self) -> *const llama_vocab
Sourcepub fn n_ctx_train(&self) -> Result<u32, TryFromIntError>
pub fn n_ctx_train(&self) -> Result<u32, TryFromIntError>
§Errors
Returns an error if the value returned by llama.cpp does not fit into a u32.
pub fn tokens( &self, decode_special: bool, ) -> impl Iterator<Item = (LlamaToken, Result<String, TokenToStringError>)> + '_
pub fn token_bos(&self) -> LlamaToken
pub fn token_eos(&self) -> LlamaToken
pub fn token_nl(&self) -> LlamaToken
pub fn is_eog_token(&self, token: &SampledToken) -> bool
pub fn decode_start_token(&self) -> LlamaToken
pub fn token_sep(&self) -> LlamaToken
Sourcepub fn str_to_token(
&self,
str: &str,
add_bos: AddBos,
) -> Result<Vec<LlamaToken>, StringToTokenError>
pub fn str_to_token( &self, str: &str, add_bos: AddBos, ) -> Result<Vec<LlamaToken>, StringToTokenError>
Sourcepub fn token_attr(
&self,
LlamaToken: LlamaToken,
) -> Result<LlamaTokenAttrs, LlamaTokenAttrsFromIntError>
pub fn token_attr( &self, LlamaToken: LlamaToken, ) -> Result<LlamaTokenAttrs, LlamaTokenAttrsFromIntError>
§Errors
Returns an error if the token type is not known to this library.
Sourcepub fn token_to_piece(
&self,
token: &SampledToken,
decoder: &mut Decoder,
special: bool,
lstrip: Option<NonZeroU16>,
) -> Result<String, TokenToStringError>
pub fn token_to_piece( &self, token: &SampledToken, decoder: &mut Decoder, special: bool, lstrip: Option<NonZeroU16>, ) -> Result<String, TokenToStringError>
§Errors
-
if the token type is unknown
-
if the returned size from llama.cpp does not fit into a
usize
Sourcepub fn token_to_piece_bytes(
&self,
token: LlamaToken,
buffer_size: usize,
special: bool,
lstrip: Option<NonZeroU16>,
) -> Result<Vec<u8>, TokenToStringError>
pub fn token_to_piece_bytes( &self, token: LlamaToken, buffer_size: usize, special: bool, lstrip: Option<NonZeroU16>, ) -> Result<Vec<u8>, TokenToStringError>
§Errors
- if the token type is unknown
- the resultant token is larger than
buffer_size. - if an integer conversion fails
pub fn n_vocab(&self) -> i32
Sourcepub fn vocab_type(&self) -> Result<VocabType, VocabTypeFromIntError>
pub fn vocab_type(&self) -> Result<VocabType, VocabTypeFromIntError>
§Errors
Returns an error if llama.cpp emits a vocab type that is not known to this library.
pub fn n_embd(&self) -> c_int
pub fn size(&self) -> u64
pub fn n_params(&self) -> u64
pub fn is_recurrent(&self) -> bool
Sourcepub fn n_layer(&self) -> Result<u32, TryFromIntError>
pub fn n_layer(&self) -> Result<u32, TryFromIntError>
§Errors
Returns an error if the layer count returned by llama.cpp does not fit into a u32.
Sourcepub fn n_head(&self) -> Result<u32, TryFromIntError>
pub fn n_head(&self) -> Result<u32, TryFromIntError>
§Errors
Returns an error if the head count returned by llama.cpp does not fit into a u32.
Sourcepub fn n_head_kv(&self) -> Result<u32, TryFromIntError>
pub fn n_head_kv(&self) -> Result<u32, TryFromIntError>
§Errors
Returns an error if the KV head count returned by llama.cpp does not fit into a u32.
pub fn is_hybrid(&self) -> bool
Sourcepub fn meta_val_str(&self, key: &str) -> Result<String, MetaValError>
pub fn meta_val_str(&self, key: &str) -> Result<String, MetaValError>
§Errors
Returns an error if the key is not found or the value is not valid UTF-8.
pub fn meta_count(&self) -> i32
Sourcepub fn meta_key_by_index(&self, index: i32) -> Result<String, MetaValError>
pub fn meta_key_by_index(&self, index: i32) -> Result<String, MetaValError>
§Errors
Returns an error if the index is out of range or the key is not valid UTF-8.
Sourcepub fn meta_val_str_by_index(&self, index: i32) -> Result<String, MetaValError>
pub fn meta_val_str_by_index(&self, index: i32) -> Result<String, MetaValError>
§Errors
Returns an error if the index is out of range or the value is not valid UTF-8.
pub fn rope_type(&self) -> Option<RopeType>
Sourcepub fn chat_template(
&self,
name: Option<&str>,
) -> Result<LlamaChatTemplate, ChatTemplateError>
pub fn chat_template( &self, name: Option<&str>, ) -> Result<LlamaChatTemplate, ChatTemplateError>
Sourcepub fn load_from_file(
_: &LlamaBackend,
path: impl AsRef<Path>,
params: &LlamaModelParams,
) -> Result<Self, LlamaModelLoadError>
pub fn load_from_file( _: &LlamaBackend, path: impl AsRef<Path>, params: &LlamaModelParams, ) -> Result<Self, LlamaModelLoadError>
§Errors
See LlamaModelLoadError for more information.
§Panics
Panics if a valid UTF-8 path somehow contains interior null bytes (should never happen).
Sourcepub fn lora_adapter_init(
&self,
path: impl AsRef<Path>,
) -> Result<LlamaLoraAdapter, LlamaLoraAdapterInitError>
pub fn lora_adapter_init( &self, path: impl AsRef<Path>, ) -> Result<LlamaLoraAdapter, LlamaLoraAdapterInitError>
§Errors
See LlamaLoraAdapterInitError for more information.
Sourcepub fn apply_chat_template(
&self,
tmpl: &LlamaChatTemplate,
chat: &[LlamaChatMessage],
add_ass: bool,
) -> Result<String, ApplyChatTemplateError>
pub fn apply_chat_template( &self, tmpl: &LlamaChatTemplate, chat: &[LlamaChatMessage], add_ass: bool, ) -> Result<String, ApplyChatTemplateError>
§Errors
There are many ways this can fail. See ApplyChatTemplateError for more information.
pub fn sampled_token_classifier(&self) -> SampledTokenClassifier<'_>
Sourcepub fn streaming_markers(
&self,
) -> Result<StreamingMarkers, MarkerDetectionError>
pub fn streaming_markers( &self, ) -> Result<StreamingMarkers, MarkerDetectionError>
§Errors
Returns MarkerDetectionError when any underlying FFI call fails.
Sourcepub fn reasoning_markers(
&self,
) -> Result<Option<ReasoningMarkers>, MarkerDetectionError>
pub fn reasoning_markers( &self, ) -> Result<Option<ReasoningMarkers>, MarkerDetectionError>
§Errors
Returns MarkerDetectionError when the underlying FFI call fails.
pub fn tool_call_markers(&self) -> Option<ToolCallMarkers>
Sourcepub fn parse_chat_message(
&self,
tools_json: &str,
input: &str,
is_partial: bool,
) -> Result<ChatMessageParseOutcome, ParseChatMessageError>
pub fn parse_chat_message( &self, tools_json: &str, input: &str, is_partial: bool, ) -> Result<ChatMessageParseOutcome, ParseChatMessageError>
§Errors
Returns ParseChatMessageError when tools_json is not valid JSON,
the FFI returns a non-OK status other than ParseException, or
accessor strings are not valid UTF-8.
Sourcepub fn diagnose_tool_call_synthetic_renders(
&self,
) -> Result<(String, String), MarkerDetectionError>
pub fn diagnose_tool_call_synthetic_renders( &self, ) -> Result<(String, String), MarkerDetectionError>
§Errors
Returns MarkerDetectionError when the C++ analyzer throws or the FFI
returns a non-OK status.
Source§impl LlamaModel
impl LlamaModel
pub fn approximate_tok_env(&self) -> Arc<ApproximateTokEnv>
Trait Implementations§
Source§impl Debug for LlamaModel
impl Debug for LlamaModel
Source§impl Drop for LlamaModel
impl Drop for LlamaModel
impl Send for LlamaModel
impl Sync for LlamaModel
Auto Trait Implementations§
impl !Freeze for LlamaModel
impl RefUnwindSafe for LlamaModel
impl Unpin for LlamaModel
impl UnsafeUnpin for LlamaModel
impl UnwindSafe for LlamaModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more