Templates
This article provides an overview of how prompt instructions and policies can be tailored to a user, through the use of templates. For instance, instructions can be customized for the user's language, the device they are using, their plan type, and so on.
Introduction to templates
Markprompt uses Handlebars, which is a simple templating language that allows you to embed expressions in your content. It is used to dynamically generate content by merging templates with a context object. Handlebars provides a clean and concise syntax for injecting variables and managing conditional content.
Using variables
The simplest use of templates is via variables, which act as placeholders for content that can be provided on a per-user basis.
Basic variable insertion
Variables are placeholders that are wrapped in double curly braces ({{}}
). These variables are replaced with corresponding values from the context provided during template rendering.
Example
If the context passed is:
this template will be rendered as:
Accessing object properties
To organize information, nested properties within an object are also supported. You can use dot notation to access these properties.
Example
If the context passed is:
this template will be rendered as:
Conditional statements
Conditional statements allow you to introduce logical branching within your instructions, such as providing different chunks of instructions depending on the user.
Basic conditional rendering
Handlebars allows you to conditionally render content using the {{#if}}
block. The content within the {{#if}}
block is rendered if the condition evaluates to true.
Example
Using alternative content
You can use the {{else}}
block to define alternative content that is rendered when the condition in {{#if}}
evaluates to false.
Helpers
Markprompt provides helper functions enabling you to interact with your project data.
Specifically, Markprompt currently supports a source
helper, which allows you to include the content of an file inside of your prompts and policies. It used as follows:
The source helper expects two parameters:
name
: the name of the sourcepath
: the path of the file under that source
You can grab this information when you open the file in the Data tab.
Playground testing
In order to test your templates, the playground allows you to pass a mock context object. This can be provided by hitting the arrow next to the Send button:
The context can be set here, as a JSON-formatted object, e.g.:
Reserved variables
In addition to the variables you pass explicitly via context, Markprompt also passes system variables and thread metadata, nested under the markprompt
and threadMetadata
objects respectively.
System variables
System variables are provided automatically, so that you do not need to worry about passing them explicitly. These variables are accessible via the markprompt
object. They are currently:
Key | Type | Description |
---|---|---|
markprompt.isMobile | true | false | True if the user is accessing your assistant via a mobile device. |
To use it, simply refer to the properties under the markprompt
object:
Thread metadata
Likewise, when you pass thread metadata alongside a chat request, the payload is accessible via the threadMetadata
object. To use thread metadata, simply refer to the properties under the threadMetadata
object: