You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-3Lines changed: 20 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -159,16 +159,33 @@ neg_common
159
159
160
160
### When you need curly braces themselves
161
161
162
-
To have the literal curly-brace characters inside the **formatted** prompt, you need to "escape" them: whenever you need one, you type it twice (`'{{'` or `'}}'`). Then, after formatting, it will turn to `'{'` or `'}'`, respectively.
162
+
#### Safe mode `✨New in v1.1.0`
163
163
164
-
Keep in mind though, that with [Recursive formatting](#recursive-formatting-), any `{{text}}` will become `{text}` after very first iteration, and thus on the next one, it still will be treated as a placeholder to put a string with a `text` key into.
164
+
The simplest solution - just enable `safe_format` toggle. It changes the node behavior: whenever formatter encounters any `{text inside curly braces}` that cannot be formatted _(for any reason: the dict misses this key, or it's an outright invalid pattern)_, it doesn't throw an error and instead simply leaves this part of template as-is.
165
+
166
+
It's extremely useful for code-like templates (e.g., containing JSON or CSS).
167
+
168
+
However, even for proper `{patterns}` referencing proper dict keys, the manual escaping (see below) also applies.
169
+
170
+
> [!NOTE]
171
+
> Keep in mind that any spaces inside braces immediately make this pattern invalid.
172
+
>
173
+
> Thus, if you want to have something like: `{{my_key}}`_(so, `{my_key}` to be replaced + it's wrapped into another set of braces which you want to have in the output)_, the easiest way to do it without escaping is simply enabling safe mode and adding a couple of spaces inside the braces you want to stay. So: `{ {my_key} }` - the innermost part will be replaced with the value of `my_key` item from the dict, while the outer braces will stay.
174
+
175
+
#### Manual escaping - double braces
176
+
177
+
If you want to explicitly control which braces perform formatting and which don't - to have the literal curly-brace characters inside the prompt **after** formatting, you need to [escape](https://docs.python.org/3/library/string.html#format-string-syntax) them: whenever you need one, you type it twice (`'{{'` or `'}}'`). Then, after formatting, it will turn to `'{'` or `'}'`, respectively.
178
+
179
+
Keep in mind though, that with escaping approach and [Recursive formatting](#recursive-formatting-), any `{{text}}` will become `{text}` after very first iteration, and thus on the next one, it still will be treated as a placeholder to put a value of the `text` key into.
165
180
166
181
However, this might be exactly what you want for...
167
182
168
183
### Dynamic pattern aka conditional formatting
169
184
170
185
In other words, you build a prompt, where **keys themselves** are compiled from pieces. For example:
171
-
- Your main text template has {{character_`{active_char}`}} pattern somewhere inside it.
186
+
- Your main text template has one of the following patterns somewhere inside it:
187
+
- {{character_`{active_char}`}} - if safe mode is off;
188
+
- {character_`{active_char}`} - if safe mode is on.
172
189
- You also have a string named `active_char` in your dict, which you simply set to a number.
173
190
- Also-also, you have strings named `character_1`, `character_2`, etc.
174
191
- Then, with recursive formatting, depending on just a **single** value you set the `active_char` element to, the following happens:
0 commit comments