diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 5db600627..a3801d10e 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -134,18 +134,18 @@ export type TooltipComponentType = { children: ReactElement; title: string | ReactElement; placement?: - | "bottom-end" - | "bottom-start" - | "bottom" - | "left-end" - | "left-start" - | "left" - | "right-end" - | "right-start" - | "right" - | "top-end" - | "top-start" - | "top"; + | "bottom-end" + | "bottom-start" + | "bottom" + | "left-end" + | "left-start" + | "left" + | "right-end" + | "right-start" + | "right" + | "top-end" + | "top-start" + | "top"; }; export type ProgressBarType = { diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index b9eca1588..a9b157c66 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -220,7 +220,8 @@ export function validateNode( ) ) { errors.push( - `${type} is missing ${template.display_name || toNormalCase(template[t].name) + `${type} is missing ${ + template.display_name || toNormalCase(template[t].name) }.` ); } else if ( @@ -233,12 +234,14 @@ export function validateNode( ) { if (hasDuplicateKeys(template[t].value)) errors.push( - `${type} (${template.display_name || template[t].name + `${type} (${ + template.display_name || template[t].name }) contains duplicate keys with the same values.` ); if (hasEmptyKey(template[t].value)) errors.push( - `${type} (${template.display_name || template[t].name + `${type} (${ + template.display_name || template[t].name }) field must not be empty.` ); } @@ -336,7 +339,6 @@ export function convertArrayToObj(arrayOfObjects) { return objConverted; } - export function hasDuplicateKeys(array) { const keys = {}; for (const obj of array) { diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 65eab3207..f06a8f63c 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -186,13 +186,13 @@ export function groupByFamily( return left ? arrOfPossibleOutputs.map((output) => ({ - family: output.category, - type: output.full ? "" : output.nodes.join(", "), - })) + family: output.category, + type: output.full ? "" : output.nodes.join(", "), + })) : arrOfPossibleInputs.map((input) => ({ - family: input.category, - type: input.full ? "" : input.nodes.join(", "), - })); + family: input.category, + type: input.full ? "" : input.nodes.join(", "), + })); } export function buildInputs(tabsState: TabsState, id: string): string { @@ -262,7 +262,7 @@ export function buildTweakObject(tweak: tweakType) { for (let kp in el[key]) { try { el[key][kp] = JSON.parse(el[key][kp]); - } catch { } + } catch {} } }); }); @@ -314,24 +314,21 @@ export function getPythonApiCode( return `import requests from typing import Optional -BASE_API_URL = "${window.location.protocol}//${window.location.host - }/api/v1/process" +BASE_API_URL = "${window.location.protocol}//${ + window.location.host + }/api/v1/process" FLOW_ID = "${flowId}" # You can tweak the flow by adding a tweaks dictionary # e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}} -TWEAKS = ${tweak && tweak.length > 0 +TWEAKS = ${ + tweak && tweak.length > 0 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2) - } + } -<<<<<<< HEAD -def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${!isAuth ? `, apiKey: str=""` : "" - }) -> dict: -======= def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${ !isAuth ? `, api_key: Optional[str] = None` : "" }) -> dict: ->>>>>>> 1773f3fda830988438e7f3e3aa40959f1df692f5 """ Run a flow with a given message and optional tweaks. @@ -354,14 +351,9 @@ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${ # Setup any tweaks you want to apply to the flow inputs = ${inputs} ${!isAuth ? `api_key = ""` : ""} -<<<<<<< HEAD -print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${!isAuth ? `, apiKey=api_key` : "" - }))`; -======= print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${ !isAuth ? `, api_key=api_key` : "" }))`; ->>>>>>> 1773f3fda830988438e7f3e3aa40959f1df692f5 } /** @@ -380,13 +372,6 @@ export function getCurlCode( const inputs = buildInputs(tabsState!, flow.id); return `curl -X POST \\ -<<<<<<< HEAD - ${window.location.protocol}//${window.location.host - }/api/v1/process/${flowId} \\ - -H 'Content-Type: application/json'\\ - ${!isAuth ? `-H 'api-key: '\\` : ""} - -d '{"inputs": ${inputs}, "tweaks": ${tweak && tweak.length > 0 -======= ${window.location.protocol}//${ window.location.host }/api/v1/process/${flowId} \\ @@ -395,10 +380,9 @@ export function getCurlCode( } -d '{"inputs": ${inputs}, "tweaks": ${ tweak && tweak.length > 0 ->>>>>>> 1773f3fda830988438e7f3e3aa40959f1df692f5 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2) - }}'`; + }}'`; } /** @@ -415,10 +399,11 @@ export function getPythonCode( const tweaks = buildTweaks(flow); const inputs = buildInputs(tabsState!, flow.id); return `from langflow import load_flow_from_json -TWEAKS = ${tweak && tweak.length > 0 +TWEAKS = ${ + tweak && tweak.length > 0 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2) - } + } flow = load_flow_from_json("${flowName}.json", tweaks=TWEAKS) # Now you can use it like any chain inputs = ${inputs} @@ -448,22 +433,19 @@ chat_input_field: Input key that you want the chat to send the user message with >>>>>> 1773f3fda830988438e7f3e3aa40959f1df692f5 >`; }