update message format to put api-key as header

This commit is contained in:
anovazzi1 2023-09-21 19:09:02 -03:00 • committed by anovazzi1
commit 187724342f

View file

@ -326,7 +326,9 @@ TWEAKS = ${
: JSON.stringify(tweaks, null, 2) : 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. 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}" api_url = f"{BASE_API_URL}/{flow_id}"
payload = {"inputs": inputs${!isAuth ? `, "api_key": apiKey` : ""}} payload = {"inputs": inputs}
if tweaks: if tweaks:
payload["tweaks"] = tweaks payload["tweaks"] = tweaks
${!isAuth ? 'headers = {"api-key": apiKey}' : ""}
response = requests.post(api_url, json=payload) response = requests.post(api_url, json=payload,headers=headers)
return response.json() return response.json()
# Setup any tweaks you want to apply to the flow # Setup any tweaks you want to apply to the flow
inputs = ${inputs} inputs = ${inputs}
${!isAuth ? `api_key = "..."` : ""} ${!isAuth ? `api_key = "<your api key>"` : ""}
print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${!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.protocol}//${
window.location.host window.location.host
}/api/v1/process/${flowId} \\ }/api/v1/process/${flowId} \\
-H 'Content-Type: application/json' \\ -H 'Content-Type: application/json'\\
-d '{"inputs": ${inputs},${!isAuth ? ` "api_key": "...", ` : " "}"tweaks": ${ ${!isAuth ? `-H 'api-key: <your api key>'\\` : ""}
-d '{"inputs": ${inputs}, "tweaks": ${
tweak && tweak.length > 0 tweak && tweak.length > 0
? buildTweakObject(tweak) ? buildTweakObject(tweak)
: JSON.stringify(tweaks, null, 2) : JSON.stringify(tweaks, null, 2)
@ -408,7 +413,11 @@ flow(inputs)`;
* @param {string} flow - The current flow. * @param {string} flow - The current flow.
* @returns {string} - The widget code * @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 flowId = flow.id;
const flowName = flow.name; const flowName = flow.name;
const inputs = buildInputs(tabsState!, flow.id); 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}" chat_input_field="${chat_input_field}"
` `
: "" : ""
}host_url="http://localhost:7860"${(!isAuth ? ` }host_url="http://localhost:7860"${
!isAuth
? `
api_key="..."` api_key="..."`
: "")} : ""
}
></langflow-chat>`; ></langflow-chat>`;
} }