Merge branch 'zustand/io/migration' of personal:logspace-ai/langflow into zustand/io/migration

This commit is contained in:
anovazzi1 2024-03-29 17:55:36 -03:00
commit 6a25d4b761
7 changed files with 85 additions and 41 deletions

View file

@ -62,4 +62,6 @@ jobs:
context: .
push: true
file: ./build_and_push.Dockerfile
tags: logspace/langflow:${{ steps.check-version.outputs.version }}
tags: |
logspace/langflow:${{ steps.check-version.outputs.version }}
logspace/langflow:latest-dev

View file

@ -2,6 +2,7 @@ import warnings
from typing import Optional, Union
from langflow.field_typing import Text
from langflow.helpers.record import records_to_text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.memory import add_messages
from langflow.schema import Record
@ -34,6 +35,12 @@ class ChatComponent(CustomComponent):
"info": "Return the message as a record containing the sender, sender_name, and session_id.",
"advanced": True,
},
"record_template": {
"display_name": "Record Template",
"multiline": True,
"info": "In case of Message being a Record, this template will be used to convert it to text.",
"advanced": True,
},
}
def store_message(
@ -76,9 +83,10 @@ class ChatComponent(CustomComponent):
self,
sender: Optional[str] = "User",
sender_name: Optional[str] = "User",
input_value: Optional[str] = None,
input_value: Optional[Union[str, Record]] = None,
session_id: Optional[str] = None,
return_record: Optional[bool] = False,
record_template: Optional[str] = "Text: {text}\nData: {data}",
) -> Union[Text, Record]:
input_value_record: Optional[Record] = None
if return_record:
@ -96,6 +104,8 @@ class ChatComponent(CustomComponent):
"session_id": session_id,
},
)
elif isinstance(input_value, Record):
input_value = records_to_text(template=record_template, records=input_value)
if not input_value:
input_value = ""
if return_record and input_value_record:

View file

@ -1,18 +1,28 @@
from typing import Optional
from typing import Optional, Union
from langflow.field_typing import Text
from langflow.helpers.record import records_to_text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record
class TextComponent(CustomComponent):
display_name = "Text Component"
description = "Used to pass text to the next component."
field_config = {
"input_value": {"display_name": "Value", "multiline": True},
}
def build_config(self):
return {
"input_value": {"display_name": "Value", "input_types": ["Record"], "info": "Text or Record to be passed."},
"record_template": {"display_name": "Record Template", "multiline": True},
}
def build(self, input_value: Optional[str] = "") -> Text:
def build(
self,
input_value: Optional[Union[Text, Record]] = "",
record_template: Optional[str] = "Text: {text}\nData: {data}",
) -> Text:
if isinstance(input_value, Record):
input_value = records_to_text(template=record_template, records=input_value)
self.status = input_value
if not input_value:
input_value = ""

View file

@ -6,7 +6,21 @@ from langflow.field_typing import Text
class TextInput(TextComponent):
display_name = "Text Input"
description = "Capture and send text inputs."
description = "Capture Text or Record and send text inputs."
def build(self, input_value: Optional[str] = "") -> Text:
return super().build(input_value=input_value)
def build_config(self):
return {
"input_value": {
"display_name": "Value",
"input_types": ["Record"],
"info": "Text or Record to be passed as input.",
},
"record_template": {"display_name": "Record Template", "multiline": True},
}
def build(
self,
input_value: Optional[str] = "",
record_template: Optional[str] = "{text}",
) -> Text:
return super().build(input_value=input_value, record_template=record_template)

View file

@ -17,6 +17,7 @@ class ChatOutput(ChatComponent):
input_value: Optional[str] = None,
session_id: Optional[str] = None,
return_record: Optional[bool] = False,
record_template: Optional[str] = "{text}",
) -> Union[Text, Record]:
return super().build(
sender=sender,
@ -24,4 +25,5 @@ class ChatOutput(ChatComponent):
input_value=input_value,
session_id=session_id,
return_record=return_record,
record_template=record_template,
)

View file

@ -8,9 +8,15 @@ class TextOutput(TextComponent):
display_name = "Text Output"
description = "Used to send a text output."
field_config = {
"input_value": {"display_name": "Value"},
}
def build_config(self):
return {
"input_value": {
"display_name": "Value",
"input_types": ["Record"],
"info": "Text or Record to be passed as output.",
},
"record_template": {"display_name": "Record Template", "multiline": True},
}
def build(self, input_value: Optional[Text] = "") -> Text:
return super().build(input_value=input_value)
def build(self, input_value: Optional[Text] = "", record_template: str = "{text}") -> Text:
return super().build(input_value=input_value, record_template=record_template)

View file

@ -5,7 +5,6 @@ import ShadTooltip from "../../../../components/ShadTooltipComponent";
import IconComponent from "../../../../components/genericIconComponent";
import { Input } from "../../../../components/ui/input";
import { Separator } from "../../../../components/ui/separator";
import { PRIORITY_SIDEBAR_ORDER } from "../../../../constants/constants";
import ExportModal from "../../../../modals/exportModal";
import ShareModal from "../../../../modals/shareModal";
import useAlertStore from "../../../../stores/alertStore";
@ -282,32 +281,7 @@ export default function ExtraSidebar(): JSX.Element {
</div>
</div>
)}
{index === PRIORITY_SIDEBAR_ORDER.length - 2 && (
<>
<a
target={"_blank"}
href="https://langflow.store"
className="components-disclosure-arrangement"
>
<div className="flex gap-4">
{/* BUG ON THIS ICON */}
<SparklesIcon
strokeWidth={1.5}
className="w-[22px] text-primary"
/>
<span className="components-disclosure-title">
Discover More
</span>
</div>
<div className="components-disclosure-div">
<div>
<LinkIcon className="h-4 w-4 text-foreground" />
</div>
</div>
</a>
</>
)}
<DisclosureComponent
openDisc={
getFilterEdge.length !== 0 || search.length !== 0
@ -368,6 +342,32 @@ export default function ExtraSidebar(): JSX.Element {
))}
</div>
</DisclosureComponent>
{index === Object.keys(dataFilter).length - 1 && (
<>
<a
target={"_blank"}
href="https://langflow.store"
className="components-disclosure-arrangement"
>
<div className="flex gap-4">
{/* BUG ON THIS ICON */}
<SparklesIcon
strokeWidth={1.5}
className="w-[22px] text-primary"
/>
<span className="components-disclosure-title">
Discover More
</span>
</div>
<div className="components-disclosure-div">
<div>
<LinkIcon className="h-4 w-4 text-foreground" />
</div>
</div>
</a>
</>
)}
</>
) : (
<div key={index}></div>