Refactor code to improve performance and readability

This commit is contained in:
anovazzi1 2024-04-01 21:20:23 -03:00
commit 15144a31d0

View file

@ -5,7 +5,7 @@
"data": { "data": {
"nodes": [ "nodes": [
{ {
"id": "ChatInput-r2WbA", "id": "ChatInput-t7F8v",
"type": "genericNode", "type": "genericNode",
"position": { "position": {
"x": 1283.2700598313072, "x": 1283.2700598313072,
@ -51,7 +51,7 @@
"info": "", "info": "",
"load_from_db": false, "load_from_db": false,
"title_case": false, "title_case": false,
"value": "what i said in the past?" "value": ""
}, },
"return_record": { "return_record": {
"type": "bool", "type": "bool",
@ -170,11 +170,11 @@
"field_order": [], "field_order": [],
"beta": false "beta": false
}, },
"id": "ChatInput-r2WbA" "id": "ChatInput-t7F8v"
}, },
"selected": false, "selected": false,
"width": 384, "width": 384,
"height": 471, "height": 469,
"positionAbsolute": { "positionAbsolute": {
"x": 1283.2700598313072, "x": 1283.2700598313072,
"y": 982.5953650473145 "y": 982.5953650473145
@ -182,7 +182,7 @@
"dragging": false "dragging": false
}, },
{ {
"id": "ChatOutput-65FlE", "id": "ChatOutput-P1jEe",
"type": "genericNode", "type": "genericNode",
"position": { "position": {
"x": 3154.916355514023, "x": 3154.916355514023,
@ -348,11 +348,11 @@
"field_order": [], "field_order": [],
"beta": false "beta": false
}, },
"id": "ChatOutput-65FlE" "id": "ChatOutput-P1jEe"
}, },
"selected": false, "selected": false,
"width": 384, "width": 384,
"height": 479, "height": 477,
"dragging": false, "dragging": false,
"positionAbsolute": { "positionAbsolute": {
"x": 3154.916355514023, "x": 3154.916355514023,
@ -360,7 +360,7 @@
} }
}, },
{ {
"id": "MemoryComponent-CsMk7", "id": "MemoryComponent-cdA1J",
"type": "genericNode", "type": "genericNode",
"position": { "position": {
"x": 1289.9606870058817, "x": 1289.9606870058817,
@ -552,13 +552,13 @@
"field_order": [], "field_order": [],
"beta": true "beta": true
}, },
"id": "MemoryComponent-CsMk7", "id": "MemoryComponent-cdA1J",
"description": "Retrieves stored chat messages given a specific Session ID.", "description": "Retrieves stored chat messages given a specific Session ID.",
"display_name": "Chat Memory" "display_name": "Chat Memory"
}, },
"selected": false, "selected": false,
"width": 384, "width": 384,
"height": 491, "height": 489,
"dragging": false, "dragging": false,
"positionAbsolute": { "positionAbsolute": {
"x": 1289.9606870058817, "x": 1289.9606870058817,
@ -566,7 +566,7 @@
} }
}, },
{ {
"id": "Prompt-p9ug4", "id": "Prompt-ODkUx",
"type": "genericNode", "type": "genericNode",
"position": { "position": {
"x": 1894.594426342426, "x": 1894.594426342426,
@ -699,13 +699,13 @@
"beta": false, "beta": false,
"error": null "error": null
}, },
"id": "Prompt-p9ug4", "id": "Prompt-ODkUx",
"description": "A component for creating prompt templates using dynamic variables.", "description": "A component for creating prompt templates using dynamic variables.",
"display_name": "Prompt" "display_name": "Prompt"
}, },
"selected": false, "selected": false,
"width": 384, "width": 384,
"height": 479, "height": 477,
"dragging": false, "dragging": false,
"positionAbsolute": { "positionAbsolute": {
"x": 1894.594426342426, "x": 1894.594426342426,
@ -713,7 +713,7 @@
} }
}, },
{ {
"id": "OpenAIModel-OwSm5", "id": "OpenAIModel-9RykF",
"type": "genericNode", "type": "genericNode",
"position": { "position": {
"x": 2561.5850334731617, "x": 2561.5850334731617,
@ -979,29 +979,137 @@
], ],
"beta": false "beta": false
}, },
"id": "OpenAIModel-OwSm5" "id": "OpenAIModel-9RykF"
}, },
"selected": false, "selected": false,
"width": 384, "width": 384,
"height": 565, "height": 563,
"positionAbsolute": { "positionAbsolute": {
"x": 2561.5850334731617, "x": 2561.5850334731617,
"y": 553.2745131130916 "y": 553.2745131130916
}, },
"dragging": false "dragging": false
},
{
"id": "TextOutput-vrs6T",
"type": "genericNode",
"position": {
"x": 1911.4785906252087,
"y": 247.39079954376987
},
"data": {
"type": "TextOutput",
"node": {
"template": {
"input_value": {
"type": "str",
"required": false,
"placeholder": "",
"list": false,
"show": true,
"multiline": false,
"value": "",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "input_value",
"display_name": "Value",
"advanced": false,
"input_types": [
"Record",
"Text"
],
"dynamic": false,
"info": "Text or Record to be passed as output.",
"load_from_db": false,
"title_case": false
},
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "from typing import Optional\n\nfrom langflow.base.io.text import TextComponent\nfrom langflow.field_typing import Text\n\n\nclass TextOutput(TextComponent):\n display_name = \"Text Output\"\n description = \"Display a text output in the Interaction Panel.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Value\",\n \"input_types\": [\"Record\", \"Text\"],\n \"info\": \"Text or Record to be passed as output.\",\n },\n \"record_template\": {\n \"display_name\": \"Record Template\",\n \"multiline\": True,\n \"info\": \"Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.\",\n \"advanced\": True,\n },\n }\n\n def build(self, input_value: Optional[Text] = \"\", record_template: str = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"record_template": {
"type": "str",
"required": false,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "record_template",
"display_name": "Record Template",
"advanced": true,
"dynamic": false,
"info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.",
"load_from_db": false,
"title_case": false,
"input_types": [
"Text"
]
},
"_type": "CustomComponent"
},
"description": "Display a text output in the Interaction Panel.",
"icon": "type",
"base_classes": [
"str",
"object",
"Text"
],
"display_name": "Inspect Memory",
"documentation": "",
"custom_fields": {
"input_value": null,
"record_template": null
},
"output_types": [
"Text"
],
"field_formatters": {},
"frozen": false,
"field_order": [],
"beta": false
},
"id": "TextOutput-vrs6T"
},
"selected": false,
"width": 384,
"height": 289,
"positionAbsolute": {
"x": 1911.4785906252087,
"y": 247.39079954376987
},
"dragging": false
} }
], ],
"edges": [ "edges": [
{ {
"source": "MemoryComponent-CsMk7", "source": "MemoryComponent-cdA1J",
"sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-CsMk7œ}", "sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}",
"target": "Prompt-p9ug4", "target": "Prompt-ODkUx",
"targetHandle": "{œfieldNameœ:œcontextœ,œidœ:œPrompt-p9ug4œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", "targetHandle": "{œfieldNameœ:œcontextœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}",
"data": { "data": {
"targetHandle": { "targetHandle": {
"fieldName": "context", "fieldName": "context",
"type": "str", "type": "str",
"id": "Prompt-p9ug4", "id": "Prompt-ODkUx",
"inputTypes": [ "inputTypes": [
"Document", "Document",
"BaseOutputParser", "BaseOutputParser",
@ -1016,26 +1124,26 @@
"object" "object"
], ],
"dataType": "MemoryComponent", "dataType": "MemoryComponent",
"id": "MemoryComponent-CsMk7" "id": "MemoryComponent-cdA1J"
} }
}, },
"style": { "style": {
"stroke": "#555" "stroke": "#555"
}, },
"className": "stroke-gray-900 stroke-connection", "className": "stroke-gray-900 stroke-connection",
"id": "reactflow__edge-MemoryComponent-CsMk7{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-CsMk7œ}-Prompt-p9ug4{œfieldNameœ:œcontextœ,œidœ:œPrompt-p9ug4œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", "id": "reactflow__edge-MemoryComponent-cdA1J{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}-Prompt-ODkUx{œfieldNameœ:œcontextœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}",
"selected": false "selected": false
}, },
{ {
"source": "ChatInput-r2WbA", "source": "ChatInput-t7F8v",
"sourceHandle": "{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-r2WbAœ}", "sourceHandle": "{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-t7F8vœ}",
"target": "Prompt-p9ug4", "target": "Prompt-ODkUx",
"targetHandle": "{œfieldNameœ:œuser_messageœ,œidœ:œPrompt-p9ug4œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", "targetHandle": "{œfieldNameœ:œuser_messageœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}",
"data": { "data": {
"targetHandle": { "targetHandle": {
"fieldName": "user_message", "fieldName": "user_message",
"type": "str", "type": "str",
"id": "Prompt-p9ug4", "id": "Prompt-ODkUx",
"inputTypes": [ "inputTypes": [
"Document", "Document",
"BaseOutputParser", "BaseOutputParser",
@ -1051,25 +1159,25 @@
"str" "str"
], ],
"dataType": "ChatInput", "dataType": "ChatInput",
"id": "ChatInput-r2WbA" "id": "ChatInput-t7F8v"
} }
}, },
"style": { "style": {
"stroke": "#555" "stroke": "#555"
}, },
"className": "stroke-gray-900 stroke-connection", "className": "stroke-gray-900 stroke-connection",
"id": "reactflow__edge-ChatInput-r2WbA{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-r2WbAœ}-Prompt-p9ug4{œfieldNameœ:œuser_messageœ,œidœ:œPrompt-p9ug4œ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}", "id": "reactflow__edge-ChatInput-t7F8v{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-t7F8vœ}-Prompt-ODkUx{œfieldNameœ:œuser_messageœ,œidœ:œPrompt-ODkUxœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}",
"selected": false "selected": false
}, },
{ {
"source": "Prompt-p9ug4", "source": "Prompt-ODkUx",
"sourceHandle": "{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-p9ug4œ}", "sourceHandle": "{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-ODkUxœ}",
"target": "OpenAIModel-OwSm5", "target": "OpenAIModel-9RykF",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-OwSm5œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-9RykFœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}",
"data": { "data": {
"targetHandle": { "targetHandle": {
"fieldName": "input_value", "fieldName": "input_value",
"id": "OpenAIModel-OwSm5", "id": "OpenAIModel-9RykF",
"inputTypes": [ "inputTypes": [
"Text" "Text"
], ],
@ -1082,24 +1190,24 @@
"object" "object"
], ],
"dataType": "Prompt", "dataType": "Prompt",
"id": "Prompt-p9ug4" "id": "Prompt-ODkUx"
} }
}, },
"style": { "style": {
"stroke": "#555" "stroke": "#555"
}, },
"className": "stroke-foreground stroke-connection", "className": "stroke-gray-900 stroke-connection",
"id": "reactflow__edge-Prompt-p9ug4{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-p9ug4œ}-OpenAIModel-OwSm5{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-OwSm5œ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" "id": "reactflow__edge-Prompt-ODkUx{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-ODkUxœ}-OpenAIModel-9RykF{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-9RykFœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}"
}, },
{ {
"source": "OpenAIModel-OwSm5", "source": "OpenAIModel-9RykF",
"sourceHandle": "{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-OwSm5œ}", "sourceHandle": "{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-9RykFœ}",
"target": "ChatOutput-65FlE", "target": "ChatOutput-P1jEe",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-65FlEœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}", "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-P1jEeœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}",
"data": { "data": {
"targetHandle": { "targetHandle": {
"fieldName": "input_value", "fieldName": "input_value",
"id": "ChatOutput-65FlE", "id": "ChatOutput-P1jEe",
"inputTypes": [ "inputTypes": [
"Text" "Text"
], ],
@ -1112,20 +1220,51 @@
"Text" "Text"
], ],
"dataType": "OpenAIModel", "dataType": "OpenAIModel",
"id": "OpenAIModel-OwSm5" "id": "OpenAIModel-9RykF"
}
},
"style": {
"stroke": "#555"
},
"className": "stroke-gray-900 stroke-connection",
"id": "reactflow__edge-OpenAIModel-9RykF{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-9RykFœ}-ChatOutput-P1jEe{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-P1jEeœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}"
},
{
"source": "MemoryComponent-cdA1J",
"sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}",
"target": "TextOutput-vrs6T",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-vrs6Tœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}",
"data": {
"targetHandle": {
"fieldName": "input_value",
"id": "TextOutput-vrs6T",
"inputTypes": [
"Record",
"Text"
],
"type": "str"
},
"sourceHandle": {
"baseClasses": [
"str",
"Text",
"object"
],
"dataType": "MemoryComponent",
"id": "MemoryComponent-cdA1J"
} }
}, },
"style": { "style": {
"stroke": "#555" "stroke": "#555"
}, },
"className": "stroke-foreground stroke-connection", "className": "stroke-foreground stroke-connection",
"id": "reactflow__edge-OpenAIModel-OwSm5{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-OwSm5œ}-ChatOutput-65FlE{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-65FlEœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}" "id": "reactflow__edge-MemoryComponent-cdA1J{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-cdA1Jœ}-TextOutput-vrs6T{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-vrs6Tœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}"
} }
], ],
"viewport": { "viewport": {
"x": -391.0433294674358, "x": -569.862554459756,
"y": -105.08951818254411, "y": -42.08339711050985,
"zoom": 0.5948708289887507 "zoom": 0.4868590524514978
} }
}, },
"description": "This project can be used as a starting point for building a Chat experience with user specific memory. You can set a different Session ID to start a new message history.", "description": "This project can be used as a starting point for building a Chat experience with user specific memory. You can set a different Session ID to start a new message history.",