Closed edwinjosechittilappilly closed 1 month ago
To resolve the issue of null
values in the Tweaks Dictionary for Python code, you can update the getPythonCode
function to replace null
with None
. Here is the updated code:
/**
* Function to get the python code for the API
* @param {string} flow - The current flow
* @param {any[]} tweaksBuildedObject - The tweaks
* @returns {string} - The python code
*/
export default function getPythonCode(
flowName: string,
tweaksBuildedObject: any[]
): string {
let tweaksString = "{}";
if (tweaksBuildedObject && tweaksBuildedObject.length > 0) {
const tweaksObject = tweaksBuildedObject[0];
if (!tweaksObject) {
throw new Error("expected tweaks");
}
tweaksString = JSON.stringify(tweaksObject, null, 2)
.replace(/true/g, "True")
.replace(/false/g, "False")
.replace(/null/g, "None");
}
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 any null
values in the JSON string are replaced with None
to avoid the NameError
in Python [1].
To continue talking to Dosu, mention @dosu.
Null Value in Tweaks Dictionary for Python Code
Title: Null Value in Tweaks Dictionary for Python Code
Description: I have encountered an issue where the Tweaks Dictionary generated for Python code contains a value
null
instead ofNone
. This results in an error becausenull
is not defined in Python, and it needs to be replaced withNone
for the code to run correctly.Error Message:
Details:
null
values.null
should be replaced withNone
.Environment:
ragstack-ai-langflow ^1.0.6.post5
Steps to Reproduce:
null
values.NameError
due tonull
being undefined.Expected Behavior: The Tweaks Dictionary should contain
None
values instead ofnull
to ensure compatibility with Python syntax.Actual Behavior: The Tweaks Dictionary contains
null
values, causing aNameError
when running the Python code.Additional Context: This issue impacts the execution of Python code when using generated Tweaks, as the
null
values need to be manually replaced withNone
.Screenshots: N/A
Logs:
Possible Solution: Update the Tweaks generation process to replace
null
withNone
for Python code.Thank you for your assistance!