fix: update curl code generation (#3191)

* refactor: update getCurlRunCode to use useFlowStore for inputs and outputs

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* [autofix.ci] apply automated fixes

---------

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
anovazzi1 2024-08-05 11:16:16 -03:00 committed by GitHub
commit dd3a92b196
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: <your api key>'\\` : ""
}
-d '{"input_value": "message",
"output_type": "chat",
"input_type": "chat",
"output_type": ${hasChatOutput ? "chat" : "text"},
"input_type": ${hasChatInput ? "chat" : "text"},
"tweaks": ${tweaksString}}'
`;
}