Skip to main content

LlamaModel

Struct LlamaModel 

Source
pub struct LlamaModel {
    pub model: NonNull<llama_model>,
    /* private fields */
}

Fields§

§model: NonNull<llama_model>

Implementations§

Source§

impl LlamaModel

Source

pub fn vocab_ptr(&self) -> *const llama_vocab

Source

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.

Source

pub fn tokens( &self, decode_special: bool, ) -> impl Iterator<Item = (LlamaToken, Result<String, TokenToStringError>)> + '_

Source

pub fn token_bos(&self) -> LlamaToken

Source

pub fn token_eos(&self) -> LlamaToken

Source

pub fn token_nl(&self) -> LlamaToken

Source

pub fn is_eog_token(&self, token: &SampledToken) -> bool

Source

pub fn decode_start_token(&self) -> LlamaToken

Source

pub fn token_sep(&self) -> LlamaToken

Source

pub fn str_to_token( &self, str: &str, add_bos: AddBos, ) -> Result<Vec<LlamaToken>, StringToTokenError>

§Errors
  • if str contains a null byte
  • if an integer conversion fails during tokenization
use llama_cpp_bindings::model::LlamaModel;
Source

pub fn token_attr( &self, LlamaToken: LlamaToken, ) -> Result<LlamaTokenAttrs, LlamaTokenAttrsFromIntError>

§Errors

Returns an error if the token type is not known to this library.

Source

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

Source

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
Source

pub fn n_vocab(&self) -> i32

Source

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.

Source

pub fn n_embd(&self) -> c_int

Source

pub fn size(&self) -> u64

Source

pub fn n_params(&self) -> u64

Source

pub fn is_recurrent(&self) -> bool

Source

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.

Source

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.

Source

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.

Source

pub fn is_hybrid(&self) -> bool

Source

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.

Source

pub fn meta_count(&self) -> i32

Source

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.

Source

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.

Source

pub fn rope_type(&self) -> Option<RopeType>

Source

pub fn chat_template( &self, name: Option<&str>, ) -> Result<LlamaChatTemplate, ChatTemplateError>

§Errors
  • If the model has no chat template by that name
§Panics

Panics if the C-returned chat template string contains interior null bytes (should never happen with valid model data).

Source

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).

Source

pub fn lora_adapter_init( &self, path: impl AsRef<Path>, ) -> Result<LlamaLoraAdapter, LlamaLoraAdapterInitError>

§Errors

See LlamaLoraAdapterInitError for more information.

Source

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.

Source

pub fn sampled_token_classifier(&self) -> SampledTokenClassifier<'_>

Source

pub fn streaming_markers( &self, ) -> Result<StreamingMarkers, MarkerDetectionError>

§Errors

Returns MarkerDetectionError when any underlying FFI call fails.

Source

pub fn reasoning_markers( &self, ) -> Result<Option<ReasoningMarkers>, MarkerDetectionError>

§Errors

Returns MarkerDetectionError when the underlying FFI call fails.

Source

pub fn tool_call_markers(&self) -> Option<ToolCallMarkers>

Source

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.

Source

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

Trait Implementations§

Source§

impl Debug for LlamaModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for LlamaModel

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for LlamaModel

Source§

impl Sync for LlamaModel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.