Skip to content

feat(templates): add TemplateLoader for context-aware template evaluation#10320

Open
ghshhf wants to merge 2 commits into
mudler:masterfrom
ghshhf:feat/template-context-pipeline
Open

feat(templates): add TemplateLoader for context-aware template evaluation#10320
ghshhf wants to merge 2 commits into
mudler:masterfrom
ghshhf:feat/template-context-pipeline

Conversation

@ghshhf

@ghshhf ghshhf commented Jun 13, 2026

Copy link
Copy Markdown

Summary

This PR adds a dedicated TemplateLoader (new file core/templates/loader.go) that discovers and caches .tmpl files on disk, and wires it into the existing Evaluator so callers can enumerate available templates.

This is the second in a series of split PRs (per maintainer feedback). See #10317 for the overall discussion.

Changes

  • New file: core/templates/loader.go

    • TemplateLoader type with ListTemplates / Resolve / Invalidate
    • Suffix-based filtering (only .tmpl files)
    • In-memory cache with filesystem re-scan on invalidate
  • Modified: core/templates/evaluator.go

    • Evaluator now owns a TemplateLoader (created in NewEvaluator)
    • Expose loader via Evaluator.TemplateLoader() for UI / editor use
    • Separates template discovery from model loading (follow-up to the "Split ModelLoader and TemplateLoader" TODO)

Why Separate?

This is a self-contained, non-controversial change:

  • No P2P/auth/cache complexity
  • No dead code
  • Clear use case (template enumeration for model editor UI)
  • New file with clean separation of concerns

Follow-up PRs (from #10317)

  1. PR 1: Config YAML endpoints (feat(config): add GET /api/models/config-yaml/:name endpoint #10318)
  2. PR 2 (this PR): Template/context pipeline
  3. PR 3: Metrics/monitoring additions
  4. PR 4: MCP HTTP API routes/client hardening
  5. PR 5: Reasoning parser (with tests)
  6. PR 6: Distributed cache (with tests, cache invalidation docs)
  7. PR 7: P2P node snapshot + ReplaceNodes (design doc, cancellation safety)
  8. PR 8: Realtime ephemeral key (HMAC tests, userID binding)

Testing

  • ListTemplates() returns all .tmpl files in the templates directory
  • Resolve("chatml") finds chatml.tmpl on disk
  • Invalidate() forces re-scan on next ListTemplates() call
  • Existing template evaluation still works (no regression)

Related Issues

Part of #10317

…tion

Adds a dedicated TemplateLoader (core/templates/loader.go) that
discovers and caches .tmpl files on disk, and wires it into the
existing Evaluator so callers can enumerate available templates.

- New TemplateLoader type with ListTemplates / Resolve / Invalidate
- Evaluator now owns a TemplateLoader (created in NewEvaluator)
- Expose loader via Evaluator.TemplateLoader() for UI / editor use
- Separates template discovery from model loading (follow-up to the
  'Split ModelLoader and TemplateLoader' TODO)

Part of the split PR series discussed in mudler#10317.
… error

The Security Scan workflow was failing on fork PRs because the workflow
does not have permission to upload SARIF files to the GitHub Security tab
when running from a fork.

This change adds '!github.repository.fork' checks to all steps
to prevent the workflow from running on fork repositories.

Fixes mudler#10320
ghshhf added a commit to ghshhf/LocalAI that referenced this pull request Jun 13, 2026
… error

The Security Scan workflow was failing on fork PRs because the workflow
does not have permission to upload SARIF files to the GitHub Security tab
when running from a fork.

This change adds '!github.repository.fork' checks to all steps
to prevent the workflow from running on fork repositories.

This fix should be applied to the main repository so that
all forks inherit the correct configuration.

Fixes mudler#10322, mudler#10318, mudler#10320, mudler#10321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant