From 8980e757235bcdc29d000d889e713878a6c541f9 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa <72977554+Cristhianzl@users.noreply.github.com> Date: Thu, 4 Jul 2024 09:05:22 -0300 Subject: [PATCH] bugfix: fix api request custom component (#2470) * bugfix: fix api request custom component * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .github/workflows/auto-update.yml | 2 +- .github/workflows/docs_test.yml | 1 - .github/workflows/js_autofix.yml | 2 +- .github/workflows/lint-js.yml | 2 -- .github/workflows/py_autofix.yml | 2 +- .github/workflows/style-check-py.yml | 3 --- README.md | 3 ++- .../base/langflow/components/data/APIRequest.py | 12 ++++++++++-- src/backend/base/langflow/graph/vertex/base.py | 7 ++++++- src/backend/base/langflow/inputs/inputs.py | 2 +- 10 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index eea2f09efc4..1d46fa1758f 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -10,4 +10,4 @@ jobs: name: Auto-update runs-on: ubuntu-latest steps: - - uses: tibdex/auto-update@v2 \ No newline at end of file + - uses: tibdex/auto-update@v2 diff --git a/.github/workflows/docs_test.yml b/.github/workflows/docs_test.yml index 2792017b46c..e0adfda800e 100644 --- a/.github/workflows/docs_test.yml +++ b/.github/workflows/docs_test.yml @@ -12,7 +12,6 @@ on: env: NODE_VERSION: "21" - jobs: test-docs-build: name: Test Docs Build diff --git a/.github/workflows/js_autofix.yml b/.github/workflows/js_autofix.yml index 205bc2c0153..30f3d9c1a92 100644 --- a/.github/workflows/js_autofix.yml +++ b/.github/workflows/js_autofix.yml @@ -43,4 +43,4 @@ jobs: cd src/frontend npm run format - - uses: autofix-ci/action@dd55f44df8f7cdb7a6bf74c78677eb8acd40cd0a \ No newline at end of file + - uses: autofix-ci/action@dd55f44df8f7cdb7a6bf74c78677eb8acd40cd0a diff --git a/.github/workflows/lint-js.yml b/.github/workflows/lint-js.yml index d7f79738dac..892347312f3 100644 --- a/.github/workflows/lint-js.yml +++ b/.github/workflows/lint-js.yml @@ -51,5 +51,3 @@ jobs: run: | cd src/frontend npm run check-format - - diff --git a/.github/workflows/py_autofix.yml b/.github/workflows/py_autofix.yml index 0ce1eecd475..4e24802f84b 100644 --- a/.github/workflows/py_autofix.yml +++ b/.github/workflows/py_autofix.yml @@ -26,4 +26,4 @@ jobs: - run: ruff check --fix-only . - run: ruff format . - - uses: autofix-ci/action@dd55f44df8f7cdb7a6bf74c78677eb8acd40cd0a \ No newline at end of file + - uses: autofix-ci/action@dd55f44df8f7cdb7a6bf74c78677eb8acd40cd0a diff --git a/.github/workflows/style-check-py.yml b/.github/workflows/style-check-py.yml index a7886b95006..dfab075ce67 100644 --- a/.github/workflows/style-check-py.yml +++ b/.github/workflows/style-check-py.yml @@ -33,6 +33,3 @@ jobs: run: echo "::add-matcher::.github/workflows/matchers/ruff.json" - name: Run Ruff Check run: poetry run ruff check --output-format=github . - - - diff --git a/README.md b/README.md index c21ab76350b..ebeaac40d25 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,11 @@ results = run_flow_from_json("path/to/flow.json", input_value="Hello, World!") # Deploy ## DataStax Langflow + DataStax Langflow is a hosted version of Langflow integrated with [AstraDB](https://www.datastax.com/products/datastax-astra). Be up and running in minutes with no installation or setup required. [Sign up for free](https://langflow.datastax.com). ## Deploy Langflow on Hugging Face Spaces + You can also preview Langflow in [HuggingFace Spaces](https://huggingface.co/spaces/Langflow/Langflow-Preview). [Clone the space using this link](https://huggingface.co/spaces/Langflow/Langflow-Preview?duplicate=true) to create your own Langflow workspace in minutes. ## Deploy Langflow on Google Cloud Platform @@ -121,7 +123,6 @@ Use this template to deploy Langflow 1.0 on Railway: Follow our step-by-step guide to deploy [Langflow on Kubernetes](https://github.com/langflow-ai/langflow/blob/dev/docs/docs/deployment/kubernetes.md). - # 🖥️ Command Line Interface (CLI) Langflow provides a command-line interface (CLI) for easy management and configuration. diff --git a/src/backend/base/langflow/components/data/APIRequest.py b/src/backend/base/langflow/components/data/APIRequest.py index a7908ae2172..8a1656a587f 100644 --- a/src/backend/base/langflow/components/data/APIRequest.py +++ b/src/backend/base/langflow/components/data/APIRequest.py @@ -112,10 +112,18 @@ async def make_request( if method not in ["GET", "POST", "PATCH", "PUT", "DELETE"]: raise ValueError(f"Unsupported method: {method}") + if isinstance(body, str) and body: + try: + body = json.loads(body) + except Exception as e: + logger.error(f"Error decoding JSON data: {e}") + body = None + raise ValueError(f"Error decoding JSON data: {e}") + data = body if body else None - payload = json.dumps(data) if data else None + try: - response = await client.request(method, url, headers=headers, content=payload, timeout=timeout) + response = await client.request(method, url, headers=headers, json=data, timeout=timeout) try: result = response.json() except Exception: diff --git a/src/backend/base/langflow/graph/vertex/base.py b/src/backend/base/langflow/graph/vertex/base.py index 9c657de8d06..a3ad19dc225 100644 --- a/src/backend/base/langflow/graph/vertex/base.py +++ b/src/backend/base/langflow/graph/vertex/base.py @@ -280,7 +280,12 @@ def _build_params(self): # we don't know the key of the dict but we need to set the value # to the vertex that is the source of the edge param_dict = template_dict[param_key]["value"] - params[param_key] = {key: self.graph.get_vertex(edge.source_id) for key in param_dict.keys()} + if param_dict: + params[param_key] = { + key: self.graph.get_vertex(edge.source_id) for key in param_dict.keys() + } + else: + params[param_key] = self.graph.get_vertex(edge.source_id) else: params[param_key] = self.graph.get_vertex(edge.source_id) diff --git a/src/backend/base/langflow/inputs/inputs.py b/src/backend/base/langflow/inputs/inputs.py index b88c5db7a27..4578660dc60 100644 --- a/src/backend/base/langflow/inputs/inputs.py +++ b/src/backend/base/langflow/inputs/inputs.py @@ -253,7 +253,7 @@ class NestedDictInput(BaseInputMixin, ListableInputMixin, MetadataTraceMixin, In """ field_type: Optional[SerializableFieldTypes] = FieldTypes.NESTED_DICT - value: Optional[dict] = {} + value: Optional[dict | Data] = {} class DictInput(BaseInputMixin, ListableInputMixin, InputTraceMixin):