refactor: Update WebhookComponent to use MultilineInput for data field

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-20 21:27:18 -03:00
commit 2e1bc10661

View file

@ -114,7 +114,7 @@
"list": false,
"show": true,
"multiline": true,
"value": "import json\n\nfrom langflow.custom import Component\nfrom langflow.io import TextInput\nfrom langflow.schema import Data\nfrom langflow.io import Output\n\n\nclass WebhookComponent(Component):\n display_name = \"Webhook Input\"\n description = \"Defines a webhook input for the flow.\"\n\n inputs = [\n TextInput(\n name=\"data\",\n display_name=\"Data\",\n info=\"Use this field to quickly test the webhook component by providing a JSON payload.\",\n multiline=True,\n )\n ]\n outputs = [\n Output(display_name=\"Data\", name=\"output_data\", method=\"build_data\"),\n ]\n\n def build_data(self) -> Data:\n message = \"\"\n if not self.data:\n self.status = \"No data provided.\"\n return Data(data={})\n try:\n body = json.loads(self.data or \"{}\")\n except json.JSONDecodeError:\n body = {\"payload\": self.data}\n message = f\"Invalid JSON payload. Please check the format.\\n\\n{self.data}\"\n data = Data(data=body)\n if not message:\n message = data\n self.status = message\n return data\n",
"value": "import json\n\nfrom langflow.custom import Component\nfrom langflow.io import MultilineInput\nfrom langflow.schema import Data\nfrom langflow.io import Output\n\n\nclass WebhookComponent(Component):\n display_name = \"Webhook Input\"\n description = \"Defines a webhook input for the flow.\"\n\n inputs = [\n MultilineInput(\n name=\"data\",\n display_name=\"Data\",\n info=\"Use this field to quickly test the webhook component by providing a JSON payload.\",\n multiline=True,\n )\n ]\n outputs = [\n Output(display_name=\"Data\", name=\"output_data\", method=\"build_data\"),\n ]\n\n def build_data(self) -> Data:\n message = \"\"\n if not self.data:\n self.status = \"No data provided.\"\n return Data(data={})\n try:\n body = json.loads(self.data or \"{}\")\n except json.JSONDecodeError:\n body = {\"payload\": self.data}\n message = f\"Invalid JSON payload. Please check the format.\\n\\n{self.data}\"\n data = Data(data=body)\n if not message:\n message = data\n self.status = message\n return data\n",
"fileTypes": [],
"file_path": "",
"password": false,