diff --git a/langflow1.db b/langflow1.db new file mode 100644 index 000000000..2b39da5dd Binary files /dev/null and b/langflow1.db differ diff --git a/src/backend/langflow/services/chat/utils.py b/src/backend/langflow/services/chat/utils.py index 85e6cdcd5..271c0e85b 100644 --- a/src/backend/langflow/services/chat/utils.py +++ b/src/backend/langflow/services/chat/utils.py @@ -8,7 +8,6 @@ from loguru import logger from langflow.api.v1.schemas import ChatMessage from langflow.interface.utils import try_setting_streaming_options from langflow.processing.base import get_result_and_steps -from langflow.utils.chat import ChatDefinition LANGCHAIN_RUNNABLES = (Chain, Runnable, AgentExecutor) @@ -40,20 +39,6 @@ async def process_graph( client_id=client_id, session_id=session_id, ) - elif isinstance(build_result, ChatDefinition): - raw_output = await run_build_result( - build_result, - chat_inputs, - client_id=client_id, - session_id=session_id, - ) - if isinstance(raw_output, dict): - if not build_result.output_key: - raise ValueError("No output key provided to ChatDefinition when returning a dict.") - result = raw_output[build_result.output_key] - else: - result = raw_output - intermediate_steps = [] else: raise TypeError(f"Unknown type {type(build_result)}") logger.debug("Generated result and intermediate_steps") diff --git a/src/backend/langflow/utils/chat.py b/src/backend/langflow/utils/chat.py deleted file mode 100644 index e1621bdab..000000000 --- a/src/backend/langflow/utils/chat.py +++ /dev/null @@ -1,34 +0,0 @@ -from typing import Any, Callable, Optional, Union - -from langchain_core.prompts import PromptTemplate as LCPromptTemplate -from langflow.utils.prompt import GenericPromptTemplate -from llama_index.prompts import PromptTemplate as LIPromptTemplate - -PromptTemplate = Union[LCPromptTemplate, LIPromptTemplate] - - -class ChatDefinition: - def __init__( - self, - func: Callable, - inputs: list[str], - output_key: Optional[str] = None, - prompt_template: Optional[PromptTemplate] = None, - ): - self.func = func - self.input_keys = inputs - self.output_key = output_key - self.prompt_template = prompt_template - - @classmethod - def from_prompt_template(cls, prompt_template: PromptTemplate, func: Callable, output_key: Optional[str] = None): - prompt = GenericPromptTemplate(prompt_template) - return cls( - func=func, - inputs=prompt.input_keys, - output_key=output_key, - prompt_template=prompt_template, - ) - - def __call__(self, inputs: dict, callbacks: Optional[Any] = None) -> dict: - return self.func(inputs, callbacks) diff --git a/src/backend/langflow/utils/prompt.py b/src/backend/langflow/utils/prompt.py deleted file mode 100644 index 871193f45..000000000 --- a/src/backend/langflow/utils/prompt.py +++ /dev/null @@ -1,58 +0,0 @@ -from typing import Any, Union - -from langchain_core.prompts import PromptTemplate as LCPromptTemplate -from llama_index.prompts import PromptTemplate as LIPromptTemplate - -PromptTemplateTypes = Union[LCPromptTemplate, LIPromptTemplate] - - -class GenericPromptTemplate: - def __init__(self, prompt_template: PromptTemplateTypes): - object.__setattr__(self, "prompt_template", prompt_template) - - @property - def input_keys(self): - prompt_template = object.__getattribute__(self, "prompt_template") - if isinstance(prompt_template, LCPromptTemplate): - return prompt_template.input_variables - elif isinstance(prompt_template, LIPromptTemplate): - return prompt_template.template_vars - else: - raise TypeError(f"Unknown prompt template type {type(prompt_template)}") - - def to_lc_prompt(self): - prompt_template = object.__getattribute__(self, "prompt_template") - if isinstance(prompt_template, LCPromptTemplate): - return prompt_template - elif isinstance(prompt_template, LIPromptTemplate): - return LCPromptTemplate.from_template(prompt_template.get_template()) - else: - raise TypeError(f"Unknown prompt template type {type(prompt_template)}") - - def to_li_prompt(self): - prompt_template = object.__getattribute__(self, "prompt_template") - if isinstance(prompt_template, LIPromptTemplate): - return prompt_template - elif isinstance(prompt_template, LCPromptTemplate): - return LIPromptTemplate(template=prompt_template.template) - else: - raise TypeError(f"Unknown prompt template type {type(prompt_template)}") - - def __or__(self, other): - prompt_template = object.__getattribute__(self, "prompt_template") - if isinstance(prompt_template, LIPromptTemplate): - return self.to_lc_prompt() | other - else: - raise TypeError(f"Unknown prompt template type {type(other)}") - - def __getattribute__(self, name: str) -> Any: - if name in { - "input_keys", - "to_lc_prompt", - "to_li_prompt", - "__or__", - "prompt_template", - }: - return object.__getattribute__(self, name) - prompt_template = object.__getattribute__(self, "prompt_template") - return getattr(prompt_template, name) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 7b04f6be4..9278f2b23 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -314,9 +314,8 @@ export default function ParameterComponent({ <>
{proxy ? ( @@ -429,8 +428,7 @@ export default function ParameterComponent({ newNode.data.node.template[name].load_from_db = true; return newNode; }); - } - else{ + } else { setNode(data.id, (oldNode) => { let newNode = cloneDeep(oldNode); newNode.data = { diff --git a/src/frontend/src/components/inputComponent/index.tsx b/src/frontend/src/components/inputComponent/index.tsx index 9dfc96a9a..cd2846cdb 100644 --- a/src/frontend/src/components/inputComponent/index.tsx +++ b/src/frontend/src/components/inputComponent/index.tsx @@ -1,11 +1,13 @@ import { Listbox, Transition } from "@headlessui/react"; import * as Form from "@radix-ui/react-form"; import { Fragment, useEffect, useRef, useState } from "react"; +import AddNewVariableButton from "../../pages/globalVariablesPage/components/addNewVariableButton"; import { InputComponentType } from "../../types/components"; import { handleKeyDown } from "../../utils/reactflowUtils"; -import { classNames } from "../../utils/utils"; +import { classNames, cn } from "../../utils/utils"; import IconComponent from "../genericIconComponent"; import { Input } from "../ui/input"; +import { Separator } from "../ui/separator"; export default function InputComponent({ autoFocus = false, @@ -26,7 +28,6 @@ export default function InputComponent({ const [pwdVisible, setPwdVisible] = useState(false); const refInput = useRef(null); const [showOptions, setShowOptions] = useState(false); - const [filteredOpts, setFilteredValue] = useState(options); // Clear component state useEffect(() => { @@ -35,13 +36,12 @@ export default function InputComponent({ } }, [disabled]); - const filteredOptions = filteredOpts.filter((option) => + const filteredOptions = options.filter((option) => option.toLowerCase().includes(value.toLowerCase()) ); function onInputLostFocus(event): void { if (onBlur) onBlur(event); - setShowOptions(false); } return ( @@ -107,103 +107,115 @@ export default function InputComponent({ handleKeyDown(e, value, ""); if (blurOnEnter && e.key === "Enter") refInput.current?.blur(); }} - onFocus={() => setShowOptions(true)} /> - { - /* options.length > 0 && filteredOptions.length > 0 */ true ? ( - { - onChange(val); - }} - > - <> -
- - { + onChange(val); + }} + > + <> +
+ + +
+
+ + Global Variables +
+
+ + + +
+
+ + {filteredOptions.map((option, id) => ( + + classNames( + active ? " bg-accent" : "", + editNode + ? "dropdown-component-false-option" + : "dropdown-component-true-option", + " hover:bg-accent" + ) + } + value={option} > - {filteredOptions.map((option, id) => ( - - classNames( - active ? " bg-accent" : "", - editNode - ? "dropdown-component-false-option" - : "dropdown-component-true-option", - " hover:bg-accent" - ) - } - value={option} - > - {({ selected, active }) => ( - <> - - {option} - + {({ selected, active }) => ( + <> + + {option} + - {selected ? ( - - - ) : null} - - )} - - ))} -
-
-
- - - ) : null - } + {selected ? ( + + + ) : null} + + )} + + ))} +
+
+
+ +
)} {options.length > 0 && ( - )} @@ -212,6 +224,7 @@ export default function InputComponent({ type="button" tabIndex={-1} className={classNames( + "mb-px", editNode ? "input-component-true-button" : "input-component-false-button" diff --git a/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx b/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx index c0a7deba2..51f88ddf0 100644 --- a/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx +++ b/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx @@ -10,7 +10,7 @@ import { useGlobalVariablesStore } from "../../../stores/globalVariables"; //TODO IMPLEMENT FORM LOGIC -export default function AddNewVariableButton(): JSX.Element { +export default function AddNewVariableButton({children}): JSX.Element { const [key, setKey] = useState(""); const [value, setValue] = useState(""); const [provider, setProvider] = useState(""); @@ -33,25 +33,24 @@ export default function AddNewVariableButton(): JSX.Element { }); } return ( - + Create a new Variable - + {children} -
-
+
{ setKey(e.target.value); }} - placeholder="example name" + placeholder="Insert a name for the variable..." > -
-