A lightweight, intuitive templating language designed for interactive use in LLM chat sessions.
CedarTL is a non-intrusive, recursive templating language that seamlessly integrates with LLM chat sessions. Its simple syntax minimizes cognitive overhead while maximizing speed, making it perfect for interactive development sessions.
- Why should I use it?
- Key Features
- Syntax
- FolderDict
- Quick Start
- Concrete Example
- What's Next?
- Contributing
It can save you time when writing your prompts.
Frequently-used pieces of text can be stored in named templates. Then, instead of typing the same text over and over, you just put a reference to the named template.
- Templating via folders: Frequently used prompts are stored as text files grouped in a
context folder
- Intuitive References: Access templates using simple
\name
syntax
See the concrete example to see how easy the syntax is.
See the quick start section if you want to support CedarTL
in your product
- π Minimal Syntax: Clean, intuitive syntax that feels natural
- Designed to blend naturally with the target text, minimizing typing overhead
- π€ LLM-Optimized: Built specifically for LLM interactions
- π Recursive Processing: It can process templates within templates, allowing for nested template structures
- π Hierarchical key access and function calls
- π Smart Folder-based templating through
FolderDict
- Structure your templates logically in different
context folders
(accessing local directories, tar/zip files, and remote servers via WebDAV, HTTP, FTP, etc) - Easy to switch between different contexts (See
\%cd
) - Multiple contexts can be layered (using most-recent-wins strategy)
- Structure your templates logically in different
- π₯οΈ Shell command Integration
You provide the CedarTL
runtime a root context: a dict
, a list
, an object, or a FolderDict
(a path to a directory where its contained files are the keys, and the file contents are the values)
To escape to CedarTL
syntax, you type a backslash and then a symbol. Examples:
\name
: Key lookup.\path/to/key
: Nested Key lookup
\..
: Move up one level in the context hierarchy\%cd(<path-spec-1> <path-spec-2>...)
: Change the currentcontext folder
from where template keys and values are read\%pwd
: Print current working context folder\%ls
: List contents of current working context folder
\%set(key="value")
: Set volatile template value\%get(key)
: Get the value associated with a key\%saveas(<target-path>)
: Save the current template to a folder\%load(<path>)
: Load template into volatile area
\*chat(some text)
: LLM chat (starts a separate LLM session)\*temp(<float>)
: LLM temperature control
... more to come
A FolderDict
is simply a way to view a folder (the context folder
) as if it were a dict
(that is, a mapping between keys and values).
In Python
, it's compatible with type dict[str, str]
.
Example: Inside a resources
folder, we've added a folder named templates
to hold different context folders. We want to view the main
context folder as a dict
,
so we point a FolderDict
to that main
folder:
resources/
βββ templates/
βββ main/
βββ fsninja.txt
βββ l0.txt
βββ rar.txt
βββ sbs.txt
In the case above, the keys are:
fsninja
(a full-stack ninja)l0
(for Level zero)rar
(for Rephrase And Respond)sbs
(for thinking step-by-step)
Notice that key names should represent the concept contained in the files.
However, all names above are arbitrary: FolderDict
will work regardless of the names involved.
And where are the values for the keys? Yes, the file contents are the values for their corresponding keys.
By storing templates in a FolderDict
, we get some advantages:
- Each folder can have specialized prompts for a specific type of task
- It's easier to share your template folder with the community (just zip it)
- It's easier to version-control a template folder
pip install cedartl
from cedartl import CedarTLProcessor
from importlib.resources import files
# [...]
class ExistingClass:
def __init__(self):
self.template_processor = CedarTLProcessor(files('resources.templates.main'))
def process_user_input(self, input: str):
# ...
processed_input: str = self.template_processor.process(input)
# ...
Real chat session using CedarTL
with qwen-2.5-72b-instruct
and Aider:
In this example, we're using a patched version of Aider that adds support for CedarTL
inside chat sessions.
(Check the FolderDict section to see the names of the templates we're using here)
Aider delegates template processing to the CedarTL
engine, which returns the final rendition of the text to be sent
to the LLM.
(see CedarML for more info)
<cedarml:tool-in.aider>
/add aider/coders/base_coder.py
</cedarml:tool-in.aider>
<cedarml:tool-out.aider>
Added /GitHub/aider/aider/coders/base_coder.py to the chat
βββββββββ
aider/coders/base_coder.py
</cedarml:tool-out.aider>
<cedarml:tool-in.cedartl>
what does this file do? \l0
</cedarml:tool-in.cedartl>
<cedarml:tool-out.cedartl>
\l0: \rar\sbs
\rar: Rephrase my request, then respond.
\sbs: Do so by thinking step by step.
</cedarml:tool-out.cedartl>
<cedarml:role.user>
what does this file do? Rephrase my request, then respond.
Do so by thinking step by step.
</cedarml:role.user>
<cedarml:role.assistant>
Sure, let's break down your request and then respond step by step.
Rephrased Request:
"Can you explain the purpose and main functionalities of the aider/coders/base_coder.py file?"
Step-by-Step Response:
1. File Overview:
β’ The aider/coders/base_coder.py file is a Python module that defines the Coder class and related functionalities.
β’ This class is a core component of the Aider application, which is designed to assist users in coding tasks using AI.
</cedarml:role.assistant>
Here's what's on the horizon for CedarTL
:
-
Browser Extension
- Cross-platform extension for seamless template access in any web text input
- Support for popular platforms:
- LLM web interfaces (Kagi Assistant, ChatGPT, Claude, OpenRouter, etc.)
- Messaging apps (WhatsApp Web, Google Chat)
- Online text editors
- Social media platforms like Facebook, Instagram
- Features:
- Local template storage and management
- Secure sync across devices
- Template preview on hover
- Context-aware template auto-complete
- Integration with browser's autofill system
- Smart template generation from frequently typed text
-
Core Enhancements
- Template sharing ecosystem
- More backend storage options (databases, cloud storage)
- Better template versioning
-
Integration APIs
- SDK for easy integration into other applications
Want to contribute? Check out our GitHub issues or propose new features!
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request