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
Describe the bug
I was using a Custom Function at the start of my flow to retrieve a variable injected via chatflowConfig named "context".
Inside this variable there was some text (markdown formatted) and some stringified objects (schema-org) that got extracted from webpage dynamically. This has worked great.
In order to black list some values I decided to replace this functionality with an IfElse Function. This hasn't worked.
When looking into the code I found that "handleEscapeCharacters" is not called for an IfElse Function's returnValue. I've seen that some weeks ago something similar has been fixed on Custom Function so I wonder why this wasn't applied to IfElse Function. I prepared a Pull-Request to fix this issue. I've tested it inside my IfElse Function, too.
@HenryHengZJ Do you want me to create a PR? The solution would be to call handleEscapeCharacters if the IfElse Response output is type of string
See:
To Reproduce
Steps to reproduce the behavior:
This has worked:
var context = $vars.context;
return String(context || 'N/A');
This hasn't worked: Unexpected Token XY in ChatPromptTemplates promptValues
var isNotBlacklisted = true;
var NO_CONTEXT = 'N/A';
var context = $vars.context || NO_CONTEXT;
var isValid = isNotBlacklisted && context !== NO_CONTEXT;
if (isValid) {
console.log(context);
return String(context);
}
This fixed it:
var NO_CONTEXT = 'N/A'
var context = $vars.context || NO_CONTEXT;
var isValid = isNotBlacklisted && context !== NO_CONTEXT;
const jsonEscapeCharacters = [
{ escape: '"', value: 'FLOWISE_DOUBLE_QUOTE' },
{ escape: '\n', value: 'FLOWISE_NEWLINE' },
{ escape: '\b', value: 'FLOWISE_BACKSPACE' },
{ escape: '\f', value: 'FLOWISE_FORM_FEED' },
{ escape: '\r', value: 'FLOWISE_CARRIAGE_RETURN' },
{ escape: '\t', value: 'FLOWISE_TAB' },
{ escape: '\\', value: 'FLOWISE_BACKSLASH' }
]
function handleEscapesJSONParse(input, reverse) {
for (const element of jsonEscapeCharacters) {
input = reverse ? input.replaceAll(element.value, element.escape) : input.replaceAll(element.escape, element.value)
}
return input
}
function iterateEscapesJSONParse(input, reverse) {
for (const element in input) {
const type = typeof input[element]
if (type === 'string') input[element] = handleEscapesJSONParse(input[element], reverse)
else if (type === 'object') input[element] = iterateEscapesJSONParse(input[element], reverse)
}
return input
}
function handleEscapeCharacters(input, reverse) {
const type = typeof input
if (type === 'string') return handleEscapesJSONParse(input, reverse)
else if (type === 'object') return iterateEscapesJSONParse(input, reverse)
return input
}
if (isValid) {
console.log(context);
return handleEscapeCharacters(String(context), false);
}
The text was updated successfully, but these errors were encountered:
If it's not missing for a reason then I'm pretty sure this got overseen. :) Appreciate to contribute that tiny piece. Using Flowise for some months now and really appreciate those valuable constant improvements that arrive, great work!
Describe the bug
I was using a Custom Function at the start of my flow to retrieve a variable injected via chatflowConfig named "context".
Inside this variable there was some text (markdown formatted) and some stringified objects (schema-org) that got extracted from webpage dynamically. This has worked great.
In order to black list some values I decided to replace this functionality with an IfElse Function. This hasn't worked.
When looking into the code I found that "handleEscapeCharacters" is not called for an IfElse Function's returnValue. I've seen that some weeks ago something similar has been fixed on Custom Function so I wonder why this wasn't applied to IfElse Function. I prepared a Pull-Request to fix this issue. I've tested it inside my IfElse Function, too.
@HenryHengZJ Do you want me to create a PR? The solution would be to call handleEscapeCharacters if the IfElse Response output is type of string
See:
To Reproduce
Steps to reproduce the behavior:
The text was updated successfully, but these errors were encountered: