From 8deeeb5ba38d99cf333a7f73d14f35eae01a67ef Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 26 Sep 2023 11:45:12 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(utils.ts):=20change=20parame?= =?UTF-8?q?ter=20name=20from=20apiKey=20to=20api=5Fkey=20to=20improve=20co?= =?UTF-8?q?nsistency=20and=20readability=20=E2=9C=A8=20feat(utils.ts):=20a?= =?UTF-8?q?dd=20support=20for=20x-api-key=20header=20in=20run=5Fflow=20fun?= =?UTF-8?q?ction=20to=20pass=20the=20API=20key=20as=20a=20header=20instead?= =?UTF-8?q?=20of=20a=20query=20parameter=20=F0=9F=94=A7=20chore(utils.ts):?= =?UTF-8?q?=20update=20getCurlCode=20function=20to=20use=20x-api-key=20hea?= =?UTF-8?q?der=20instead=20of=20api-key=20header=20for=20authentication?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/utils.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 111b1ce51..f06a8f63c 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -327,7 +327,7 @@ TWEAKS = ${ } def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${ - !isAuth ? `, apiKey: str=""` : "" + !isAuth ? `, api_key: Optional[str] = None` : "" }) -> dict: """ Run a flow with a given message and optional tweaks. @@ -340,18 +340,19 @@ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${ api_url = f"{BASE_API_URL}/{flow_id}" payload = {"inputs": inputs} - + headers = None if tweaks: payload["tweaks"] = tweaks - ${!isAuth ? 'headers = {"api-key": apiKey}' : ""} - response = requests.post(api_url, json=payload,headers=headers) + if api_key: + headers = {"x-api-key": api_key} + response = requests.post(api_url, json=payload, headers=headers) return response.json() # Setup any tweaks you want to apply to the flow inputs = ${inputs} ${!isAuth ? `api_key = ""` : ""} print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${ - !isAuth ? `, apiKey=api_key` : "" + !isAuth ? `, api_key=api_key` : "" }))`; } @@ -374,8 +375,9 @@ export function getCurlCode( ${window.location.protocol}//${ window.location.host }/api/v1/process/${flowId} \\ - -H 'Content-Type: application/json'\\ - ${!isAuth ? `-H 'api-key: '\\` : ""} + -H 'Content-Type: application/json'\\${ + !isAuth ? `\n -H 'x-api-key: '\\` : "" + } -d '{"inputs": ${inputs}, "tweaks": ${ tweak && tweak.length > 0 ? buildTweakObject(tweak) @@ -443,7 +445,7 @@ chat_input_field: Input key that you want the chat to send the user message with api_key="..."` : "" } - + >`; }