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

Allow default variable values ​​when testing CustomFunction #1800

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

mokeyish
Copy link
Contributor

@mokeyish mokeyish commented Feb 23, 2024

Testing code is more cumbersome when CustomFunction requires input variables.

const question = $question ?? 'my default question'

```js
const question = $question ?? 'my default question'

```
@HenryHengZJ
Copy link
Contributor

The pre-requisite is that you need to have the variables already specified in the UI, right?

@mokeyish
Copy link
Contributor Author

The pre-requisite is that you need to have the variables already specified in the UI, right?

When CustomFunction needs to receive variables from chatflow, testing CustomFunction often reports errors. This can be forcibly defined as undefined. If the variable is undefined, the default value in the code will be used.

This is only a temporary fix for better testing CustomFunction.

  • before

    // const question = $question  // we need comment this line to avoid error.
    const question = "my default question"
  • after

    const question = $question ?? "my default question"

@HenryHengZJ
Copy link
Contributor

for future reference:

1.) Have a custom js function node with input variable, then hit execute:
image
We will see the error

2.) With the changes, it will becomes undefined (not throwing error):
image

@HenryHengZJ HenryHengZJ merged commit 2d9bf58 into FlowiseAI:main Feb 27, 2024
2 checks passed
@mokeyish mokeyish deleted the patch-2 branch February 27, 2024 04:54
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

Successfully merging this pull request may close these issues.

None yet

2 participants