fix: ensure tweaks object exists (#2134)
* ensure tweaks object exists * Make similar change for python code
This commit is contained in:
parent
1110494615
commit
a5752cdc14
2 changed files with 28 additions and 11 deletions
|
|
@ -2,19 +2,27 @@
|
||||||
* Function to get the python code for the API
|
* Function to get the python code for the API
|
||||||
* @param {string} flowId - The id of the flow
|
* @param {string} flowId - The id of the flow
|
||||||
* @param {boolean} isAuth - If the API is authenticated
|
* @param {boolean} isAuth - If the API is authenticated
|
||||||
* @param {any[]} tweak - The tweaks
|
* @param {any[]} tweaksBuildedObject - The tweaks
|
||||||
|
* @param {string} [endpointName] - The optional endpoint name
|
||||||
* @returns {string} - The python code
|
* @returns {string} - The python code
|
||||||
*/
|
*/
|
||||||
export default function getPythonApiCode(
|
export default function getPythonApiCode(
|
||||||
flowId: string,
|
flowId: string,
|
||||||
isAuth: boolean,
|
isAuth: boolean,
|
||||||
tweaksBuildedObject,
|
tweaksBuildedObject: any[],
|
||||||
endpointName?: string
|
endpointName?: string,
|
||||||
): string {
|
): string {
|
||||||
const tweaksObject = tweaksBuildedObject[0];
|
let tweaksString = "{}";
|
||||||
const tweaksString = JSON.stringify(tweaksObject, null, 2)
|
if (tweaksBuildedObject && tweaksBuildedObject.length > 0) {
|
||||||
.replace(/true/g, "True")
|
const tweaksObject = tweaksBuildedObject[0];
|
||||||
.replace(/false/g, "False");
|
if (!tweaksObject) {
|
||||||
|
throw new Error("expected tweaks");
|
||||||
|
}
|
||||||
|
tweaksString = JSON.stringify(tweaksObject, null, 2)
|
||||||
|
.replace(/true/g, "True")
|
||||||
|
.replace(/false/g, "False");
|
||||||
|
}
|
||||||
|
|
||||||
return `import argparse
|
return `import argparse
|
||||||
import json
|
import json
|
||||||
from argparse import RawTextHelpFormatter
|
from argparse import RawTextHelpFormatter
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,26 @@
|
||||||
/**
|
/**
|
||||||
* Function to get the python code for the API
|
* Function to get the python code for the API
|
||||||
* @param {string} flow - The current flow
|
* @param {string} flow - The current flow
|
||||||
* @param {any[]} tweak - The tweaks
|
* @param {any[]} tweaksBuildedObject - The tweaks
|
||||||
* @returns {string} - The python code
|
* @returns {string} - The python code
|
||||||
*/
|
*/
|
||||||
export default function getPythonCode(
|
export default function getPythonCode(
|
||||||
flowName: string,
|
flowName: string,
|
||||||
tweaksBuildedObject
|
tweaksBuildedObject: any[],
|
||||||
): string {
|
): string {
|
||||||
const tweaksObject = tweaksBuildedObject[0];
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
return `from langflow.load import run_flow_from_json
|
return `from langflow.load import run_flow_from_json
|
||||||
TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
|
TWEAKS = ${tweaksString}
|
||||||
|
|
||||||
result = run_flow_from_json(flow="${flowName}.json",
|
result = run_flow_from_json(flow="${flowName}.json",
|
||||||
input_value="message",
|
input_value="message",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue