Skip to main content

LlmPlugin

Struct LlmPlugin 

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

Plugin that uses a local LLM to augment content at build time.

Implementations§

Source§

impl LlmPlugin

Source

pub const fn new(config: LlmConfig) -> Self

Creates a new LlmPlugin with the given configuration.

§Examples
use ssg::llm::{LlmConfig, LlmPlugin};
use ssg::plugin::Plugin;

let p = LlmPlugin::new(LlmConfig::default());
assert_eq!(p.name(), "llm");
Source§

impl LlmPlugin

Source

pub fn audit_all(content_dir: &Path, target_grade: f64) -> Result<AuditReport>

Audits all Markdown files in a directory for readability.

Returns a structured report with per-file Flesch-Kincaid scores. Does not require an LLM — uses the local ReadabilityAudit engine.

Note: The syllable heuristic is English-only. Non-English content (Bengali, Hindi, Turkish, etc.) produces inflated scores. Use the en/ subdirectory for accurate results on multilingual repos, or filter results by locale.

§Examples
use ssg::llm::LlmPlugin;
use tempfile::tempdir;

let dir = tempdir().unwrap();
let report = LlmPlugin::audit_all(dir.path(), 8.0).unwrap();
// Empty dir ⇒ no files audited.
assert_eq!(report.total_files, 0);
Source

pub fn audit_and_fix(content_dir: &Path, config: &LlmConfig) -> Result<usize>

Audits and rewrites failing Markdown files via LLM refinement.

For each file that exceeds target_grade:

  1. Extracts the prose body (strips frontmatter)
  2. Sends it to the LLM with a simplification prompt
  3. If the refined version scores better, writes it back (preserving the original frontmatter)
  4. If dry_run, prints the diff without writing

Returns the number of files rewritten.

§Examples
use ssg::llm::{LlmConfig, LlmPlugin};
use tempfile::tempdir;

let dir = tempdir().unwrap();
// No Ollama reachable ⇒ returns Ok(0) without writing anything.
let cfg = LlmConfig {
    endpoint: "http://127.0.0.1:1".into(),
    ..LlmConfig::default()
};
assert_eq!(LlmPlugin::audit_and_fix(dir.path(), &cfg).unwrap(), 0);
Source

pub fn audit_and_fix_with_report( content_dir: &Path, config: &LlmConfig, ) -> Result<AiFixReport>

Agentic pipeline: audit → diagnose → fix → verify → report.

Like audit_and_fix() but returns a detailed JSON-serialisable report with before/after scores for each file.

§Examples
use ssg::llm::{LlmConfig, LlmPlugin};
use tempfile::tempdir;

let dir = tempdir().unwrap();
let cfg = LlmConfig {
    endpoint: "http://127.0.0.1:1".into(),
    ..LlmConfig::default()
};
let report = LlmPlugin::audit_and_fix_with_report(dir.path(), &cfg).unwrap();
assert_eq!(report.total_fixed, 0);
Source§

impl LlmPlugin

Source

pub fn query(&self, prompt: &str) -> Result<String, SsgError>

Typed entry point for invoking the configured local LLM (issue #520, AC4/AC5).

Unlike the in-tree augmentation helpers which swallow errors and fall back to leaving content untouched, query surfaces transport and protocol failures as typed SsgError variants so external callers (CLI commands, integration tests, custom pipelines) can react appropriately.

§Examples
use ssg::llm::{LlmConfig, LlmPlugin};

// No Ollama running ⇒ deterministic transport error.
let cfg = LlmConfig {
    endpoint: "http://127.0.0.1:1".into(),
    ..LlmConfig::default()
};
let plugin = LlmPlugin::new(cfg);
assert!(plugin.query("hi").is_err());
§Errors

See query_ollama for the exact variants.

Trait Implementations§

Source§

impl Debug for LlmPlugin

Source§

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

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

impl Plugin for LlmPlugin

Source§

fn name(&self) -> &'static str

Returns the unique name of this plugin.
Source§

fn after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>

Called after site compilation completes. Read more
Source§

fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>

Called before site compilation begins. Read more
Source§

fn transform_html( &self, html: &str, _path: &Path, _ctx: &PluginContext, ) -> Result<String, SsgError>

Per-file HTML transform hook — called once per HTML file during the fused transform pass. Read more
Source§

fn has_transform(&self) -> bool

Returns true if this plugin implements transform_html. Override to true to opt in to the fused transform pass.
Source§

fn needs_all_files(&self) -> bool

Returns true if this plugin must always observe the full cache.html_files() list — even during --incremental rebuilds that only invalidated a handful of pages. Read more
Source§

fn on_serve(&self, _ctx: &PluginContext) -> Result<(), SsgError>

Called before the development server starts serving files. 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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