Refactor: move getPythonCode to apiModal folder
This commit is contained in:
parent
9bd70b2616
commit
69f3b16fb7
3 changed files with 18 additions and 19 deletions
17
src/frontend/src/modals/apiModal/utils/get-python-code.tsx
Normal file
17
src/frontend/src/modals/apiModal/utils/get-python-code.tsx
Normal 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)`;
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,6 @@ import { TemplateVariableType } from "../../../types/api";
|
||||||
import { uniqueTweakType } from "../../../types/components";
|
import { uniqueTweakType } from "../../../types/components";
|
||||||
import { FlowType } from "../../../types/flow/index";
|
import { FlowType } from "../../../types/flow/index";
|
||||||
import {
|
import {
|
||||||
getPythonCode,
|
|
||||||
getWidgetCode,
|
getWidgetCode,
|
||||||
tabsArray,
|
tabsArray,
|
||||||
} from "../../../utils/utils";
|
} from "../../../utils/utils";
|
||||||
|
|
@ -27,6 +26,7 @@ import { getNodesWithDefaultValue } from "../utils/get-nodes-with-default-value"
|
||||||
import { getValue } from "../utils/get-value";
|
import { getValue } from "../utils/get-value";
|
||||||
import getPythonApiCode from "../utils/get-python-api-code";
|
import getPythonApiCode from "../utils/get-python-api-code";
|
||||||
import getCurlCode from "../utils/get-curl-code";
|
import getCurlCode from "../utils/get-curl-code";
|
||||||
|
import getPythonCode from "../utils/get-python-code";
|
||||||
|
|
||||||
const ApiModal = forwardRef(
|
const ApiModal = forwardRef(
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -158,24 +158,6 @@ export function getOutputIds(flow) {
|
||||||
return arrayOfOutputsJoin;
|
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
|
* Function to get the widget code for the API
|
||||||
* @param {string} flow - The current flow.
|
* @param {string} flow - The current flow.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue