Merge remote-tracking branch 'origin/dev' into two_edges

This commit is contained in:
ogabrielluiz 2024-06-11 09:52:41 -03:00
commit 0014d8e50a
16 changed files with 182 additions and 31 deletions

View file

@ -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

View file

@ -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",