Refactor: move getPythonCode to apiModal folder

This commit is contained in:
igorrCarvalho 2024-05-21 19:56:02 -03:00
commit 69f3b16fb7
3 changed files with 18 additions and 19 deletions

View file

@ -0,0 +1,17 @@
/**
* Function to get the python code for the API
* @param {string} flow - The current flow
* @param {any[]} tweak - The tweaks
* @returns {string} - The python code
*/
export default function getPythonCode(flowName: string, tweaksBuildedObject): string {
const tweaksObject = tweaksBuildedObject[0];
return `from langflow.load import run_flow_from_json
TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
result = run_flow_from_json(flow="${flowName}.json",
input_value="message",
fallback_to_env_vars=True, # False by default
tweaks=TWEAKS)`;
}

View file

@ -14,7 +14,6 @@ import { TemplateVariableType } from "../../../types/api";
import { uniqueTweakType } from "../../../types/components";
import { FlowType } from "../../../types/flow/index";
import {
getPythonCode,
getWidgetCode,
tabsArray,
} from "../../../utils/utils";
@ -27,6 +26,7 @@ import { getNodesWithDefaultValue } from "../utils/get-nodes-with-default-value"
import { getValue } from "../utils/get-value";
import getPythonApiCode from "../utils/get-python-api-code";
import getCurlCode from "../utils/get-curl-code";
import getPythonCode from "../utils/get-python-code";
const ApiModal = forwardRef(
(

View file

@ -158,24 +158,6 @@ export function getOutputIds(flow) {
return arrayOfOutputsJoin;
}
/**
* Function to get the python code for the API
* @param {string} flow - The current flow
* @param {any[]} tweak - The tweaks
* @returns {string} - The python code
*/
export function getPythonCode(flowName: string, tweaksBuildedObject): string {
const tweaksObject = tweaksBuildedObject[0];
return `from langflow.load import run_flow_from_json
TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
result = run_flow_from_json(flow="${flowName}.json",
input_value="message",
fallback_to_env_vars=True, # False by default
tweaks=TWEAKS)`;
}
/**
* Function to get the widget code for the API
* @param {string} flow - The current flow.