From 187724342fb018d6ad7544cc7a227683a4dd4125 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 21 Sep 2023 19:09:02 -0300 Subject: [PATCH] update message format to put api-key as header --- src/frontend/src/utils/utils.ts | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index aa0825986..111b1ce51 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -326,7 +326,9 @@ TWEAKS = ${ : JSON.stringify(tweaks, null, 2) } -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 ? `, apiKey: str=""` : "" + }) -> dict: """ Run a flow with a given message and optional tweaks. @@ -337,18 +339,20 @@ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${!isAuth """ api_url = f"{BASE_API_URL}/{flow_id}" - payload = {"inputs": inputs${!isAuth ? `, "api_key": apiKey` : ""}} + payload = {"inputs": inputs} if tweaks: payload["tweaks"] = tweaks - - response = requests.post(api_url, json=payload) + ${!isAuth ? 'headers = {"api-key": apiKey}' : ""} + 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 ? `, api_key` : ""}))`; +${!isAuth ? `api_key = ""` : ""} +print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${ + !isAuth ? `, apiKey=api_key` : "" + }))`; } /** @@ -370,8 +374,9 @@ export function getCurlCode( ${window.location.protocol}//${ window.location.host }/api/v1/process/${flowId} \\ - -H 'Content-Type: application/json' \\ - -d '{"inputs": ${inputs},${!isAuth ? ` "api_key": "...", ` : " "}"tweaks": ${ + -H 'Content-Type: application/json'\\ + ${!isAuth ? `-H 'api-key: '\\` : ""} + -d '{"inputs": ${inputs}, "tweaks": ${ tweak && tweak.length > 0 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2) @@ -408,7 +413,11 @@ flow(inputs)`; * @param {string} flow - The current flow. * @returns {string} - The widget code */ -export function getWidgetCode(flow: FlowType, isAuth: boolean, tabsState?: TabsState): string { +export function getWidgetCode( + flow: FlowType, + isAuth: boolean, + tabsState?: TabsState +): string { const flowId = flow.id; const flowName = flow.name; const inputs = buildInputs(tabsState!, flow.id); @@ -428,9 +437,12 @@ chat_input_field: Input key that you want the chat to send the user message with chat_input_field="${chat_input_field}" ` : "" - }host_url="http://localhost:7860"${(!isAuth ? ` + }host_url="http://localhost:7860"${ + !isAuth + ? ` api_key="..."` - : "")} + : "" + } >`; }