Update Memory Example

This commit is contained in:
ogabrielluiz 2024-06-13 12:12:24 -03:00
commit 045cb38cd3

View file

@ -1,173 +1,10 @@
{
"id": "321b1bab-8691-42da-9689-1f12b5d2a48b",
"data": {
"edges": [
{
"className": "stroke-gray-900 stroke-connection",
"data": {
"sourceHandle": {
"baseClasses": [
"str",
"Text",
"object"
],
"dataType": "MemoryComponent",
"id": "MemoryComponent-iDkC0"
},
"targetHandle": {
"fieldName": "context",
"id": "Prompt-19lCm",
"inputTypes": [
"Document",
"BaseOutputParser",
"Record",
"Text"
],
"type": "str"
}
},
"id": "reactflow__edge-MemoryComponent-iDkC0{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-iDkC0œ}-Prompt-19lCm{œfieldNameœ:œcontextœ,œidœ:œPrompt-19lCmœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}",
"selected": false,
"source": "MemoryComponent-iDkC0",
"sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œMemoryComponentœ, œidœ: œMemoryComponent-iDkC0œ}",
"style": {
"stroke": "#555"
},
"target": "Prompt-19lCm",
"targetHandle": "{œfieldNameœ: œcontextœ, œidœ: œPrompt-19lCmœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}"
},
{
"className": "",
"data": {
"sourceHandle": {
"baseClasses": [
"Text",
"object",
"Record",
"str"
],
"dataType": "ChatInput",
"id": "ChatInput-Z6G1Z"
},
"targetHandle": {
"fieldName": "user_message",
"id": "Prompt-19lCm",
"inputTypes": [
"Document",
"BaseOutputParser",
"Record",
"Text"
],
"type": "str"
}
},
"id": "reactflow__edge-ChatInput-Z6G1Z{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-Z6G1Zœ}-Prompt-19lCm{œfieldNameœ:œuser_messageœ,œidœ:œPrompt-19lCmœ,œinputTypesœ:[œDocumentœ,œBaseOutputParserœ,œRecordœ,œTextœ],œtypeœ:œstrœ}",
"selected": false,
"source": "ChatInput-Z6G1Z",
"sourceHandle": "{œbaseClassesœ: [œTextœ, œobjectœ, œRecordœ, œstrœ], œdataTypeœ: œChatInputœ, œidœ: œChatInput-Z6G1Zœ}",
"style": {
"stroke": "#555"
},
"target": "Prompt-19lCm",
"targetHandle": "{œfieldNameœ: œuser_messageœ, œidœ: œPrompt-19lCmœ, œinputTypesœ: [œDocumentœ, œBaseOutputParserœ, œRecordœ, œTextœ], œtypeœ: œstrœ}"
},
{
"className": "",
"data": {
"sourceHandle": {
"baseClasses": [
"Text",
"str",
"object"
],
"dataType": "Prompt",
"id": "Prompt-19lCm"
},
"targetHandle": {
"fieldName": "input_value",
"id": "OpenAIModel-1v5Hz",
"inputTypes": [
"Text",
"Record",
"Prompt"
],
"type": "str"
}
},
"id": "reactflow__edge-Prompt-19lCm{œbaseClassesœ:[œTextœ,œstrœ,œobjectœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-19lCmœ}-OpenAIModel-1v5Hz{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-1v5Hzœ,œinputTypesœ:[œTextœ,œRecordœ,œPromptœ],œtypeœ:œstrœ}",
"source": "Prompt-19lCm",
"sourceHandle": "{œbaseClassesœ: [œTextœ, œstrœ, œobjectœ], œdataTypeœ: œPromptœ, œidœ: œPrompt-19lCmœ}",
"style": {
"stroke": "#555"
},
"target": "OpenAIModel-1v5Hz",
"targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-1v5Hzœ, œinputTypesœ: [œTextœ, œRecordœ, œPromptœ], œtypeœ: œstrœ}"
},
{
"className": "",
"data": {
"sourceHandle": {
"baseClasses": [
"str",
"object",
"Text"
],
"dataType": "OpenAIModel",
"id": "OpenAIModel-1v5Hz"
},
"targetHandle": {
"fieldName": "input_value",
"id": "ChatOutput-i56kN",
"inputTypes": [
"Text"
],
"type": "str"
}
},
"id": "reactflow__edge-OpenAIModel-1v5Hz{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-1v5Hzœ}-ChatOutput-i56kN{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-i56kNœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}",
"source": "OpenAIModel-1v5Hz",
"sourceHandle": "{œbaseClassesœ: [œstrœ, œobjectœ, œTextœ], œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-1v5Hzœ}",
"style": {
"stroke": "#555"
},
"target": "ChatOutput-i56kN",
"targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-i56kNœ, œinputTypesœ: [œTextœ], œtypeœ: œstrœ}"
},
{
"className": "",
"data": {
"sourceHandle": {
"baseClasses": [
"str",
"Text",
"object"
],
"dataType": "MemoryComponent",
"id": "MemoryComponent-iDkC0"
},
"targetHandle": {
"fieldName": "input_value",
"id": "TextOutput-KuLNK",
"inputTypes": [
"Record",
"Text"
],
"type": "str"
}
},
"id": "reactflow__edge-MemoryComponent-iDkC0{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-iDkC0œ}-TextOutput-KuLNK{œfieldNameœ:œinput_valueœ,œidœ:œTextOutput-KuLNKœ,œinputTypesœ:[œRecordœ,œTextœ],œtypeœ:œstrœ}",
"source": "MemoryComponent-iDkC0",
"sourceHandle": "{œbaseClassesœ: [œstrœ, œTextœ, œobjectœ], œdataTypeœ: œMemoryComponentœ, œidœ: œMemoryComponent-iDkC0œ}",
"style": {
"stroke": "#555"
},
"target": "TextOutput-KuLNK",
"targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œTextOutput-KuLNKœ, œinputTypesœ: [œRecordœ, œTextœ], œtypeœ: œstrœ}"
}
],
"nodes": [
{
"data": {
"id": "ChatInput-Z6G1Z",
"id": "ChatInput-Z9Rn6",
"node": {
"base_classes": [
"Text",
@ -232,7 +69,7 @@
"show": true,
"title_case": false,
"type": "str",
"value": ""
"value": "do you know his name?"
},
"sender": {
"advanced": true,
@ -309,8 +146,8 @@
"type": "ChatInput"
},
"dragging": false,
"height": 469,
"id": "ChatInput-Z6G1Z",
"height": 477,
"id": "ChatInput-Z9Rn6",
"position": {
"x": 1283.2700598313072,
"y": 982.5953650473145
@ -325,7 +162,7 @@
},
{
"data": {
"id": "ChatOutput-i56kN",
"id": "ChatOutput-cVR7W",
"node": {
"base_classes": [
"Text",
@ -468,8 +305,8 @@
"type": "ChatOutput"
},
"dragging": false,
"height": 477,
"id": "ChatOutput-i56kN",
"height": 485,
"id": "ChatOutput-cVR7W",
"position": {
"x": 3154.916355514023,
"y": 851.051882666333
@ -486,7 +323,7 @@
"data": {
"description": "Retrieves stored chat messages given a specific Session ID.",
"display_name": "Chat Memory",
"id": "MemoryComponent-iDkC0",
"id": "MemoryComponent-u6m5G",
"node": {
"base_classes": [
"str",
@ -674,8 +511,8 @@
"type": "MemoryComponent"
},
"dragging": false,
"height": 489,
"id": "MemoryComponent-iDkC0",
"height": 505,
"id": "MemoryComponent-u6m5G",
"position": {
"x": 1289.9606870058817,
"y": 442.16804561053766
@ -690,38 +527,10 @@
},
{
"data": {
"description": "A component for creating prompt templates using dynamic variables.",
"display_name": "Prompt",
"id": "Prompt-19lCm",
"node": {
"base_classes": [
"Text",
"str",
"object"
],
"beta": false,
"custom_fields": {
"template": [
"context",
"user_message"
]
},
"description": "Create a prompt template with dynamic variables.",
"display_name": "Prompt",
"documentation": "",
"error": null,
"field_formatters": {},
"field_order": [],
"frozen": false,
"full_path": null,
"icon": "prompts",
"is_composition": null,
"is_input": null,
"is_output": null,
"name": "",
"output_types": [
"Prompt"
],
"id": "Prompt-kykM2",
"node": {
"template": {
"_type": "CustomComponent",
"code": {
@ -742,32 +551,6 @@
"type": "code",
"value": "from langflow.custom import CustomComponent\nfrom langflow.field_typing import TemplateField\nfrom langflow.field_typing.prompt import Prompt\n\n\nclass PromptComponent(CustomComponent):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n\n def build_config(self):\n return {\n \"template\": TemplateField(display_name=\"Template\"),\n \"code\": TemplateField(advanced=True),\n }\n\n async def build(\n self,\n template: Prompt,\n **kwargs,\n ) -> Prompt:\n prompt = await Prompt.from_template_and_variables(template, kwargs)\n self.status = prompt.format_text()\n return prompt\n"
},
"context": {
"advanced": false,
"display_name": "context",
"dynamic": false,
"field_type": "str",
"fileTypes": [],
"file_path": "",
"info": "",
"input_types": [
"Document",
"BaseOutputParser",
"Record",
"Text"
],
"list": false,
"load_from_db": false,
"multiline": true,
"name": "context",
"password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"type": "str",
"value": ""
},
"template": {
"advanced": false,
"display_name": "Template",
@ -788,56 +571,110 @@
"show": true,
"title_case": false,
"type": "prompt",
"value": "{context}\n\nUser: {user_message}\nAI: "
"value": "Previous messages:\n{Context}\n\nUser: {UserMessage}\nAI: "
},
"user_message": {
"advanced": false,
"display_name": "user_message",
"dynamic": false,
"Context": {
"field_type": "str",
"required": false,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "",
"fileTypes": [],
"file_path": "",
"info": "",
"password": false,
"name": "Context",
"display_name": "Context",
"advanced": false,
"input_types": [
"Document",
"BaseOutputParser",
"Message",
"Record",
"Text"
],
"list": false,
"dynamic": false,
"info": "",
"load_from_db": false,
"multiline": true,
"name": "user_message",
"password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"type": "str",
"value": ""
}
"type": "str"
},
"UserMessage": {
"field_type": "str",
"required": false,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "UserMessage",
"display_name": "UserMessage",
"advanced": false,
"input_types": [
"Document",
"Message",
"Record",
"Text"
],
"dynamic": false,
"info": "",
"load_from_db": false,
"title_case": false,
"type": "str"
}
},
"description": "Create a prompt template with dynamic variables.",
"icon": "prompts",
"is_input": null,
"is_output": null,
"is_composition": null,
"base_classes": [
"object",
"str",
"Text"
],
"name": "",
"display_name": "Prompt",
"documentation": "",
"custom_fields": {
"template": [
"Context",
"UserMessage"
]
},
"output_types": [
"Prompt"
],
"full_path": null,
"field_formatters": {},
"frozen": false,
"field_order": [],
"beta": false,
"error": null
},
"type": "Prompt"
},
"dragging": false,
"height": 477,
"id": "Prompt-19lCm",
"height": 513,
"id": "Prompt-kykM2",
"position": {
"x": 1894.594426342426,
"x": 1890.2582485007167,
"y": 753.3797365481901
},
"positionAbsolute": {
"x": 1894.594426342426,
"x": 1890.2582485007167,
"y": 753.3797365481901
},
"selected": false,
"selected": true,
"type": "genericNode",
"width": 384
},
{
"data": {
"id": "OpenAIModel-1v5Hz",
"id": "OpenAIModel-Neuec",
"node": {
"base_classes": [
"str",
@ -1099,8 +936,8 @@
"type": "OpenAIModel"
},
"dragging": false,
"height": 563,
"id": "OpenAIModel-1v5Hz",
"height": 571,
"id": "OpenAIModel-Neuec",
"position": {
"x": 2561.5850334731617,
"y": 553.2745131130916
@ -1112,131 +949,136 @@
"selected": false,
"type": "genericNode",
"width": 384
}
],
"edges": [
{
"className": "",
"data": {
"sourceHandle": {
"baseClasses": [
"str",
"object",
"Text"
],
"dataType": "OpenAIModel",
"id": "OpenAIModel-Neuec"
},
"targetHandle": {
"fieldName": "input_value",
"id": "ChatOutput-cVR7W",
"inputTypes": [
"Text"
],
"type": "str"
}
},
"id": "reactflow__edge-OpenAIModel-Neuec{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-Neuecœ}-ChatOutput-cVR7W{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-cVR7Wœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}",
"source": "OpenAIModel-Neuec",
"sourceHandle": "{œbaseClassesœ:[œstrœ,œobjectœ,œTextœ],œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-Neuecœ}",
"style": {
"stroke": "#555"
},
"target": "ChatOutput-cVR7W",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-cVR7Wœ,œinputTypesœ:[œTextœ],œtypeœ:œstrœ}"
},
{
"source": "Prompt-kykM2",
"sourceHandle": "{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-kykM2œ}",
"target": "OpenAIModel-Neuec",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-Neuecœ,œinputTypesœ:[œTextœ,œRecordœ,œPromptœ],œtypeœ:œstrœ}",
"data": {
"description": "Display a text output in the Playground.",
"display_name": "Inspect Memory",
"edited": false,
"id": "TextOutput-KuLNK",
"node": {
"base_classes": [
"targetHandle": {
"fieldName": "input_value",
"id": "OpenAIModel-Neuec",
"inputTypes": [
"Text",
"Record",
"Prompt"
],
"type": "str"
},
"sourceHandle": {
"baseClasses": [
"object",
"str",
"Text"
],
"beta": false,
"custom_fields": {
"input_value": null,
"record_template": null
"dataType": "Prompt",
"id": "Prompt-kykM2"
}
},
"description": "Display a text output in the Playground.",
"display_name": "Inspect Memory",
"documentation": "",
"edited": true,
"field_formatters": {},
"field_order": [],
"frozen": false,
"icon": "type",
"output_types": [
"Text"
],
"template": {
"_type": "CustomComponent",
"code": {
"advanced": true,
"dynamic": true,
"fileTypes": [],
"file_path": "",
"info": "",
"list": false,
"load_from_db": false,
"multiline": true,
"name": "code",
"password": false,
"placeholder": "",
"required": true,
"show": true,
"title_case": false,
"type": "code",
"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 Playground.\"\n icon = \"type\"\n\n def build_config(self):\n return {\n \"input_value\": {\n \"display_name\": \"Text\",\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: Optional[str] = \"\") -> Text:\n return super().build(input_value=input_value, record_template=record_template)\n"
"id": "reactflow__edge-Prompt-kykM2{œbaseClassesœ:[œobjectœ,œstrœ,œTextœ],œdataTypeœ:œPromptœ,œidœ:œPrompt-kykM2œ}-OpenAIModel-Neuec{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-Neuecœ,œinputTypesœ:[œTextœ,œRecordœ,œPromptœ],œtypeœ:œstrœ}",
"className": ""
},
"input_value": {
"advanced": false,
"display_name": "Text",
"dynamic": false,
"fileTypes": [],
"file_path": "",
"info": "Text or Record to be passed as output.",
"input_types": [
{
"source": "ChatInput-Z9Rn6",
"sourceHandle": "{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-Z9Rn6œ}",
"target": "Prompt-kykM2",
"targetHandle": "{œfieldNameœ:œUserMessageœ,œidœ:œPrompt-kykM2œ,œinputTypesœ:[œDocumentœ,œMessageœ,œRecordœ,œTextœ],œtypeœ:œstrœ}",
"data": {
"targetHandle": {
"fieldName": "UserMessage",
"id": "Prompt-kykM2",
"inputTypes": [
"Document",
"Message",
"Record",
"Text"
],
"list": false,
"load_from_db": false,
"multiline": false,
"name": "input_value",
"password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"type": "str",
"value": ""
"type": "str"
},
"record_template": {
"advanced": true,
"display_name": "Record Template",
"dynamic": false,
"fileTypes": [],
"file_path": "",
"info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.",
"input_types": [
"sourceHandle": {
"baseClasses": [
"Text",
"object",
"Record",
"str"
],
"dataType": "ChatInput",
"id": "ChatInput-Z9Rn6"
}
},
"id": "reactflow__edge-ChatInput-Z9Rn6{œbaseClassesœ:[œTextœ,œobjectœ,œRecordœ,œstrœ],œdataTypeœ:œChatInputœ,œidœ:œChatInput-Z9Rn6œ}-Prompt-kykM2{œfieldNameœ:œUserMessageœ,œidœ:œPrompt-kykM2œ,œinputTypesœ:[œDocumentœ,œMessageœ,œRecordœ,œTextœ],œtypeœ:œstrœ}"
},
{
"source": "MemoryComponent-u6m5G",
"sourceHandle": "{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-u6m5Gœ}",
"target": "Prompt-kykM2",
"targetHandle": "{œfieldNameœ:œContextœ,œidœ:œPrompt-kykM2œ,œinputTypesœ:[œDocumentœ,œMessageœ,œRecordœ,œTextœ],œtypeœ:œstrœ}",
"data": {
"targetHandle": {
"fieldName": "Context",
"id": "Prompt-kykM2",
"inputTypes": [
"Document",
"Message",
"Record",
"Text"
],
"list": false,
"load_from_db": false,
"multiline": true,
"name": "record_template",
"password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"type": "str",
"value": ""
}
"type": "str"
},
"sourceHandle": {
"baseClasses": [
"str",
"Text",
"object"
],
"dataType": "MemoryComponent",
"id": "MemoryComponent-u6m5G"
}
},
"type": "TextOutput"
},
"dragging": false,
"height": 289,
"id": "TextOutput-KuLNK",
"position": {
"x": 1911.4785906252087,
"y": 247.39079954376987
},
"positionAbsolute": {
"x": 1911.4785906252087,
"y": 247.39079954376987
},
"selected": false,
"type": "genericNode",
"width": 384
"id": "reactflow__edge-MemoryComponent-u6m5G{œbaseClassesœ:[œstrœ,œTextœ,œobjectœ],œdataTypeœ:œMemoryComponentœ,œidœ:œMemoryComponent-u6m5Gœ}-Prompt-kykM2{œfieldNameœ:œContextœ,œidœ:œPrompt-kykM2œ,œinputTypesœ:[œDocumentœ,œMessageœ,œRecordœ,œTextœ],œtypeœ:œstrœ}"
}
],
"viewport": {
"x": -569.862554459756,
"y": -42.08339711050985,
"zoom": 0.4868590524514978
"x": -511.79726701119625,
"y": 48.514712353620894,
"zoom": 0.4612356948928673
}
},
"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.",
"icon": "🤖",
"icon_bg_color": "#FFD700",
"id": "edee50d3-a7e7-4cc7-9448-cc662300e8fb",
"is_component": false,
"last_tested_version": "1.0.0a52",
"name": "Memory Chatbot"
"name": "Memory Chatbot",
"last_tested_version": "1.0.0a54",
"is_component": false
}