Skip to content

Templates

Templates allow you to put variable values into a text, and they are widely used for Prompt assembling. There are two template nodes in ChainGraph: Handlebars and Langchain. Syntax-wise, Handlebars is more functional and better documented.

We will use Handlebars for an example. Here's a simple prompt:

You are a simple AI comedian chatting with people and telling jokes.
You reply like a comdeian doing a show, you never repeat your jokes.

Here's the user message: {{user_message.text}}

And the chat history:
{{ yaml chat_history }}

And the current time:
{{ time }}

Your reply follows...

In this prompt we have 3 variables:

  • user_message, an Object, having at least one text property that is likely of a string type;
  • chat_history, the yaml operator before it tells us that it will be serialised into YAML, meaning we can provide Array, Object, or any other type to it;
  • time, likely String.

Here's how we can supply all these variables to the prompt:

Licensed under BUSL-1.1