feat: add support for template variables in prompt files through vars parameter#98
Merged
Conversation
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds dynamic prompt templating support so users can supply a vars YAML block and have Nunjucks templates rendered for both prompt and system-prompt inputs while preserving backward compatibility.
- Introduce
processTemplate()helper using js-yaml and Nunjucks - Hook template processing into
run()forprompt/prompt-fileandsystem-prompt/system-prompt-file - Update metadata, dependencies, tests, and docs to cover the new
varsinput
Reviewed Changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/template.ts | New processTemplate function parses YAML and renders via Nunjucks |
| src/main.ts | Calls processTemplate on both prompt and system-prompt inputs |
| package.json | Added js-yaml, nunjucks, and their type definitions |
| action.yml | Declared optional vars input |
| README.md | Documented templating feature with examples |
| tests/template.test.ts | Unit tests covering variable substitution, loops, conditionals, filters, and errors |
| tests/main.test.ts | Integration tests for templating in action run |
| tests/prompts/country-capital-prompt.md | Sample prompt template for country-capital test |
| tests/country-capital-response.json | JSON schema for the country-capital example |
| .github/workflows/test-action.yml | Updated test workflow to exercise templating and schema validation |
Comments suppressed due to low confidence (2)
README.md:110
- The YAML snippet under "Basic Variable Substitution" is invalid: the
promptkey should use a pipe (|) for a multi-line string rather than a quoted scalar on the next line. Update to:
prompt: |
You are a {{ language }} expert translator. Translate the following text to {{ target_language }}: {{ text }} prompt:
tests/main.test.ts:642
- There is no test covering
system-prompt-filetemplating withvars. Consider adding a test that mockssystem-prompt-fileand verifies it is rendered with the provided variables.
it('should process template with prompt file', async () => {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds dynamic prompt templating support using Nunjucks templates and YAML variables, making the action much more flexible and reusable across different contexts.
✨ New Features
Template Variables Support
varsinput parameter accepts YAML-formatted variablesprompt,prompt-file,system-prompt,system-prompt-fileTemplate Syntax
{{ variable }}{% if condition %}...{% endif %}{% for item in items %}...{% endfor %}{{ text | upper }},{{ items | join(', ') }}{{ user.name }},{{ config.database.host }}📋 Examples
Basic Variable Substitution
GitHub Workflow Context Integration
Template Files with Loops and Conditionals
Fixes #77.