Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cURL command in API section is not accurate #3377

Closed
maxpaynebupt opened this issue Aug 16, 2024 · 3 comments
Closed

cURL command in API section is not accurate #3377

maxpaynebupt opened this issue Aug 16, 2024 · 3 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@maxpaynebupt
Copy link
Contributor

Bug Description

the example's output_type value should be quoted.

image

Reproduction

setup a flow , and try to call it.

Expected behavior

copy the command and paste it should be OK to run.

Who can help?

No response

Operating System

Docker image v1.0.15

Langflow Version

v1.0.15

Python Version

None

Screenshot

No response

Flow File

No response

@maxpaynebupt maxpaynebupt added the bug Something isn't working label Aug 16, 2024
@dosubot dosubot bot added the documentation Improvements or additions to documentation label Aug 16, 2024
Copy link

dosubot bot commented Aug 16, 2024

The cURL command example in the API section should indeed quote the output_type value in the JSON payload. Here is the corrected version of the getCurlRunCode function:

import useFlowStore from "@/stores/flowStore";

/**
 * Function to get the curl code for the API
 * @param {string} flowId - The id of the flow
 * @param {boolean} isAuth - If the API is authenticated
 * @returns {string} - The curl code
 */
export function getCurlRunCode(
  flowId: string,
  isAuth: boolean,
  tweaksBuildedObject?: {},
  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
  return `curl -X POST \\
    "${window.location.protocol}//${window.location.host}/api/v1/run/${
      endpointName || flowId
    }?stream=false" \\
    -H 'Content-Type: application/json'\\${
      !isAuth ? `\n  -H 'x-api-key: <your api key>'\\` : ""
    }
    -d '{"input_value": "message",
    "output_type": "${hasChatOutput ? 'chat' : 'text'}",
    "input_type": "${hasChatInput ? 'chat' : 'text'}",
    "tweaks": ${tweaksString}}'
    `;
}

/**
 * Generates a cURL command for making a POST request to a webhook endpoint.
 *
 * @param {Object} options - The options for generating the cURL command.
 * @param {string} options.flowId - The ID of the flow.
 * @param {boolean} options.isAuth - Indicates whether authentication is required.
 * @param {string} options.endpointName - The name of the webhook endpoint.
 * @returns {string} The cURL command.
 */
export function getCurlWebhookCode(
  flowId,
  isAuth,
  endpointName?: string | null,
) {
  return `curl -X POST \\
  "${window.location.protocol}//${window.location.host}/api/v1/webhook/${
    endpointName || flowId
  }" \\
  -H 'Content-Type: application/json'\\${
    !isAuth ? `\n  -H 'x-api-key: <your api key>'\\` : ""
  }
  -d '{"any": "data"}'
  `;
}

This update ensures that the output_type value is correctly quoted in the JSON payload [1].

To continue talking to Dosu, mention @dosu.

@uladkaminski
Copy link
Contributor

Issue was recently fixed by #3337

@carlosrcoelho
Copy link
Contributor

#3337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants