From f504bcc8c2d7f3b5e41e30254c3c7223d9028544 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 18 Jul 2024 14:22:45 -0300 Subject: [PATCH] fix(get-python-api-code): set the endpoint in the correct variable (#2800) * feat: refactor upload_file function to handle optional tweaks parameter Refactor the upload_file function in utils.py to handle the optional tweaks parameter. If the tweaks parameter is not provided, it is set to an empty dictionary. This change improves the flexibility and usability of the function. * fix(get-python-api-code): set the endpoint in the correct variable --- src/backend/base/langflow/load/utils.py | 4 +++- .../src/modals/apiModal/utils/get-python-api-code.tsx | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/load/utils.py b/src/backend/base/langflow/load/utils.py index 9c2918e91..4012bc934 100644 --- a/src/backend/base/langflow/load/utils.py +++ b/src/backend/base/langflow/load/utils.py @@ -29,7 +29,7 @@ def upload(file_path, host, flow_id): raise Exception(f"Error uploading file: {e}") -def upload_file(file_path, host, flow_id, components, tweaks={}): +def upload_file(file_path: str, host: str, flow_id: str, components: list[str], tweaks: dict | None = None): """ Upload a file to Langflow and return the file path. @@ -47,6 +47,8 @@ def upload_file(file_path, host, flow_id, components, tweaks={}): Raises: Exception: If an error occurs during the upload process. """ + if not tweaks: + tweaks = {} try: response = upload(file_path, host, flow_id) if response["file_path"]: diff --git a/src/frontend/src/modals/apiModal/utils/get-python-api-code.tsx b/src/frontend/src/modals/apiModal/utils/get-python-api-code.tsx index 224d1d711..813e0fb72 100644 --- a/src/frontend/src/modals/apiModal/utils/get-python-api-code.tsx +++ b/src/frontend/src/modals/apiModal/utils/get-python-api-code.tsx @@ -35,7 +35,7 @@ except ImportError: warnings.warn("Langflow provides a function to help you upload files to the flow. Please install langflow to use it.") upload_file = None -BASE_API_URL = "${window.location.protocol}//${window.location.host}/api/v1/run" +BASE_API_URL = "${window.location.protocol}//${window.location.host}" FLOW_ID = "${flowId}" ENDPOINT = "${endpointName || ""}" ${ endpointName @@ -61,7 +61,7 @@ def run_flow(message: str, :param tweaks: Optional tweaks to customize the flow :return: The JSON response from the flow """ - api_url = f"{BASE_API_URL}/{endpoint}" + api_url = f"{BASE_API_URL}/api/v1/run/{endpoint}" payload = { "input_value": message,