Merge branch 'zustand/io/migration' of personal:logspace-ai/langflow into zustand/io/migration
This commit is contained in:
commit
c1f29c1d76
7 changed files with 155 additions and 62 deletions
|
|
@ -26,6 +26,12 @@ class MessageHistoryComponent(CustomComponent):
|
||||||
"info": "Session ID of the chat history.",
|
"info": "Session ID of the chat history.",
|
||||||
"input_types": ["Text"],
|
"input_types": ["Text"],
|
||||||
},
|
},
|
||||||
|
"order": {
|
||||||
|
"options": ["Ascending", "Descending"],
|
||||||
|
"display_name": "Order",
|
||||||
|
"info": "Order of the messages.",
|
||||||
|
"advanced": True,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def build(
|
def build(
|
||||||
|
|
@ -34,7 +40,9 @@ class MessageHistoryComponent(CustomComponent):
|
||||||
sender_name: Optional[str] = None,
|
sender_name: Optional[str] = None,
|
||||||
session_id: Optional[str] = None,
|
session_id: Optional[str] = None,
|
||||||
n_messages: int = 5,
|
n_messages: int = 5,
|
||||||
|
order: Optional[str] = "Descending",
|
||||||
) -> List[Record]:
|
) -> List[Record]:
|
||||||
|
order = "DESC" if order == "Descending" else "ASC"
|
||||||
if sender == "Machine and User":
|
if sender == "Machine and User":
|
||||||
sender = None
|
sender = None
|
||||||
messages = get_messages(
|
messages = get_messages(
|
||||||
|
|
@ -42,6 +50,7 @@ class MessageHistoryComponent(CustomComponent):
|
||||||
sender_name=sender_name,
|
sender_name=sender_name,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
limit=n_messages,
|
limit=n_messages,
|
||||||
|
order=order,
|
||||||
)
|
)
|
||||||
self.status = messages
|
self.status = messages
|
||||||
return messages
|
return messages
|
||||||
|
|
|
||||||
87
src/backend/base/langflow/components/helpers/SplitText.py
Normal file
87
src/backend/base/langflow/components/helpers/SplitText.py
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from langchain.text_splitter import (
|
||||||
|
RecursiveCharacterTextSplitter,
|
||||||
|
CharacterTextSplitter,
|
||||||
|
)
|
||||||
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
|
from langflow.interface.custom.custom_component import CustomComponent
|
||||||
|
from langflow.schema import Record
|
||||||
|
from langflow.field_typing import Text
|
||||||
|
from langflow.utils.util import build_loader_repr_from_records, unescape_string
|
||||||
|
|
||||||
|
|
||||||
|
class SplitTextComponent(CustomComponent):
|
||||||
|
display_name: str = "Split Text"
|
||||||
|
description: str = "Split text into chunks of a specified length."
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
return {
|
||||||
|
"texts": {
|
||||||
|
"display_name": "Texts",
|
||||||
|
"info": "Texts to split.",
|
||||||
|
"input_types": ["Text"],
|
||||||
|
},
|
||||||
|
"separators": {
|
||||||
|
"display_name": "Separators",
|
||||||
|
"info": 'The characters to split on.\nIf left empty defaults to [" "].',
|
||||||
|
"is_list": True,
|
||||||
|
},
|
||||||
|
"chunk_size": {
|
||||||
|
"display_name": "Chunk Size",
|
||||||
|
"info": "The maximum length of each chunk.",
|
||||||
|
"field_type": "int",
|
||||||
|
"value": 1000,
|
||||||
|
},
|
||||||
|
"chunk_overlap": {
|
||||||
|
"display_name": "Chunk Overlap",
|
||||||
|
"info": "The amount of overlap between chunks.",
|
||||||
|
"field_type": "int",
|
||||||
|
"value": 200,
|
||||||
|
},
|
||||||
|
"recursive": {
|
||||||
|
"display_name": "Recursive",
|
||||||
|
},
|
||||||
|
"code": {"show": False},
|
||||||
|
}
|
||||||
|
|
||||||
|
def build(
|
||||||
|
self,
|
||||||
|
texts: list[Text],
|
||||||
|
separators: Optional[list[str]] = [" "],
|
||||||
|
chunk_size: Optional[int] = 1000,
|
||||||
|
chunk_overlap: Optional[int] = 200,
|
||||||
|
recursive: bool = False,
|
||||||
|
) -> list[Record]:
|
||||||
|
|
||||||
|
separators = [unescape_string(x) for x in separators]
|
||||||
|
|
||||||
|
# Make sure chunk_size and chunk_overlap are ints
|
||||||
|
if isinstance(chunk_size, str):
|
||||||
|
chunk_size = int(chunk_size)
|
||||||
|
if isinstance(chunk_overlap, str):
|
||||||
|
chunk_overlap = int(chunk_overlap)
|
||||||
|
|
||||||
|
if recursive:
|
||||||
|
splitter = RecursiveCharacterTextSplitter(
|
||||||
|
separators=separators,
|
||||||
|
chunk_size=chunk_size,
|
||||||
|
chunk_overlap=chunk_overlap,
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
splitter = CharacterTextSplitter(
|
||||||
|
separator=separators[0],
|
||||||
|
chunk_size=chunk_size,
|
||||||
|
chunk_overlap=chunk_overlap,
|
||||||
|
)
|
||||||
|
|
||||||
|
documents = []
|
||||||
|
for _text in texts:
|
||||||
|
# documents.append(_input.to_lc_document())
|
||||||
|
documents.append(Document(page_content=_text))
|
||||||
|
|
||||||
|
records = self.to_records(splitter.split_documents(documents))
|
||||||
|
self.status = records
|
||||||
|
return records
|
||||||
|
|
@ -12,6 +12,7 @@ def get_messages(
|
||||||
sender_name: Optional[str] = None,
|
sender_name: Optional[str] = None,
|
||||||
session_id: Optional[str] = None,
|
session_id: Optional[str] = None,
|
||||||
order_by: Optional[str] = "timestamp",
|
order_by: Optional[str] = "timestamp",
|
||||||
|
order: Optional[str] = "DESC",
|
||||||
limit: Optional[int] = None,
|
limit: Optional[int] = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
@ -34,6 +35,7 @@ def get_messages(
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
order_by=order_by,
|
order_by=order_by,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
|
order=order,
|
||||||
)
|
)
|
||||||
|
|
||||||
records: list[Record] = []
|
records: list[Record] = []
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ class MonitorService(Service):
|
||||||
sender_name: Optional[str] = None,
|
sender_name: Optional[str] = None,
|
||||||
session_id: Optional[str] = None,
|
session_id: Optional[str] = None,
|
||||||
order_by: Optional[str] = "timestamp",
|
order_by: Optional[str] = "timestamp",
|
||||||
|
order: Optional[str] = "DESC",
|
||||||
limit: Optional[int] = None,
|
limit: Optional[int] = None,
|
||||||
):
|
):
|
||||||
query = "SELECT sender_name, sender, session_id, message, artifacts, timestamp FROM messages"
|
query = "SELECT sender_name, sender, session_id, message, artifacts, timestamp FROM messages"
|
||||||
|
|
@ -128,7 +129,8 @@ class MonitorService(Service):
|
||||||
query += " WHERE " + " AND ".join(conditions)
|
query += " WHERE " + " AND ".join(conditions)
|
||||||
|
|
||||||
if order_by:
|
if order_by:
|
||||||
query += f" ORDER BY {order_by}"
|
# Make sure the order is from newest to oldest
|
||||||
|
query += f" ORDER BY {order_by} {order.upper()}"
|
||||||
|
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
query += f" LIMIT {limit}"
|
query += f" LIMIT {limit}"
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ def add_row_to_table(
|
||||||
validated_data = model(**monitor_data)
|
validated_data = model(**monitor_data)
|
||||||
|
|
||||||
# Extract data for the insert statement
|
# Extract data for the insert statement
|
||||||
validated_dict = validated_data.model_dump(exclude_unset=True)
|
validated_dict = validated_data.model_dump()
|
||||||
keys = [key for key in validated_dict.keys() if key != INDEX_KEY]
|
keys = [key for key in validated_dict.keys() if key != INDEX_KEY]
|
||||||
columns = ", ".join(keys)
|
columns = ", ".join(keys)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -402,9 +402,7 @@ export default function ParameterComponent({
|
||||||
{title}
|
{title}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<span
|
<span className={(required ? "ml-2 " : "") + "text-status-red"}>
|
||||||
className={(info === "" ? "" : "ml-1 ") + " pl-1 text-status-red"}
|
|
||||||
>
|
|
||||||
{required ? "*" : ""}
|
{required ? "*" : ""}
|
||||||
</span>
|
</span>
|
||||||
<div className="">
|
<div className="">
|
||||||
|
|
|
||||||
|
|
@ -106,13 +106,7 @@ export default function IOModal({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseModal
|
<BaseModal
|
||||||
size={
|
size={selectedTab === 0 ? "large-thin" : "large"}
|
||||||
haveChat || selectedViewField
|
|
||||||
? selectedTab === 0
|
|
||||||
? "large-thin"
|
|
||||||
: "large"
|
|
||||||
: "small"
|
|
||||||
}
|
|
||||||
open={open}
|
open={open}
|
||||||
setOpen={setOpen}
|
setOpen={setOpen}
|
||||||
disable={disable}
|
disable={disable}
|
||||||
|
|
@ -135,8 +129,7 @@ export default function IOModal({
|
||||||
{selectedTab !== 0 && (
|
{selectedTab !== 0 && (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"mr-6 flex h-full w-2/6 flex-shrink-0 flex-col justify-start transition-all duration-300",
|
"mr-6 flex h-full w-2/6 w-2/6 flex-shrink-0 flex-col justify-start transition-all duration-300"
|
||||||
haveChat || selectedViewField ? "w-2/6" : "w-full"
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Tabs
|
<Tabs
|
||||||
|
|
@ -299,54 +292,54 @@ export default function IOModal({
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{haveChat || selectedViewField ? (
|
<div className="flex h-full min-w-96 flex-grow">
|
||||||
<div className="flex h-full min-w-96 flex-grow">
|
{selectedViewField && (
|
||||||
{selectedViewField && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
"flex h-full w-full flex-col items-start gap-4 pt-4",
|
|
||||||
!selectedViewField ? "hidden" : ""
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className="font-xl flex items-center justify-center gap-3 font-semibold">
|
|
||||||
<button onClick={() => setSelectedViewField(undefined)}>
|
|
||||||
<IconComponent
|
|
||||||
name={"ArrowLeft"}
|
|
||||||
className="h-6 w-6"
|
|
||||||
></IconComponent>
|
|
||||||
</button>
|
|
||||||
{
|
|
||||||
nodes.find((node) => node.id === selectedViewField.id)
|
|
||||||
?.data.node.display_name
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
<div className="h-full w-full">
|
|
||||||
{inputs.some(
|
|
||||||
(input) => input.id === selectedViewField.id
|
|
||||||
) ? (
|
|
||||||
<IOFieldView
|
|
||||||
type={InputOutput.INPUT}
|
|
||||||
left={false}
|
|
||||||
fieldType={selectedViewField.type!}
|
|
||||||
fieldId={selectedViewField.id!}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<IOFieldView
|
|
||||||
type={InputOutput.OUTPUT}
|
|
||||||
left={false}
|
|
||||||
fieldType={selectedViewField.type!}
|
|
||||||
fieldId={selectedViewField.id!}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-full w-full",
|
"flex h-full w-full flex-col items-start gap-4 pt-4",
|
||||||
selectedViewField ? "hidden" : ""
|
!selectedViewField ? "hidden" : ""
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
<div className="font-xl flex items-center justify-center gap-3 font-semibold">
|
||||||
|
<button onClick={() => setSelectedViewField(undefined)}>
|
||||||
|
<IconComponent
|
||||||
|
name={"ArrowLeft"}
|
||||||
|
className="h-6 w-6"
|
||||||
|
></IconComponent>
|
||||||
|
</button>
|
||||||
|
{
|
||||||
|
nodes.find((node) => node.id === selectedViewField.id)
|
||||||
|
?.data.node.display_name
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="h-full w-full">
|
||||||
|
{inputs.some(
|
||||||
|
(input) => input.id === selectedViewField.id
|
||||||
|
) ? (
|
||||||
|
<IOFieldView
|
||||||
|
type={InputOutput.INPUT}
|
||||||
|
left={false}
|
||||||
|
fieldType={selectedViewField.type!}
|
||||||
|
fieldId={selectedViewField.id!}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<IOFieldView
|
||||||
|
type={InputOutput.OUTPUT}
|
||||||
|
left={false}
|
||||||
|
fieldType={selectedViewField.type!}
|
||||||
|
fieldId={selectedViewField.id!}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex h-full w-full",
|
||||||
|
selectedViewField ? "hidden" : ""
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{haveChat ? (
|
||||||
<ChatView
|
<ChatView
|
||||||
sendMessage={sendMessage}
|
sendMessage={sendMessage}
|
||||||
chatValue={chatValue}
|
chatValue={chatValue}
|
||||||
|
|
@ -354,11 +347,13 @@ export default function IOModal({
|
||||||
lockChat={lockChat}
|
lockChat={lockChat}
|
||||||
setLockChat={setLockChat}
|
setLockChat={setLockChat}
|
||||||
/>
|
/>
|
||||||
</div>
|
) : (
|
||||||
|
<span className="flex h-full w-full items-center justify-center font-thin text-muted-foreground">
|
||||||
|
Select an IO component to view
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
</div>
|
||||||
<div className="absolute bottom-8 right-8"></div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</BaseModal.Content>
|
</BaseModal.Content>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue