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

Fix the failure to resolve variables for OverrideConfig(Json Object) #1843

Merged
merged 2 commits into from
Mar 11, 2024

Conversation

mokeyish
Copy link
Contributor

@mokeyish mokeyish commented Mar 1, 2024

When defining chatflowConfig as below, {{question}} was not replaced with user input.

Chatbot.initFull({
      chatflowid: 'e8c221b3-a47e-4c05-bcbc-86491b52bea9',
      apiHost: 'http://127.0.0.1:8711',
      isFullPage: true,
      chatflowConfig: {
        functionInputVariables: {
          topk: '7', // {{question}}
        }
      },
})

I found out that getVariableValue only handles strings. This PR solves the problem.

@mokeyish
Copy link
Contributor Author

mokeyish commented Mar 1, 2024

@HenryHengZJ It seems that the failure of CI is not due to this code modification.

图片

@HenryHengZJ
Copy link
Contributor

You mean the topK provided below is not being captured?

Chatbot.initFull({
      chatflowid: 'e8c221b3-a47e-4c05-bcbc-86491b52bea9',
      apiHost: 'http://127.0.0.1:8711',
      isFullPage: true,
      chatflowConfig: {
        functionInputVariables: {
          topk: '7', // {{question}}
        }
      },
})

@mokeyish
Copy link
Contributor Author

mokeyish commented Mar 1, 2024

topk is captured, it's no problem, but CustomFunction received {{question}}.

@HenryHengZJ
Copy link
Contributor

topk is captured, it's no problem, but CustomFunction received {{question}}.

hey sorry for late getting back. what do you mean by CustomFunction received {{question}} ?

I tested the following chatflow:
image

{
    "question": "how are u",
    "overrideConfig": {
        "functionInputVariables": {
            "character": "sarcastic"
        }
    }
}

It is able to override the variable character

@mokeyish
Copy link
Contributor Author

Add {question} to Format Prompt Values, and then only overwrite character, CustomFunction will not be able to get the value of {question}.

@mokeyish
Copy link
Contributor Author

mokeyish commented Mar 11, 2024

This is because getVariableValue receives paramValue of type object.

{
   "character": "sarcastic",
   "question": "{{question}}"
}

paramValue.length returns undefined, so it will not be able to resolve {question}.


This can be solved by serializing paramValue to a JSON string.

@HenryHengZJ
Copy link
Contributor

HenryHengZJ commented Mar 11, 2024

Add {question} to Format Prompt Values, and then only overwrite character, CustomFunction will not be able to get the value of {question}.

actually it was a bug on UI, the dialog was meant to be from the Input Variables from Custom Function:
image

Here's the chatflow:
test Chatflow.json

@HenryHengZJ
Copy link
Contributor

For future reference, the issue was:

When you have an overrideConfig which is a JSON type. For example: functionInputVariables, and you have {{question}} as one of the variables value:
image

The code does not replace {{question}}:
image

This fix is to stringify the JSON object, allowing {{question}} to be replaced correctly

@HenryHengZJ
Copy link
Contributor

@mokeyish can you pull the latest changes from main so we can have this to let the CI run successfully

@mokeyish
Copy link
Contributor Author

sure

@mokeyish
Copy link
Contributor Author

@HenryHengZJ BTW, It would be better to use squash+rebase when merging code into the main branch, so that you can have a clearer git history.

@HenryHengZJ
Copy link
Contributor

@HenryHengZJ BTW, It would be better to use squash+rebase when merging code into the main branch, so that you can have a clearer git history.

thanks for the suggestion! will definitely take a look!

@HenryHengZJ HenryHengZJ merged commit 90d40e1 into FlowiseAI:main Mar 11, 2024
2 checks passed
@mokeyish mokeyish deleted the patch-6 branch March 11, 2024 11:00
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