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
|
||||
* @param {string} flowId - The id of the flow
|
||||
* @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
|
||||
*/
|
||||
export default function getPythonApiCode(
|
||||
flowId: string,
|
||||
isAuth: boolean,
|
||||
tweaksBuildedObject,
|
||||
endpointName?: string
|
||||
tweaksBuildedObject: any[],
|
||||
endpointName?: string,
|
||||
): string {
|
||||
const tweaksObject = tweaksBuildedObject[0];
|
||||
const tweaksString = JSON.stringify(tweaksObject, null, 2)
|
||||
.replace(/true/g, "True")
|
||||
.replace(/false/g, "False");
|
||||
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 `import argparse
|
||||
import json
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
|
|
|||
|
|
@ -1,17 +1,26 @@
|
|||
/**
|
||||
* Function to get the python code for the API
|
||||
* @param {string} flow - The current flow
|
||||
* @param {any[]} tweak - The tweaks
|
||||
* @param {any[]} tweaksBuildedObject - The tweaks
|
||||
* @returns {string} - The python code
|
||||
*/
|
||||
export default function getPythonCode(
|
||||
flowName: string,
|
||||
tweaksBuildedObject
|
||||
tweaksBuildedObject: any[],
|
||||
): 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
|
||||
TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
|
||||
TWEAKS = ${tweaksString}
|
||||
|
||||
result = run_flow_from_json(flow="${flowName}.json",
|
||||
input_value="message",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue