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
Contributor

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

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.

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

@localai-org-maint-bot localai-org-maint-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mudler This adds a TemplateLoader but no production caller uses ListTemplates, Resolve, or Invalidate; the only integration is an accessor returning the otherwise-unused loader. The split PR also omitted the 22 tests mentioned in the parent branch and carries an unrelated security-scan edit. Please either include a concrete consumer plus focused loader tests, or remove the unused surface, then rebase the scoped change onto current master without .github/workflows/secscan.yaml.

whllwsyh and others added 2 commits July 29, 2026 18:04
…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
@localai-org-maint-bot
localai-org-maint-bot force-pushed the feat/template-context-pipeline branch from 3c86963 to 3f0615a Compare July 29, 2026 18:05
localai-org-maint-bot pushed a commit to ghshhf/LocalAI that referenced this pull request Jul 29, 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
localai-org-maint-bot pushed a commit to ghshhf/LocalAI that referenced this pull request Jul 29, 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
mudler pushed a commit that referenced this pull request Jul 30, 2026
… error (#10323)

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 #10322, #10318, #10320, #10321

Co-authored-by: ghshhf <ghshhf@users.noreply.github.com>
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.

2 participants