pub struct Model { /* private fields */ }Expand description
High-level model wrapper with builder pattern for text generation.
Use this when you need to:
- Generate multiple times with the same model
- Use streaming callbacks
- Maintain conversation history
- Access model metadata
§Example
ⓘ
use oxide_rs::Model;
let mut model = Model::new("model.gguf")?
.with_options(oxide_rs::GenerateOptions {
max_tokens: 256,
temperature: 0.7,
..Default::default()
})
.load()?;
let response = model.generate("Hello!")?;
println!("{}", response);Implementations§
Source§impl Model
impl Model
Sourcepub fn with_options(self, options: GenerateOptions) -> Self
pub fn with_options(self, options: GenerateOptions) -> Self
Sourcepub fn with_tokenizer<P: AsRef<Path>>(self, tokenizer_path: P) -> Self
pub fn with_tokenizer<P: AsRef<Path>>(self, tokenizer_path: P) -> Self
Sourcepub fn generate_stream<F>(
&mut self,
prompt: &str,
callback: F,
) -> Result<String, Box<dyn Error>>
pub fn generate_stream<F>( &mut self, prompt: &str, callback: F, ) -> Result<String, Box<dyn Error>>
Generate text with streaming callback.
Tokens are passed to the callback as they’re generated, enabling real-time output display.
Requires load() to be called first.
§Arguments
prompt- The input promptcallback- Function called for each generated token
§Example
ⓘ
model.generate_stream("Tell me a story", |token| {
print!("{}", token);
})?;Sourcepub fn generate_batch(
&mut self,
prompts: Vec<String>,
) -> Result<Vec<String>, Box<dyn Error>>
pub fn generate_batch( &mut self, prompts: Vec<String>, ) -> Result<Vec<String>, Box<dyn Error>>
Generate text from multiple prompts in batch.
Processes multiple prompts sequentially, sharing the loaded model for efficiency. Each prompt generates independently with its own output.
Requires load() to be called first.
§Arguments
prompts- Vector of input prompts
§Example
ⓘ
let prompts = vec!["Hello!", "How are you?", "What's up?"];
let results = model.generate_batch(prompts)?;
for result in results {
println!("{}", result);
}Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Sourcepub fn metadata(&self) -> Option<&GgufMetadata>
pub fn metadata(&self) -> Option<&GgufMetadata>
Sourcepub fn context_used(&self) -> Option<usize>
pub fn context_used(&self) -> Option<usize>
Sourcepub fn context_limit(&self) -> Option<usize>
pub fn context_limit(&self) -> Option<usize>
Auto Trait Implementations§
impl !Freeze for Model
impl !RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnsafeUnpin for Model
impl !UnwindSafe for Model
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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