🐛 fix(constants.tsx): add check for empty tweak array to avoid JSON.stringify error

This commit is contained in:
Cristhian Zanforlin Lousa 2023-06-27 19:51:53 -03:00
commit 132b2e367b
2 changed files with 4 additions and 3 deletions

View file

@ -71,7 +71,7 @@ FLOW_ID = "${flowId}"
# You can tweak the flow by adding a tweaks dictionary
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
TWEAKS = ${
tweak ? JSON.stringify(tweak, null, 2) : JSON.stringify(tweaks, null, 2)
tweak && tweak.length > 0 ? JSON.stringify(tweak, null, 2) : JSON.stringify(tweaks, null, 2)
}
def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict:
@ -111,7 +111,7 @@ export const getCurlCode = (flow: FlowType, tweak?): string => {
}/api/v1/process/${flowId} \\
-H 'Content-Type: application/json' \\
-d '{"inputs": {"input": message}, "tweaks": ${
tweak ? JSON.stringify(tweak, null, 2) : JSON.stringify(tweaks, null, 2)
tweak && tweak.length > 0 ? JSON.stringify(tweak, null, 2) : JSON.stringify(tweaks, null, 2)
}}'`;
};
/**
@ -124,7 +124,7 @@ export const getPythonCode = (flow: FlowType, tweak?): string => {
const tweaks = buildTweaks(flow);
return `from langflow import load_flow_from_json
TWEAKS = ${
tweak ? JSON.stringify(tweak, null, 2) : JSON.stringify(tweaks, null, 2)
tweak && tweak.length > 0 ? JSON.stringify(tweak, null, 2) : JSON.stringify(tweaks, null, 2)
}
flow = load_flow_from_json("${flowName}.json", tweaks=TWEAKS)
# Now you can use it like any chain

View file

@ -77,6 +77,7 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
closePopUp();
}
}
const pythonApiCode = getPythonApiCode(flow, tweak.current);
const curl_code = getCurlCode(flow, tweak.current);