fix(get-python-api-code):fixing errors in a file uploading flow, as in issue #2799 (#2815)

fixing errors in a file uploading flow, as in issue #2799

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
Mike Manh 2024-08-09 18:53:39 -04:00 • committed by GitHub
commit 583bc74019
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -22,7 +22,7 @@ def upload(file_path, host, flow_id):
url = f"{host}/api/v1/upload/{flow_id}" url = f"{host}/api/v1/upload/{flow_id}"
with open(file_path, "rb") as file: with open(file_path, "rb") as file:
response = httpx.post(url, files={"file": file}) response = httpx.post(url, files={"file": file})
if response.status_code == 200: if response.status_code == 200 or response.status_code == 201:
return response.json() return response.json()
else: else:
raise Exception(f"Error uploading file: {response.status_code}") raise Exception(f"Error uploading file: {response.status_code}")
@ -55,7 +55,7 @@ def upload_file(file_path: str, host: str, flow_id: str, components: list[str],
if response["file_path"]: if response["file_path"]:
for component in components: for component in components:
if isinstance(component, str): if isinstance(component, str):
tweaks[component] = {"file_path": response["file_path"]} tweaks[component] = {"path": response["file_path"]}
else: else:
raise ValueError(f"Component ID or name must be a string. Got {type(component)}") raise ValueError(f"Component ID or name must be a string. Got {type(component)}")
return tweaks return tweaks

View file

@ -95,7 +95,7 @@ def main():
raise ImportError("Langflow is not installed. Please install it to use the upload_file function.") raise ImportError("Langflow is not installed. Please install it to use the upload_file function.")
elif not args.components: elif not args.components:
raise ValueError("You need to provide the components to upload the file to.") raise ValueError("You need to provide the components to upload the file to.")
tweaks = upload_file(file_path=args.upload_file, host=BASE_API_URL, flow_id=ENDPOINT, components=args.components, tweaks=tweaks) tweaks = upload_file(file_path=args.upload_file, host=BASE_API_URL, flow_id=args.endpoint, components=[args.components], tweaks=tweaks)
response = run_flow( response = run_flow(
message=args.message, message=args.message,