pub struct LlmPlugin { /* private fields */ }Expand description
Plugin that uses a local LLM to augment content at build time.
Implementations§
Source§impl LlmPlugin
impl LlmPlugin
Sourcepub fn audit_all(content_dir: &Path, target_grade: f64) -> Result<AuditReport>
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);Sourcepub fn audit_and_fix(content_dir: &Path, config: &LlmConfig) -> Result<usize>
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:
- Extracts the prose body (strips frontmatter)
- Sends it to the LLM with a simplification prompt
- If the refined version scores better, writes it back (preserving the original frontmatter)
- 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);Sourcepub fn audit_and_fix_with_report(
content_dir: &Path,
config: &LlmConfig,
) -> Result<AiFixReport>
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
impl LlmPlugin
Sourcepub fn query(&self, prompt: &str) -> Result<String, SsgError>
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 Plugin for LlmPlugin
impl Plugin for LlmPlugin
Source§fn after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
fn after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
Source§fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>
fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>
Source§fn transform_html(
&self,
html: &str,
_path: &Path,
_ctx: &PluginContext,
) -> Result<String, SsgError>
fn transform_html( &self, html: &str, _path: &Path, _ctx: &PluginContext, ) -> Result<String, SsgError>
Source§fn has_transform(&self) -> bool
fn has_transform(&self) -> bool
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
fn needs_all_files(&self) -> bool
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 moreAuto Trait Implementations§
impl Freeze for LlmPlugin
impl RefUnwindSafe for LlmPlugin
impl Send for LlmPlugin
impl Sync for LlmPlugin
impl Unpin for LlmPlugin
impl UnsafeUnpin for LlmPlugin
impl UnwindSafe for LlmPlugin
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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