From 69f3b16fb73231c07728c721a7e1d5b2194b6d65 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Tue, 21 May 2024 19:56:02 -0300 Subject: [PATCH] Refactor: move getPythonCode to apiModal folder --- .../modals/apiModal/utils/get-python-code.tsx | 17 +++++++++++++++++ .../src/modals/apiModal/views/index.tsx | 2 +- src/frontend/src/utils/utils.ts | 18 ------------------ 3 files changed, 18 insertions(+), 19 deletions(-) create mode 100644 src/frontend/src/modals/apiModal/utils/get-python-code.tsx diff --git a/src/frontend/src/modals/apiModal/utils/get-python-code.tsx b/src/frontend/src/modals/apiModal/utils/get-python-code.tsx new file mode 100644 index 000000000..d5327c3e7 --- /dev/null +++ b/src/frontend/src/modals/apiModal/utils/get-python-code.tsx @@ -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)`; + } diff --git a/src/frontend/src/modals/apiModal/views/index.tsx b/src/frontend/src/modals/apiModal/views/index.tsx index 26b9d765f..bf45d9eae 100644 --- a/src/frontend/src/modals/apiModal/views/index.tsx +++ b/src/frontend/src/modals/apiModal/views/index.tsx @@ -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( ( diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 7bd08208d..4e15fc4ad 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -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.