pub struct LlmProvider { /* private fields */ }Expand description
The LLM correction provider.
Implementations§
Source§impl LlmProvider
impl LlmProvider
Sourcepub fn from_config(llm: &LlmConfig) -> Result<Self, LlmError>
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.
Sourcepub fn fix_word_in_context(
&self,
sentence: &str,
word: &str,
) -> Result<String, LlmError>
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.
Sourcepub fn rewrite_with_alternatives(
&self,
text: &str,
) -> Result<(String, Vec<WordSuggestions>), LlmError>
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.