From 512b499915e8b24a9675cf9b0d35e6d5321a7bd3 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 7 Jul 2023 13:51:16 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(constants.tsx):=20add=20suppor?= =?UTF-8?q?t=20for=20dynamic=20inputs=20in=20getPythonApiCode=20and=20getC?= =?UTF-8?q?urlCode=20functions=20In=20the=20getPythonApiCode=20function,?= =?UTF-8?q?=20the=20run=5Fflow=20function=20had=20an=20unnecessary=20type?= =?UTF-8?q?=20annotation=20for=20the=20message=20parameter.=20It=20was=20r?= =?UTF-8?q?emoved=20to=20improve=20code=20readability.=20Additionally,=20t?= =?UTF-8?q?he=20variable=20name=20in=20the=20run=5Fflow=20function=20was?= =?UTF-8?q?=20changed=20from=20inputs=20to=20payload=20to=20better=20refle?= =?UTF-8?q?ct=20its=20purpose.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the getCurlCode function, support for dynamic inputs was added. The inputs variable is now passed as an argument to the flow function, allowing for flexibility in providing different inputs when generating the curl code. 🐛 fix(constants.tsx): remove unnecessary type annotation and fix variable name in run_flow function --- src/frontend/src/constants.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/constants.tsx b/src/frontend/src/constants.tsx index a31074a16..8c14f919c 100644 --- a/src/frontend/src/constants.tsx +++ b/src/frontend/src/constants.tsx @@ -85,6 +85,7 @@ export const getPythonApiCode = ( const tweaks = buildTweaks(flow); const inputs = buildInputs(tabsState, flow.id); return `import requests + from typing import Optional BASE_API_URL = "${window.location.protocol}//${ window.location.host @@ -98,7 +99,7 @@ TWEAKS = ${ : JSON.stringify(tweaks, null, 2) } -def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict: +def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None) -> dict: """ Run a flow with a given message and optional tweaks. @@ -109,7 +110,7 @@ def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict: """ api_url = f"{BASE_API_URL}/{flow_id}" - payload = {"inputs": ${inputs}} + payload = {"inputs": inputs} if tweaks: payload["tweaks"] = tweaks @@ -118,8 +119,8 @@ def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict: return response.json() # Setup any tweaks you want to apply to the flow - -print(run_flow("Your message", flow_id=FLOW_ID, tweaks=TWEAKS))`; +inputs = ${inputs} +print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS))`; }; /** * Function to get the curl code for the API @@ -134,6 +135,7 @@ export const getCurlCode = ( const flowId = flow.id; const tweaks = buildTweaks(flow); const inputs = buildInputs(tabsState, flow.id); + return `curl -X POST \\ ${window.location.protocol}//${ window.location.host @@ -166,7 +168,8 @@ TWEAKS = ${ } flow = load_flow_from_json("${flowName}.json", tweaks=TWEAKS) # Now you can use it like any chain -flow(${inputs})`; +inputs = ${inputs} +flow(inputs)`; }; function buildTweakObject(tweak) {