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

Error in the Code Export: Boolean values are in the incorrect syntax. 'false' should be changed to 'False', 'true' should be changed to 'True'. #2126

Closed
edwinjosechittilappilly opened this issue Jun 10, 2024 · 2 comments · Fixed by #2130
Labels
bug Something isn't working

Comments

@edwinjosechittilappilly
Copy link
Contributor

Error in the Code Export: Boolean values are in the incorrect syntax. 'false' should be changed to 'False', 'true' should be changed to 'True'.

To Reproduce
Steps to reproduce the behavior:
click to export code, and turn on tweaks

Screenshots
Screenshot 2024-06-10 at 1 42 59 PM

@dosubot dosubot bot added the bug Something isn't working label Jun 10, 2024
Copy link

dosubot bot commented Jun 10, 2024

To fix the issue where Boolean values are incorrectly formatted for Python in the code export feature, you need to ensure that the Boolean values in the tweaksBuildedObject are correctly converted from JavaScript's true/false to Python's True/False. You can achieve this by modifying the getPythonCode function to replace these values in the JSON string.

Here's the updated code:

/**
 * Function to get the python code for the API
 * @param {string} flow - The current flow
 * @param {any[]} tweak - The tweaks
 * @returns {string} - The python code
 */
export default function getPythonCode(
  flowName: string,
  tweaksBuildedObject
): string {
  const tweaksObject = tweaksBuildedObject[0];
  const tweaksString = JSON.stringify(tweaksObject, null, 2)
    .replace(/true/g, "True")
    .replace(/false/g, "False");

  return `from langflow.load import run_flow_from_json
TWEAKS = ${tweaksString}

result = run_flow_from_json(flow="${flowName}.json",
                            input_value="message",
                            fallback_to_env_vars=True, # False by default
                            tweaks=TWEAKS)`;
}

This modification ensures that the Boolean values are correctly formatted for Python when the code is exported. Additionally, the CodeTabsComponent in src/frontend/src/components/codeTabsComponent/index.tsx includes a switch to enable or disable tweaks, which should be considered when exporting the code [1][2][3][4][5].

To continue talking to Dosu, mention @dosu.

@edwinjosechittilappilly
Copy link
Contributor Author

#2130
Bugfix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant