langflow-ai / langflow

⛓️ Langflow is a visual framework for building multi-agent and RAG applications. It's open-source, Python-powered, fully customizable, model and vector store agnostic.

Home Page:http://www.langflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TWEAKS never work via API

mihit opened this issue · comments

Describe the bug
TWEAKS looks never work.

Browser and Version

  • chrome 125.0.6422.144

To Reproduce

  1. Write a flow has a OpenAI component.
  2. Generate python API code from the flow.
  3. Modify the code's TWEAK like this.
    "OpenAIModel-*****": {"max_tokens": "10"},
  4. Call the API code. It doesn't affected by the TWEAK.

Not only OpenAI component, but also other components seems doesn't work.

@mihit Hello there! I'm a bot here to help you with any bugs, questions, or contributions you might have. Let's work together to solve this issue.

The issue with TWEAKS not working when modifying components like OpenAI in the generated Python API code is likely due to the tweaksBuildedObject not being correctly populated or passed. The code expects tweaksBuildedObject to be an array with at least one object, and it uses only the first object in the array. If tweaksBuildedObject is empty or not correctly formatted, the tweaks will not be applied.

Here is the relevant part of the code:

/**
 * Function to get the python code for the API
 * @param {string} flow - The current flow
 * @param {any[]} tweaksBuildedObject - The tweaks
 * @returns {string} - The python code
 */
export default function getPythonCode(
  flowName: string,
  tweaksBuildedObject: any[]
): string {
  let tweaksString = "{}";
  if (tweaksBuildedObject && tweaksBuildedObject.length > 0) {
    const tweaksObject = tweaksBuildedObject[0];
    if (!tweaksObject) {
      throw new Error("expected tweaks");
    }
    tweaksString = JSON.stringify(tweaksObject, null, 2)
      .replace(/true/g, "True")
      .replace(/false/g, "False");
  }

  return `from langflow.load import run_flow_from_json
TWEAKS = ${tweaksString}

result = run_flow_from_json(flow="${flowName}.json",
                            input_value="message",
                            fallback_to_env_vars=True, # False by default
                            tweaks=TWEAKS)`;
}

Ensure that tweaksBuildedObject is correctly populated with the necessary tweaks before calling this function [1][2].

To continue talking to Dosu, mention @dosu.

commented

@ogabrielluiz
[v1.0.0a53] did not work, but [v1.0.0a59] seems fixed it. OK, now I can send user's id as session id. Nice dev!👍