Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Introduce the possibility to use {{param}} notation as alternative to single {param} notation #274

Open
massi-ang opened this issue May 3, 2024 · 2 comments

Comments

@massi-ang
Copy link
Contributor

In many prompts the context is JSON data. By using single curly brackets notation for template parameters means that I need to escape all the { and } in the input JSON data.

I propose to introduce a flow setting to switch from single curly brackets to double curly brackets notation. By setting the property on the flow would guarantee backward compatibility with the current notation and would apply to all nodes (text, prompts) etc in the flow. Alternatively, the option could be enabled on each node separately (more flexible but could be source of errors) or as a global setting (simpler, but might generate errors or unexpected results if a flow with the other notation is loaded and executed).

The double curly brackets notation is used by the widely adopted Mustache

@massi-ang
Copy link
Contributor Author

@ianarawjo I have a working implementation for the double curly bracket notation, but would like to have your input on the best way to enable this feature.

@ianarawjo
Copy link
Owner

Sounds worthwhile. Indeed I have thought of letting users selectively turn it off in TextFields Nodes. However, this is a system-wide issue and best handled as a global setting (in global settings modal) that persists across user sessions and is also stored on a flow-specific basis.

The simplest way to implement that is to add a settings tab called "Flow Settings" (settings specific to just this flow) that let the user customize global properties. It would contain one setting for template format, as a drop-down (NativeSelect). If the user imports a flow, it will try to auto-detect the correct setting and change it. If the user clicks New Flow, it will look at the current setting and carry that over.

In the backend, this change would affect how templates are parsed, which is quite low-level code. I implemented these functions for brace parsing in (template.ts) as a linear O(n) parse because RegEx was hard to read and lookaheads/behinds weren't supported everywhere. In particular, you may also need to modify cleanEscapedBraces and esp escapeBraces, since you won't want ti to escape all braces anymore but rather only double-braces. The easiest way is to set a global variable in StorageCache and read the setting from it in functions outside of React components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants