Created
October 22, 2023 16:07
-
-
Save rodrigosnader/ee08e30597b067d6aa3cb53335d6e1d1 to your computer and use it in GitHub Desktop.
Transform Chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"Transform Chain","description":"Transform Your Business with Smart Dialogues.","data":{"nodes":[{"width":384,"height":539,"id":"CustomComponent-C8eNm","type":"genericNode","position":{"x":361.2179541318329,"y":14.576073295690833},"data":{"type":"CustomComponent","node":{"template":{"code":{"dynamic":true,"required":true,"placeholder":"","show":true,"multiline":true,"value":"from langflow import CustomComponent\nfrom langflow.field_typing import Chain\nfrom langchain.chains import TransformChain\n\nclass ChainTransformer(CustomComponent):\n display_name = \"Transform Chain\"\n description = \"Converts a python function into a chain.\"\n\n # Modify this as you like, use any argument created in 'build' via 'self'\n def perform_action(self, chat_input):\n result = (chat_input + \" \" + self.foo + \" ๐๐\").upper()\n return {self.output_key: result}\n\n # Parameters here are turned into class attributes accessible in 'perform_action'\n def build(self, foo: str = \"World\", input_key: str = \"input\", output_key: str = \"output\") -> Chain:\n args = locals()\n del args['self']\n for key, value in args.items():\n setattr(self, key, value)\n \n def wrapper(inputs: dict):\n chat_input = inputs.get(self.input_key)\n return self.perform_action(chat_input)\n \n return TransformChain(\n input_variables=[self.input_key], output_variables=[self.output_key], transform=wrapper\n )\n","password":false,"name":"code","advanced":false,"type":"code","list":false},"_type":"CustomComponent","foo":{"required":true,"placeholder":"","show":true,"multiline":false,"value":"World","password":false,"name":"foo","display_name":"foo","advanced":false,"dynamic":false,"info":"","type":"str","list":false},"input_key":{"required":true,"placeholder":"","show":true,"multiline":false,"value":"input","password":false,"name":"input_key","display_name":"input_key","advanced":false,"dynamic":false,"info":"","type":"str","list":false},"output_key":{"required":true,"placeholder":"","show":true,"multiline":false,"value":"output","password":false,"name":"output_key","display_name":"output_key","advanced":false,"dynamic":false,"info":"","type":"str","list":false}},"description":"Converts a python function into a chain.","base_classes":["Chain"],"display_name":"Transform Chain","custom_fields":{"foo":null,"input_key":null,"output_key":null},"output_types":["Chain"],"documentation":"","beta":true,"error":null},"id":"CustomComponent-C8eNm"},"selected":true,"positionAbsolute":{"x":361.2179541318329,"y":14.576073295690833},"dragging":false}],"edges":[],"viewport":{"x":-26.989203538796687,"y":49.09456857762268,"zoom":1.051337481371938}},"id":"0b9438b4-39d2-435d-af6d-f7d74cf6f18a","user_id":"2d55065d-e2ba-4f7c-86a1-567fec88d9ac"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment