Skip to main content

GgufContext

Struct GgufContext 

Source
pub struct GgufContext { /* private fields */ }
Expand description

A safe wrapper around gguf_context.

Opens a GGUF file and parses only the metadata header; tensor weights are never loaded into memory (no_alloc = true).

Implementations§

Source§

impl GgufContext

Source

pub fn from_file(path: &Path) -> Option<Self>

Open a GGUF file and parse its metadata header.

Returns None if the path contains a null byte, the file does not exist, or the file is not a valid GGUF file.

Source

pub fn n_kv(&self) -> i64

Total number of key-value pairs in the metadata.

Source

pub fn find_key(&self, key: &str) -> i64

Find the index of a key by name. Returns -1 if not found.

Source

pub fn key_at(&self, idx: i64) -> Option<&str>

Return the key name at the given index, or None if out of range.

Source

pub fn kv_type(&self, idx: i64) -> gguf_type

Return the value type of the KV pair at idx.

Source

pub fn val_u32(&self, idx: i64) -> u32

Read a uint32 value. Panics (inside llama.cpp) if the stored type is not GGUF_TYPE_UINT32 — check kv_type first if unsure.

Source

pub fn val_i32(&self, idx: i64) -> i32

Read an int32 value.

Source

pub fn val_u64(&self, idx: i64) -> u64

Read a uint64 value.

Source

pub fn val_str(&self, idx: i64) -> Option<&str>

Read a string value. Returns None if the pointer is null or not valid UTF-8.

Source

pub fn n_tensors(&self) -> i64

Total number of tensors described in the file.

Trait Implementations§

Source§

impl Debug for GgufContext

Source§

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

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

impl Drop for GgufContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more