From dd3a92b1966f6739f2437b12e00a2f1b94feb8ae Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 5 Aug 2024 11:16:16 -0300 Subject: [PATCH] fix: update curl code generation (#3191) * refactor: update getCurlRunCode to use useFlowStore for inputs and outputs Co-authored-by: Gabriel Luiz Freitas Almeida * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../src/modals/apiModal/utils/get-curl-code.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx b/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx index 9f7b5aa75..b60b8c31b 100644 --- a/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx +++ b/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx @@ -1,3 +1,5 @@ +import useFlowStore from "@/stores/flowStore"; + /** * Function to get the curl code for the API * @param {string} flowId - The id of the flow @@ -11,6 +13,10 @@ export function getCurlRunCode( endpointName?: string | null, ): string { let tweaksString = "{}"; + const inputs = useFlowStore.getState().inputs; + const outputs = useFlowStore.getState().outputs; + const hasChatInput = inputs.some((input) => input.type === "ChatInput"); + const hasChatOutput = outputs.some((output) => output.type === "ChatOutput"); if (tweaksBuildedObject) tweaksString = JSON.stringify(tweaksBuildedObject, null, 2); // show the endpoint name in the curl command if it exists @@ -22,8 +28,8 @@ export function getCurlRunCode( !isAuth ? `\n -H 'x-api-key: '\\` : "" } -d '{"input_value": "message", - "output_type": "chat", - "input_type": "chat", + "output_type": ${hasChatOutput ? "chat" : "text"}, + "input_type": ${hasChatInput ? "chat" : "text"}, "tweaks": ${tweaksString}}' `; }