-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support for template propmpts * Update dependencies and integrate variable interpolation in markdown processing * Refactor interpolation logic by moving it from markdown.ts to a new file mustache.ts and update imports in promptdom.ts * Refactor test generation script and implement interpolation tests for mustache module * Add support for importing template data in prompt rendering functions * Added mustache template rendering and updated types and sample files for improved template interpolation * Update keywords and add hint function in import-template.genai.mts * Add docstring to interpolateVariables function in mustache.ts * Add importTemplate documentation and improve guidelines in pr-review-commit script * front matter
- Loading branch information
Showing
34 changed files
with
1,052 additions
and
468 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
"pelikhan", | ||
"promptdom", | ||
"promptfoo", | ||
"prompty", | ||
"stringifying", | ||
"sysr", | ||
"tabletojson", | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ https://www.npmjs.com/package/generate-license-file | |
|
||
The following npm package may be included in this product: | ||
|
||
- pdfjs-dist@4.5.136 | ||
- pdfjs-dist@4.6.82 | ||
|
||
This package contains the following license and notice below: | ||
|
||
|
@@ -1458,7 +1458,7 @@ The following npm packages may be included in this product: | |
- @types/http-cache-semantics@4.0.4 | ||
- @types/jsonfile@6.1.4 | ||
- @types/mute-stream@0.0.4 | ||
- @types/node@22.5.1 | ||
- @types/node@22.5.2 | ||
- @types/turndown@5.0.5 | ||
- @types/yauzl@2.10.3 | ||
|
||
|
@@ -1520,7 +1520,7 @@ MIT License | |
|
||
The following npm package may be included in this product: | ||
|
||
- genaiscript-vscode@1.52.0 | ||
- genaiscript-vscode@1.53.1 | ||
|
||
This package contains the following license and notice below: | ||
|
||
|
@@ -2044,7 +2044,7 @@ software or this license, under any kind of legal claim._** | |
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected].5 | ||
- [email protected].7 | ||
|
||
This package contains the following license and notice below: | ||
|
||
|
@@ -2921,7 +2921,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
The following npm packages may be included in this product: | ||
|
||
- [email protected] | ||
- [email protected].1 | ||
- [email protected].2 | ||
- [email protected] | ||
- [email protected] | ||
|
||
|
@@ -3320,20 +3320,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
|
||
The following npm packages may be included in this product: | ||
|
||
- @inquirer/checkbox@2.4.7 | ||
- @inquirer/confirm@3.1.22 | ||
- @inquirer/core@9.0.10 | ||
- @inquirer/editor@2.1.22 | ||
- @inquirer/expand@2.1.22 | ||
- @inquirer/checkbox@2.5.0 | ||
- @inquirer/confirm@3.2.0 | ||
- @inquirer/core@9.1.0 | ||
- @inquirer/editor@2.2.0 | ||
- @inquirer/expand@2.2.0 | ||
- @inquirer/figures@1.0.5 | ||
- @inquirer/input@2.2.9 | ||
- @inquirer/number@1.0.10 | ||
- @inquirer/password@2.1.22 | ||
- @inquirer/prompts@5.3.8 | ||
- @inquirer/rawlist@2.2.4 | ||
- @inquirer/search@1.0.7 | ||
- @inquirer/select@2.4.7 | ||
- @inquirer/type@1.5.2 | ||
- @inquirer/input@2.3.0 | ||
- @inquirer/number@1.1.0 | ||
- @inquirer/password@2.2.0 | ||
- @inquirer/prompts@5.4.0 | ||
- @inquirer/rawlist@2.3.0 | ||
- @inquirer/search@1.1.0 | ||
- @inquirer/select@2.5.0 | ||
- @inquirer/type@1.5.3 | ||
|
||
These packages each contain the following license and notice below: | ||
|
||
|
@@ -4582,9 +4582,9 @@ The following npm packages may be included in this product: | |
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- genaiscript-core-internal@1.52.0 | ||
- genaiscript-sample@1.52.0 | ||
- genaiscript@1.52.0 | ||
- genaiscript-core-internal@1.53.1 | ||
- genaiscript-sample@1.53.1 | ||
- genaiscript@1.53.1 | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
79 changes: 79 additions & 0 deletions
79
docs/src/content/docs/reference/scripts/import-template.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: Import Template | ||
sidebar: | ||
order: 50 | ||
description: Learn how to import prompt templates into GenAIScript using | ||
`importTemplate` with support for mustache variable interpolation and file | ||
globs. | ||
keywords: importTemplate, prompts, mustache, variable interpolation, file globs | ||
|
||
--- | ||
|
||
Various LLM tools allow to store prompts in text or markdown files. | ||
You can use `importTemplate` to import these files into the prompt. | ||
|
||
```markdown title="cot.md" | ||
Explain your answer step by step. | ||
``` | ||
|
||
```js title="tool.genai.mjs" | ||
importTemplate("cot.md"); | ||
``` | ||
|
||
## Variable interpolation | ||
|
||
`importTemplate` supports [mustache](https://mustache.github.io/) variable interpolation. You can use variables in the imported template and pass them as arguments to the `importTemplate` function. | ||
|
||
```markdown title="time.md" | ||
The current time is {{time}}. | ||
``` | ||
|
||
```js title="tool.genai.mjs" | ||
importTemplate("time.md", { time: "12:00" }); | ||
``` | ||
|
||
Mustache supports arguments as functions. This allows you to pass dynamic values to the template. | ||
|
||
```js title="tool.genai.mjs" | ||
importTemplate("time.md", { time: () => Date.now() }); | ||
``` | ||
|
||
|
||
## File globs | ||
|
||
You can specify an array of files or glob patterns. | ||
|
||
```js | ||
importTemplate("*.prompt") | ||
``` | ||
|
||
## Other File formats | ||
|
||
Aside from the basic text or markdown formats, `importTemplate` also automatically supports these variations. | ||
|
||
### Prompty | ||
|
||
[Prompty](https://prompty.ai/) provides a simple markdown-based format for prompts. It adds the concept of role sections to the markdown format. | ||
|
||
```markdown | ||
--- | ||
name: Basic Prompt | ||
description: A basic prompt that uses the chat API to answer questions | ||
... | ||
inputs: | ||
question: | ||
type: string | ||
sample: | ||
"question": "Who is the most famous person in the world?" | ||
--- | ||
system: | ||
You are an AI assistant who helps people find information. | ||
As the assistant, you answer questions briefly, succinctly. | ||
|
||
user: | ||
{{question}} | ||
``` | ||
|
||
```js title="tool.genai.mjs" | ||
importTemplate("basic.prompty", { question: "what is the capital of France?" }); | ||
``` |
Oops, something went wrong.