Skip to content

Commit

Permalink
chore: Add advanced option for storing messages in ChatInput and Chat…
Browse files Browse the repository at this point in the history
…Output
  • Loading branch information
ogabrielluiz committed Jul 12, 2024
1 parent 7589a29 commit 60df022
Showing 1 changed file with 63 additions and 25 deletions.
88 changes: 63 additions & 25 deletions tests/data/SimpleAPITest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "9f5e1c24-2b69-48e0-9f68-0c9c90ed703d",
"id": "e9380216-9300-41a1-bc35-7ee92fe4b30d",
"data": {
"nodes": [
{
"id": "ChatInput-qBJin",
"id": "ChatInput-irFJf",
"type": "genericNode",
"position": {
"x": 180,
Expand Down Expand Up @@ -62,7 +62,7 @@
"list": false,
"show": true,
"multiline": true,
"value": "from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.io import DropdownInput, FileInput, MessageTextInput, MultilineInput, Output\nfrom langflow.schema.message import Message\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n name = \"ChatInput\"\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n value=\"\",\n info=\"Message to be passed as input.\",\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[\"Machine\", \"User\"],\n value=\"User\",\n info=\"Type of sender.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=\"User\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\", display_name=\"Session ID\", info=\"Session ID for the message.\", advanced=True\n ),\n FileInput(\n name=\"files\",\n display_name=\"Files\",\n file_types=TEXT_FILE_TYPES + IMG_FILE_TYPES,\n info=\"Files to be sent with the message.\",\n advanced=True,\n is_list=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Message\", name=\"message\", method=\"message_response\"),\n ]\n\n def message_response(self) -> Message:\n message = Message(\n text=self.input_value,\n sender=self.sender,\n sender_name=self.sender_name,\n session_id=self.session_id,\n files=self.files,\n )\n if self.session_id and isinstance(message, Message) and isinstance(message.text, str):\n self.store_message(message)\n self.message.value = message\n\n self.status = message\n return message\n",
"value": "from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.inputs import BoolInput\nfrom langflow.io import DropdownInput, FileInput, MessageTextInput, MultilineInput, Output\nfrom langflow.memory import store_message\nfrom langflow.schema.message import Message\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"ChatInput\"\n name = \"ChatInput\"\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n value=\"\",\n info=\"Message to be passed as input.\",\n ),\n BoolInput(\n name=\"store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[\"Machine\", \"User\"],\n value=\"User\",\n info=\"Type of sender.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=\"User\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\", display_name=\"Session ID\", info=\"Session ID for the message.\", advanced=True\n ),\n FileInput(\n name=\"files\",\n display_name=\"Files\",\n file_types=TEXT_FILE_TYPES + IMG_FILE_TYPES,\n info=\"Files to be sent with the message.\",\n advanced=True,\n is_list=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Message\", name=\"message\", method=\"message_response\"),\n ]\n\n def message_response(self) -> Message:\n message = Message(\n text=self.input_value,\n sender=self.sender,\n sender_name=self.sender_name,\n session_id=self.session_id,\n files=self.files,\n )\n\n if self.session_id and isinstance(message, Message) and isinstance(message.text, str):\n store_message(\n message,\n flow_id=self.graph.flow_id,\n )\n self.message.value = message\n\n self.status = message\n return message\n",
"fileTypes": [],
"file_path": "",
"password": false,
Expand Down Expand Up @@ -151,6 +151,21 @@
"info": "Session ID for the message.",
"title_case": false,
"type": "str"
},
"store_message": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"value": true,
"name": "store_message",
"display_name": "Store Messages",
"advanced": true,
"dynamic": false,
"info": "Store the message in the history.",
"title_case": false,
"type": "bool"
}
},
"description": "Get chat inputs from the Playground.",
Expand Down Expand Up @@ -180,6 +195,7 @@
],
"field_order": [
"input_value",
"store_message",
"sender",
"sender_name",
"session_id",
Expand All @@ -188,14 +204,16 @@
"beta": false,
"edited": false
},
"id": "ChatInput-qBJin"
"id": "ChatInput-irFJf",
"description": "Get chat inputs from the Playground.",
"display_name": "Chat Input"
},
"selected": false,
"width": 384,
"height": 309
},
{
"id": "TextInput-uORgD",
"id": "TextInput-tcoZg",
"type": "genericNode",
"position": {
"x": 186,
Expand Down Expand Up @@ -276,7 +294,7 @@
"beta": false,
"edited": false
},
"id": "TextInput-uORgD"
"id": "TextInput-tcoZg"
},
"selected": true,
"width": 384,
Expand All @@ -288,7 +306,7 @@
"dragging": false
},
{
"id": "ChatOutput-7pSZE",
"id": "ChatOutput-dJRst",
"type": "genericNode",
"position": {
"x": 820,
Expand All @@ -306,7 +324,7 @@
"list": false,
"show": true,
"multiline": true,
"value": "from langflow.base.io.chat import ChatComponent\nfrom langflow.io import DropdownInput, MessageTextInput, Output\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n name = \"ChatOutput\"\n\n inputs = [\n MessageTextInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Message to be passed as output.\",\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[\"Machine\", \"User\"],\n value=\"Machine\",\n advanced=True,\n info=\"Type of sender.\",\n ),\n MessageTextInput(\n name=\"sender_name\", display_name=\"Sender Name\", info=\"Name of the sender.\", value=\"AI\", advanced=True\n ),\n MessageTextInput(\n name=\"session_id\", display_name=\"Session ID\", info=\"Session ID for the message.\", advanced=True\n ),\n MessageTextInput(\n name=\"data_template\",\n display_name=\"Data Template\",\n value=\"{text}\",\n advanced=True,\n info=\"Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.\",\n ),\n ]\n outputs = [\n Output(display_name=\"Message\", name=\"message\", method=\"message_response\"),\n ]\n\n def message_response(self) -> Message:\n message = Message(\n text=self.input_value,\n sender=self.sender,\n sender_name=self.sender_name,\n session_id=self.session_id,\n )\n if self.session_id and isinstance(message, Message) and isinstance(message.text, str):\n self.store_message(message)\n self.message.value = message\n\n self.status = message\n return message\n",
"value": "from langflow.base.io.chat import ChatComponent\nfrom langflow.inputs import BoolInput\nfrom langflow.io import DropdownInput, MessageTextInput, Output\nfrom langflow.memory import store_message\nfrom langflow.schema.message import Message\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"ChatOutput\"\n name = \"ChatOutput\"\n\n inputs = [\n MessageTextInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Message to be passed as output.\",\n ),\n BoolInput(\n name=\"store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[\"Machine\", \"User\"],\n value=\"Machine\",\n advanced=True,\n info=\"Type of sender.\",\n ),\n MessageTextInput(\n name=\"sender_name\", display_name=\"Sender Name\", info=\"Name of the sender.\", value=\"AI\", advanced=True\n ),\n MessageTextInput(\n name=\"session_id\", display_name=\"Session ID\", info=\"Session ID for the message.\", advanced=True\n ),\n MessageTextInput(\n name=\"data_template\",\n display_name=\"Data Template\",\n value=\"{text}\",\n advanced=True,\n info=\"Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.\",\n ),\n ]\n outputs = [\n Output(display_name=\"Message\", name=\"message\", method=\"message_response\"),\n ]\n\n def message_response(self) -> Message:\n message = Message(\n text=self.input_value,\n sender=self.sender,\n sender_name=self.sender_name,\n session_id=self.session_id,\n )\n if self.session_id and isinstance(message, Message) and isinstance(message.text, str):\n store_message(\n message,\n flow_id=self.graph.flow_id,\n )\n self.message.value = message\n\n self.status = message\n return message\n",
"fileTypes": [],
"file_path": "",
"password": false,
Expand Down Expand Up @@ -386,7 +404,7 @@
"value": "",
"name": "sender_name",
"display_name": "Sender Name",
"advanced": false,
"advanced": true,
"input_types": [
"Message"
],
Expand Down Expand Up @@ -414,6 +432,21 @@
"info": "Session ID for the message.",
"title_case": false,
"type": "str"
},
"store_message": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"value": true,
"name": "store_message",
"display_name": "Store Messages",
"advanced": true,
"dynamic": false,
"info": "Store the message in the history.",
"title_case": false,
"type": "bool"
}
},
"description": "Display a chat message in the Playground.",
Expand Down Expand Up @@ -443,6 +476,7 @@
],
"field_order": [
"input_value",
"store_message",
"sender",
"sender_name",
"session_id",
Expand All @@ -451,7 +485,9 @@
"beta": false,
"edited": false
},
"id": "ChatOutput-7pSZE"
"id": "ChatOutput-dJRst",
"description": "Display a chat message in the Playground.",
"display_name": "Chat Output"
},
"selected": false,
"width": 384,
Expand All @@ -465,54 +501,56 @@
],
"edges": [
{
"source": "ChatInput-qBJin",
"sourceHandle": "{œdataTypeœ:œChatInputœ,œidœ:œChatInput-qBJinœ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}",
"target": "ChatOutput-7pSZE",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-7pSZEœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"source": "ChatInput-irFJf",
"sourceHandle": "{œdataTypeœ:œChatInputœ,œidœ:œChatInput-irFJfœ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}",
"target": "ChatOutput-dJRst",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-dJRstœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"data": {
"targetHandle": {
"fieldName": "input_value",
"id": "ChatOutput-7pSZE",
"id": "ChatOutput-dJRst",
"inputTypes": [
"Message"
],
"type": "str"
},
"sourceHandle": {
"dataType": "ChatInput",
"id": "ChatInput-qBJin",
"id": "ChatInput-irFJf",
"name": "message",
"output_types": [
"Message"
]
}
},
"id": "reactflow__edge-ChatInput-qBJin{œdataTypeœ:œChatInputœ,œidœ:œChatInput-qBJinœ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-7pSZE{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-7pSZEœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
"id": "reactflow__edge-ChatInput-irFJf{œdataTypeœ:œChatInputœ,œidœ:œChatInput-irFJfœ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-dJRst{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-dJRstœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"className": ""
},
{
"source": "TextInput-uORgD",
"sourceHandle": "{œdataTypeœ:œTextInputœ,œidœ:œTextInput-uORgDœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}",
"target": "ChatOutput-7pSZE",
"targetHandle": "{œfieldNameœ:œsender_nameœ,œidœ:œChatOutput-7pSZEœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"source": "TextInput-tcoZg",
"sourceHandle": "{œdataTypeœ:œTextInputœ,œidœ:œTextInput-tcoZgœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}",
"target": "ChatOutput-dJRst",
"targetHandle": "{œfieldNameœ:œsender_nameœ,œidœ:œChatOutput-dJRstœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"data": {
"targetHandle": {
"fieldName": "sender_name",
"id": "ChatOutput-7pSZE",
"id": "ChatOutput-dJRst",
"inputTypes": [
"Message"
],
"type": "str"
},
"sourceHandle": {
"dataType": "TextInput",
"id": "TextInput-uORgD",
"id": "TextInput-tcoZg",
"name": "text",
"output_types": [
"Message"
]
}
},
"id": "reactflow__edge-TextInput-uORgD{œdataTypeœ:œTextInputœ,œidœ:œTextInput-uORgDœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-7pSZE{œfieldNameœ:œsender_nameœ,œidœ:œChatOutput-7pSZEœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
"id": "reactflow__edge-TextInput-tcoZg{œdataTypeœ:œTextInputœ,œidœ:œTextInput-tcoZgœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-dJRst{œfieldNameœ:œsender_nameœ,œidœ:œChatOutput-dJRstœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"className": ""
}
],
"viewport": {
Expand All @@ -523,7 +561,7 @@
},
"description": "Nurture NLP Nodes Here.",
"name": "Simple API Test",
"last_tested_version": "1.0.8",
"last_tested_version": "1.0.9",
"endpoint_name": null,
"is_component": false
}

0 comments on commit 60df022

Please sign in to comment.