Skip to main content

LlmProvider

Struct LlmProvider 

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

The LLM correction provider.

Implementations§

Source§

impl LlmProvider

Source

pub fn from_config(llm: &LlmConfig) -> Result<Self, LlmError>

Build the provider from the user’s crate::LlmConfig — resolves the backend and reads its API key out of the OS keychain.

§Errors

LlmError::UnsupportedBackend for an unknown backend id (or a custom openai-compatible backend with no base URL set), and LlmError::NoApiKey when a cloud backend has no stored key. See LlmError.

Source

pub fn rewrite(&self, text: &str) -> Result<String, LlmError>

Rewrite text into its corrected form. Returns the corrected string verbatim; callers compare against the input to decide whether an edit is needed.

§Errors

See LlmError.

Source

pub fn fix_word_in_context( &self, sentence: &str, word: &str, ) -> Result<String, LlmError>

Correct a single word using the surrounding sentence as context. The LLM is told to return ONLY the corrected word, not the rest of the sentence — callers splice it back in at the caret. Good for homophones and context-dependent typos where the offline spellbook either can’t see the error (their/there) or picks the wrong nearest neighbor.

§Errors

See LlmError.

Source

pub fn rewrite_with_alternatives( &self, text: &str, ) -> Result<(String, Vec<WordSuggestions>), LlmError>

Correct text AND return ranked alternative spellings for each word the model changed, in one structured (JSON) call — this powers the review popup’s per-word suggestion dropdown. Returns the corrected sentence and the alternatives (best-first, the applied option first).

§Errors

Returns LlmError::Response if the reply isn’t the expected JSON — the daemon falls back to rewrite + offline suggestions, so the dropdown still appears.

Trait Implementations§

Source§

impl Debug for LlmProvider

Source§

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

Formats the value using the given formatter. 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, 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.