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

This commit is contained in:
anovazzi1 2024-03-30 18:50:35 -03:00
commit 782ec35e20
11 changed files with 58 additions and 22 deletions

View file

@ -12,16 +12,29 @@ class TextComponent(CustomComponent):
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},
"input_value": {
"display_name": "Value",
"input_types": ["Text", "Record"],
"info": "Text or Record to be passed.",
},
"record_template": {
"display_name": "Record Template",
"multiline": True,
"info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.",
"advanced": True,
},
}
def build(
self,
input_value: Optional[Union[Text, Record]] = "",
record_template: Optional[str] = "Text: {text}\nData: {data}",
record_template: Optional[str] = "{text}",
) -> Text:
if isinstance(input_value, Record):
if record_template == "":
# it should be dynamically set to the Record's .text_key value
# meaning, if text_key = "bacon", then record_template = "{bacon}"
record_template = "{" + input_value.text_key + "}"
input_value = records_to_text(template=record_template, records=input_value)
self.status = input_value
if not input_value:

View file

@ -35,6 +35,8 @@ class LCModelComponent(CustomComponent):
self, runnable: BaseChatModel, stream: bool, input_value: str, system_message: Optional[str] = None
):
messages: list[Union[HumanMessage, SystemMessage]] = []
if not input_value and not system_message:
raise ValueError("The message you want to send to the model is empty.")
if system_message:
messages.append(SystemMessage(content=system_message))
if input_value:

View file

@ -9,7 +9,7 @@ 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
from langflow.utils.util import unescape_string
class SplitTextComponent(CustomComponent):
@ -54,7 +54,6 @@ class SplitTextComponent(CustomComponent):
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

View file

@ -13,15 +13,20 @@ class TextInput(TextComponent):
return {
"input_value": {
"display_name": "Value",
"input_types": ["Record"],
"input_types": ["Text", "Record"],
"info": "Text or Record to be passed as input.",
},
"record_template": {"display_name": "Record Template", "multiline": True},
"record_template": {
"display_name": "Record Template",
"multiline": True,
"info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.",
"advanced": True,
},
}
def build(
self,
input_value: Optional[str] = "",
record_template: Optional[str] = "{text}",
record_template: Optional[str] = "",
) -> Text:
return super().build(input_value=input_value, record_template=record_template)

View file

@ -16,8 +16,13 @@ class TextOutput(TextComponent):
"input_types": ["Record"],
"info": "Text or Record to be passed as output.",
},
"record_template": {"display_name": "Record Template", "multiline": True},
"record_template": {
"display_name": "Record Template",
"multiline": True,
"info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.",
"advanced": True,
},
}
def build(self, input_value: Optional[Text] = "", record_template: str = "{text}") -> Text:
def build(self, input_value: Optional[Text] = "", record_template: str = "") -> Text:
return super().build(input_value=input_value, record_template=record_template)

View file

@ -603,8 +603,7 @@ class Graph:
# This is a hack to make sure that the LLM vertex is sent to
# the toolkit vertex
self._build_vertex_params()
# remove invalid vertices
self._validate_vertices()
# Now that we have the vertices and edges
# We need to map the vertices that are connected to
# to ChatVertex instances
@ -631,14 +630,6 @@ class Graph:
if isinstance(vertex, ToolkitVertex):
vertex.params["llm"] = llm_vertex
def _validate_vertices(self) -> None:
"""Check that all vertices have edges"""
if len(self.vertices) == 1:
return
for vertex in self.vertices:
if not self._validate_vertex(vertex):
raise ValueError(f"{vertex.display_name} is not connected to any other components")
def _validate_vertex(self, vertex: Vertex) -> bool:
"""Validates a vertex."""
# All vertices that do not have edges are invalid

View file

@ -74,12 +74,11 @@ export const EditFlowSettings: React.FC<InputProps> = ({
onChange={handleDescriptionChange}
value={description!}
placeholder="Flow description"
className="mt-2 max-h-[100px] font-normal resize-none"
className="mt-2 max-h-[100px] resize-none font-normal"
rows={3}
onDoubleClickCapture={(event) => {
handleFocus(event);
}}
/>
) : (
<span

View file

@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M16 8.016A8.522 8.522 0 008.016 16h-.032A8.521 8.521 0 000 8.016v-.032A8.521 8.521 0 007.984 0h.032A8.522 8.522 0 0016 7.984v.032z" fill="url(#prefix__paint0_radial_980_20147)"/><defs><radialGradient id="prefix__paint0_radial_980_20147" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(16.1326 5.4553 -43.70045 129.2322 1.588 6.503)"><stop offset=".067" stop-color="#9168C0"/><stop offset=".343" stop-color="#5684D1"/><stop offset=".672" stop-color="#1BA1E3"/></radialGradient></defs></svg>

After

Width:  |  Height:  |  Size: 599 B

View file

@ -0,0 +1,10 @@
const SvgGoogleGenerativeAI = (props) => (<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" {...props}>
<path d="M16 8.016A8.522 8.522 0 008.016 16h-.032A8.521 8.521 0 000 8.016v-.032A8.521 8.521 0 007.984 0h.032A8.522 8.522 0 0016 7.984v.032z" fill="url(#prefix__paint0_radial_980_20147)"/>
<defs>
<radialGradient id="prefix__paint0_radial_980_20147" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(16.1326 5.4553 -43.70045 129.2322 1.588 6.503)">
<stop offset=".067" stop-color="#9168C0"/><stop offset=".343" stop-color="#5684D1"/><stop offset=".672" stop-color="#1BA1E3"/>
</radialGradient>
</defs>
</svg>
);
export default SvgGoogleGenerativeAI;

View file

@ -0,0 +1,9 @@
import React, { forwardRef } from "react";
import SvgGoogleGenerativeAI from "./GoogleGemini";
export const GoogleGenerativeAIIcon = forwardRef<
SVGSVGElement,
React.PropsWithChildren<{}>
>((props, ref) => {
return <SvgGoogleGenerativeAI ref={ref} {...props} />;
});

View file

@ -151,6 +151,7 @@ import { EvernoteIcon } from "../icons/Evernote";
import { FBIcon } from "../icons/FacebookMessenger";
import { GitBookIcon } from "../icons/GitBook";
import { GoogleIcon } from "../icons/Google";
import { GoogleGenerativeAIIcon } from "../icons/GoogleGenerativeAI";
import {
GradientInfinity,
GradientSave,
@ -328,6 +329,7 @@ export const nodeIconsLucide: iconsType = {
GoogleSearchResults: GoogleIcon,
GoogleSearchRun: GoogleIcon,
Google: GoogleIcon,
GoogleGenerativeAI: GoogleGenerativeAIIcon,
HNLoader: HackerNewsIcon,
HuggingFaceHub: HuggingFaceIcon,
HuggingFace: HuggingFaceIcon,