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

Issue with TWEAKS

lgertel opened this issue · comments

Describe the bug
Issue calling tweaks Dict.

I'm not able to config a tweak that is not a dictionary. I'm on 1-alpha.

import requests
from typing import Optional

BASE_API_URL = "xxxxxx"
FLOW_ID = "c6cd55fb-f6a5-41b1-bdf4-45abec02f144"

TWEAKS = {
  "TextInput-DrjBW": {
    "input_value": "ALURA"
  },
  "TextInput-10yXf": {
      "input_value": "Spring Java Dev"
  },
  "CreateRecord-fL5ax": {
    "field_1_key": {
      "url": "https://s3.us-east-1.amazonaws.com"
    }
  },
}

TWEAKS = {
  "Prompt-mEN0d": {},
  "ChatOutput-Q5GTP": {},
  "TextInput-DrjBW": {},
  "TextInput-10yXf": {},
  "APIRequest-NxjG2": {},
  "CreateRecord-fL5ax": {
    "field_1_key": {
      "url": "https://s3.us-east-1.amazonaws.com/"
    }
  },
  "RecordsToText-ST8PA": {},
  "OpenAIModel-xveiE": {}
}

def run_flow(message: str,
  flow_id: str,
  output_type: str = "chat",
  input_type: str = "chat",
  tweaks: Optional[dict] = None,
  api_key: Optional[str] = None) -> dict:
  
    api_url = f"{BASE_API_URL}/{flow_id}"

    payload = {
        "input_value": message,
        "output_type": output_type,
        "input_type": input_type,
    }
    headers = None
    if tweaks:
        payload["tweaks"] = tweaks
    if api_key:
        headers = {"x-api-key": api_key}
    response = requests.post(api_url, json=payload, headers=headers)
    return response.json()


message = "message"

print(run_flow(message=message, flow_id=FLOW_ID, tweaks=TWEAKS))

This is the error:
{'detail': [{'type': 'string_type', 'loc': ['body', 'tweaks', 'CreateRecord-fL5ax', 'str'], 'msg': 'Input should be a valid string', 'input': {'field_1_key': {'url': 'https://s3.us-east-1.amazonaws.com/'}}}, {'type': 'string_type', 'loc': ['body', 'tweaks', 'CreateRecord-fL5ax', 'dict[str,str]', 'field_1_key'], 'msg': 'Input should be a valid string', 'input': {'url': 'https://s3.us-east-1.amazonaws.com/'}}]}

I think you have used Tweaks twice.

import requests
from typing import Optional

BASE_API_URL = "https://brave-strength-production.up.railway.app/api/v1/run"
FLOW_ID = "c6cd55fb-f6a5-41b1-bdf4-45abec02f144"
# You can tweak the flow by adding a tweaks dictionary
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
TWEAKS = {
  "TextInput-DrjBW": {
    "input_value": "ALURA"
  },
  "TextInput-10yXf": {
      "input_value": "Spring Java Dev"
  },
  "CreateRecord-fL5ax": {
    "field_1_key": {
      "url": "https://s3.us-east-1.amazonaws.com/ac-genai-platform-develop-bucket/public/workspaces/cltiv6yy80001nw53od7bkois/typebots/clvd4lrf4000ofwhor6s660ek/results/evdred6xvd62l0jzpzh7c25o/Curri%CC%81culo%20-%20Matheus%20Pedroni.pdf"
    }
  },
}

def run_flow(message: str,
  flow_id: str,
  output_type: str = "chat",
  input_type: str = "chat",
  tweaks: Optional[dict] = None,
  api_key: Optional[str] = None) -> dict:
    """
    Run a flow with a given message and optional tweaks.

    :param message: The message to send to the flow
    :param flow_id: The ID of the flow to run
    :param tweaks: Optional tweaks to customize the flow
    :return: The JSON response from the flow
    """
    api_url = f"{BASE_API_URL}/{flow_id}"

    payload = {
        "input_value": message,
        "output_type": output_type,
        "input_type": input_type,
    }
    headers = None
    if tweaks:
        payload["tweaks"] = tweaks
    if api_key:
        headers = {"x-api-key": api_key}
    response = requests.post(api_url, json=payload, headers=headers)
    return response.json()

# Setup any tweaks you want to apply to the flow
message = "message"

print(run_flow(message=message, flow_id=FLOW_ID, tweaks=TWEAKS))
{'detail': [{'type': 'string_type', 'loc': ['body', 'tweaks', 'CreateRecord-fL5ax', 'str'], 'msg': 'Input should be a valid string', 'input': {'field_1_key': {'url': 'https://s3.us-east-1.amazonaws.com/ac-genai-platform-develop-bucket/public/workspaces/cltiv6yy80001nw53od7bkois/typebots/clvd4lrf4000ofwhor6s660ek/results/evdred6xvd62l0jzpzh7c25o/Curri%CC%81culo%20-%20Matheus%20Pedroni.pdf'}}}, {'type': 'string_type', 'loc': ['body', 'tweaks', 'CreateRecord-fL5ax', 'dict[str,str]', 'field_1_key'], 'msg': 'Input should be a valid string', 'input': {'url': 'https://s3.us-east-1.amazonaws.com/ac-genai-platform-develop-bucket/public/workspaces/cltiv6yy80001nw53od7bkois/typebots/clvd4lrf4000ofwhor6s660ek/results/evdred6xvd62l0jzpzh7c25o/Curri%CC%81culo%20-%20Matheus%20Pedroni.pdf'}}]}

Ok. I think this might be a validation bug. I'll take a look.

Thanks @lgertel and @yamonkjd

Let us know if you find anything else

Hey all

This fix will be in release 1.0.0a27