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
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-07-18 14:22:45 -03:00 committed by GitHub
commit f504bcc8c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -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"]:

View file

@ -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,