Fix formatting and remove unused imports
This commit is contained in:
parent
fb52f1368e
commit
c32a7f9f11
19 changed files with 85 additions and 112 deletions
|
|
@ -150,10 +150,9 @@ class OllamaLLM(CustomComponent):
|
||||||
"top_k": top_k,
|
"top_k": top_k,
|
||||||
"top_p": top_p,
|
"top_p": top_p,
|
||||||
}
|
}
|
||||||
|
|
||||||
# None Value remove
|
|
||||||
llm_params = {k: v for k, v in llm_params.items() if v is not None}
|
|
||||||
|
|
||||||
|
# None Value remove
|
||||||
|
llm_params = {k: v for k, v in llm_params.items() if v is not None}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
llm = Ollama(**llm_params)
|
llm = Ollama(**llm_params)
|
||||||
|
|
|
||||||
|
|
@ -15,29 +15,21 @@ class VectaraSelfQueryRetriverComponent(CustomComponent):
|
||||||
|
|
||||||
display_name: str = "Vectara Self Query Retriever for Vectara Vector Store"
|
display_name: str = "Vectara Self Query Retriever for Vectara Vector Store"
|
||||||
description: str = "Implementation of Vectara Self Query Retriever"
|
description: str = "Implementation of Vectara Self Query Retriever"
|
||||||
documentation = (
|
documentation = "https://python.langchain.com/docs/integrations/retrievers/self_query/vectara_self_query"
|
||||||
"https://python.langchain.com/docs/integrations/retrievers/self_query/vectara_self_query"
|
|
||||||
)
|
|
||||||
beta = True
|
beta = True
|
||||||
|
|
||||||
field_config = {
|
field_config = {
|
||||||
"code": {"show": True},
|
"code": {"show": True},
|
||||||
"vectorstore": {
|
"vectorstore": {"display_name": "Vector Store", "info": "Input Vectara Vectore Store"},
|
||||||
"display_name": "Vector Store",
|
"llm": {"display_name": "LLM", "info": "For self query retriever"},
|
||||||
"info": "Input Vectara Vectore Store"
|
"document_content_description": {
|
||||||
},
|
"display_name": "Document Content Description",
|
||||||
"llm": {
|
|
||||||
"display_name": "LLM",
|
|
||||||
"info": "For self query retriever"
|
|
||||||
},
|
|
||||||
"document_content_description":{
|
|
||||||
"display_name": "Document Content Description",
|
|
||||||
"info": "For self query retriever",
|
"info": "For self query retriever",
|
||||||
},
|
},
|
||||||
"metadata_field_info": {
|
"metadata_field_info": {
|
||||||
"display_name": "Metadata Field Info",
|
"display_name": "Metadata Field Info",
|
||||||
"info": "Each metadata field info is a string in the form of key value pair dictionary containing additional search metadata.\nExample input: {\"name\":\"speech\",\"description\":\"what name of the speech\",\"type\":\"string or list[string]\"}.\nThe keys should remain constant(name, description, type)",
|
"info": 'Each metadata field info is a string in the form of key value pair dictionary containing additional search metadata.\nExample input: {"name":"speech","description":"what name of the speech","type":"string or list[string]"}.\nThe keys should remain constant(name, description, type)',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def build(
|
def build(
|
||||||
|
|
@ -47,24 +39,19 @@ class VectaraSelfQueryRetriverComponent(CustomComponent):
|
||||||
llm: BaseLanguageModel,
|
llm: BaseLanguageModel,
|
||||||
metadata_field_info: List[str],
|
metadata_field_info: List[str],
|
||||||
) -> BaseRetriever:
|
) -> BaseRetriever:
|
||||||
|
|
||||||
metadata_field_obj = []
|
metadata_field_obj = []
|
||||||
|
|
||||||
for meta in metadata_field_info:
|
for meta in metadata_field_info:
|
||||||
meta_obj = json.loads(meta)
|
meta_obj = json.loads(meta)
|
||||||
if 'name' not in meta_obj or 'description' not in meta_obj or 'type' not in meta_obj :
|
if "name" not in meta_obj or "description" not in meta_obj or "type" not in meta_obj:
|
||||||
raise Exception('Incorrect metadata field info format.')
|
raise Exception("Incorrect metadata field info format.")
|
||||||
attribute_info = AttributeInfo(
|
attribute_info = AttributeInfo(
|
||||||
name = meta_obj['name'],
|
name=meta_obj["name"],
|
||||||
description = meta_obj['description'],
|
description=meta_obj["description"],
|
||||||
type = meta_obj['type'],
|
type=meta_obj["type"],
|
||||||
)
|
)
|
||||||
metadata_field_obj.append(attribute_info)
|
metadata_field_obj.append(attribute_info)
|
||||||
|
|
||||||
return SelfQueryRetriever.from_llm(
|
return SelfQueryRetriever.from_llm(
|
||||||
llm,
|
llm, vectorstore, document_content_description, metadata_field_obj, verbose=True
|
||||||
vectorstore,
|
)
|
||||||
document_content_description,
|
|
||||||
metadata_field_obj,
|
|
||||||
verbose=True
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -70,13 +70,7 @@ export default function ParameterComponent({
|
||||||
const { setErrorData, modalContextOpen } = useContext(alertContext);
|
const { setErrorData, modalContextOpen } = useContext(alertContext);
|
||||||
const updateNodeInternals = useUpdateNodeInternals();
|
const updateNodeInternals = useUpdateNodeInternals();
|
||||||
const [position, setPosition] = useState(0);
|
const [position, setPosition] = useState(0);
|
||||||
const {
|
const { tabId, flows, nodes, edges, setNode } = useContext(FlowsContext);
|
||||||
tabId,
|
|
||||||
flows,
|
|
||||||
nodes,
|
|
||||||
edges,
|
|
||||||
setNode,
|
|
||||||
} = useContext(FlowsContext);
|
|
||||||
|
|
||||||
const flow = flows.find((flow) => flow.id === tabId)?.data?.nodes ?? null;
|
const flow = flows.find((flow) => flow.id === tabId)?.data?.nodes ?? null;
|
||||||
|
|
||||||
|
|
@ -133,8 +127,8 @@ export default function ParameterComponent({
|
||||||
let newNode = cloneDeep(oldNode);
|
let newNode = cloneDeep(oldNode);
|
||||||
|
|
||||||
newNode.data = {
|
newNode.data = {
|
||||||
...newNode.data
|
...newNode.data,
|
||||||
}
|
};
|
||||||
|
|
||||||
newNode.data.node.template[name].value = newValue;
|
newNode.data.node.template[name].value = newValue;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { useContext, useState } from "react";
|
||||||
import Loading from "../../../components/ui/loading";
|
import Loading from "../../../components/ui/loading";
|
||||||
import { useSSE } from "../../../contexts/SSEContext";
|
import { useSSE } from "../../../contexts/SSEContext";
|
||||||
import { alertContext } from "../../../contexts/alertContext";
|
import { alertContext } from "../../../contexts/alertContext";
|
||||||
import { typesContext } from "../../../contexts/typesContext";
|
|
||||||
import { postBuildInit } from "../../../controllers/API";
|
import { postBuildInit } from "../../../controllers/API";
|
||||||
import { FlowType } from "../../../types/flow";
|
import { FlowType } from "../../../types/flow";
|
||||||
|
|
||||||
|
|
@ -36,10 +35,7 @@ export default function BuildTrigger({
|
||||||
if (isBuilding) {
|
if (isBuilding) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const errors = validateNodes(
|
const errors = validateNodes(nodes, edges);
|
||||||
nodes,
|
|
||||||
edges
|
|
||||||
);
|
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "Oops! Looks like you missed something",
|
title: "Oops! Looks like you missed something",
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ import { NodeType } from "../../types/flow";
|
||||||
export default function Chat({ flow }: ChatType): JSX.Element {
|
export default function Chat({ flow }: ChatType): JSX.Element {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [canOpen, setCanOpen] = useState(false);
|
const [canOpen, setCanOpen] = useState(false);
|
||||||
const { tabsState, isBuilt, setIsBuilt, isPending } = useContext(FlowsContext);
|
const { tabsState, isBuilt, setIsBuilt, isPending } =
|
||||||
|
useContext(FlowsContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import {
|
||||||
updateFlowInDatabase,
|
updateFlowInDatabase,
|
||||||
uploadFlowsToDatabase,
|
uploadFlowsToDatabase,
|
||||||
} from "../controllers/API";
|
} from "../controllers/API";
|
||||||
import { APIClassType, APITemplateType } from "../types/api";
|
import { APIClassType } from "../types/api";
|
||||||
import { tweakType } from "../types/components";
|
import { tweakType } from "../types/components";
|
||||||
import {
|
import {
|
||||||
FlowType,
|
FlowType,
|
||||||
|
|
@ -51,7 +51,6 @@ import {
|
||||||
scapedJSONStringfy,
|
scapedJSONStringfy,
|
||||||
updateEdgesHandleIds,
|
updateEdgesHandleIds,
|
||||||
updateIds,
|
updateIds,
|
||||||
updateTemplate,
|
|
||||||
} from "../utils/reactflowUtils";
|
} from "../utils/reactflowUtils";
|
||||||
import {
|
import {
|
||||||
createRandomKey,
|
createRandomKey,
|
||||||
|
|
@ -153,8 +152,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
const onNodesChange = useCallback(
|
const onNodesChange = useCallback(
|
||||||
(change: NodeChange[]) => {
|
(change: NodeChange[]) => {
|
||||||
onNodesChangeInternal(change);
|
onNodesChangeInternal(change);
|
||||||
if(!isPending)
|
if (!isPending) setPending(true);
|
||||||
setPending(true);
|
|
||||||
},
|
},
|
||||||
[onNodesChangeInternal, setPending, isPending]
|
[onNodesChangeInternal, setPending, isPending]
|
||||||
);
|
);
|
||||||
|
|
@ -162,8 +160,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
const onEdgesChange = useCallback(
|
const onEdgesChange = useCallback(
|
||||||
(edges: EdgeChange[]) => {
|
(edges: EdgeChange[]) => {
|
||||||
onEdgesChangeInternal(edges);
|
onEdgesChangeInternal(edges);
|
||||||
if(!isPending)
|
if (!isPending) setPending(true);
|
||||||
setPending(true);
|
|
||||||
},
|
},
|
||||||
[onEdgesChangeInternal, setPending, isPending]
|
[onEdgesChangeInternal, setPending, isPending]
|
||||||
);
|
);
|
||||||
|
|
@ -697,7 +694,11 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
|
|
||||||
const saveTimeoutId = useRef<NodeJS.Timeout | null>(null);
|
const saveTimeoutId = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
const saveCurrentFlow = (nodes: Node[], edges: Edge[], viewport: Viewport) => {
|
const saveCurrentFlow = (
|
||||||
|
nodes: Node[],
|
||||||
|
edges: Edge[],
|
||||||
|
viewport: Viewport
|
||||||
|
) => {
|
||||||
// Clear the previous timeout if it exists.
|
// Clear the previous timeout if it exists.
|
||||||
if (saveTimeoutId.current) {
|
if (saveTimeoutId.current) {
|
||||||
clearTimeout(saveTimeoutId.current);
|
clearTimeout(saveTimeoutId.current);
|
||||||
|
|
@ -710,8 +711,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
saveFlow({ ...currentFlow, data: { nodes, edges, viewport } }, true);
|
saveFlow({ ...currentFlow, data: { nodes, edges, viewport } }, true);
|
||||||
}
|
}
|
||||||
}, 300); // Delay of 300ms.
|
}, 300); // Delay of 300ms.
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
async function saveFlow(flow?: FlowType, silent?: boolean) {
|
async function saveFlow(flow?: FlowType, silent?: boolean) {
|
||||||
let newFlow;
|
let newFlow;
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,6 @@ export function TypesProvider({ children }: { children: ReactNode }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<typesContext.Provider
|
<typesContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import {
|
||||||
useEffect,
|
useEffect,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useReactFlow } from "reactflow";
|
|
||||||
import {
|
import {
|
||||||
HistoryItem,
|
HistoryItem,
|
||||||
UseUndoRedoOptions,
|
UseUndoRedoOptions,
|
||||||
|
|
@ -29,7 +28,8 @@ const defaultOptions: UseUndoRedoOptions = {
|
||||||
export const undoRedoContext = createContext<undoRedoContextType>(initialValue);
|
export const undoRedoContext = createContext<undoRedoContextType>(initialValue);
|
||||||
|
|
||||||
export function UndoRedoProvider({ children }) {
|
export function UndoRedoProvider({ children }) {
|
||||||
const { tabId, flows, setNodes, setEdges, nodes, edges } = useContext(FlowsContext);
|
const { tabId, flows, setNodes, setEdges, nodes, edges } =
|
||||||
|
useContext(FlowsContext);
|
||||||
|
|
||||||
const [past, setPast] = useState<HistoryItem[][]>(flows.map(() => []));
|
const [past, setPast] = useState<HistoryItem[][]>(flows.map(() => []));
|
||||||
const [future, setFuture] = useState<HistoryItem[][]>(flows.map(() => []));
|
const [future, setFuture] = useState<HistoryItem[][]>(flows.map(() => []));
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,7 @@ import {
|
||||||
} from "../../constants/constants";
|
} from "../../constants/constants";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import { FlowsContext } from "../../contexts/flowsContext";
|
import { FlowsContext } from "../../contexts/flowsContext";
|
||||||
import { typesContext } from "../../contexts/typesContext";
|
|
||||||
import { NodeDataType } from "../../types/flow";
|
import { NodeDataType } from "../../types/flow";
|
||||||
import { FlowsState } from "../../types/tabs";
|
|
||||||
import {
|
import {
|
||||||
convertObjToArray,
|
convertObjToArray,
|
||||||
convertValuesToNumbers,
|
convertValuesToNumbers,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import { Checkbox } from "../../components/ui/checkbox";
|
||||||
import { EXPORT_DIALOG_SUBTITLE } from "../../constants/constants";
|
import { EXPORT_DIALOG_SUBTITLE } from "../../constants/constants";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import { FlowsContext } from "../../contexts/flowsContext";
|
import { FlowsContext } from "../../contexts/flowsContext";
|
||||||
import { typesContext } from "../../contexts/typesContext";
|
|
||||||
import { removeApiKeys } from "../../utils/reactflowUtils";
|
import { removeApiKeys } from "../../utils/reactflowUtils";
|
||||||
import BaseModal from "../baseModal";
|
import BaseModal from "../baseModal";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { useContext, useEffect, useRef, useState } from "react";
|
import { useContext, useEffect, useRef, useState } from "react";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import { typesContext } from "../../contexts/typesContext";
|
|
||||||
import { sendAllProps } from "../../types/api";
|
import { sendAllProps } from "../../types/api";
|
||||||
import { ChatMessageType } from "../../types/chat";
|
import { ChatMessageType } from "../../types/chat";
|
||||||
import { FlowType } from "../../types/flow";
|
import { FlowType } from "../../types/flow";
|
||||||
|
|
@ -383,10 +382,7 @@ export default function FormModal({
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
function sendMessage(): void {
|
function sendMessage(): void {
|
||||||
let nodeValidationErrors = validateNodes(
|
let nodeValidationErrors = validateNodes(nodes, edges);
|
||||||
nodes,
|
|
||||||
edges
|
|
||||||
);
|
|
||||||
if (nodeValidationErrors.length === 0) {
|
if (nodeValidationErrors.length === 0) {
|
||||||
setLockChat(true);
|
setLockChat(true);
|
||||||
let inputs = tabsState[id.current].formKeysData.input_keys;
|
let inputs = tabsState[id.current].formKeysData.input_keys;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import { Checkbox } from "../../components/ui/checkbox";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import { FlowsContext } from "../../contexts/flowsContext";
|
import { FlowsContext } from "../../contexts/flowsContext";
|
||||||
import { StoreContext } from "../../contexts/storeContext";
|
import { StoreContext } from "../../contexts/storeContext";
|
||||||
import { typesContext } from "../../contexts/typesContext";
|
|
||||||
import {
|
import {
|
||||||
getStoreComponents,
|
getStoreComponents,
|
||||||
getStoreTags,
|
getStoreTags,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import ReactFlow, {
|
||||||
SelectionDragHandler,
|
SelectionDragHandler,
|
||||||
addEdge,
|
addEdge,
|
||||||
updateEdge,
|
updateEdge,
|
||||||
useReactFlow,
|
|
||||||
} from "reactflow";
|
} from "reactflow";
|
||||||
import GenericNode from "../../../../CustomNodes/GenericNode";
|
import GenericNode from "../../../../CustomNodes/GenericNode";
|
||||||
import Chat from "../../../../components/chatComponent";
|
import Chat from "../../../../components/chatComponent";
|
||||||
|
|
@ -29,7 +28,6 @@ import { typesContext } from "../../../../contexts/typesContext";
|
||||||
import { undoRedoContext } from "../../../../contexts/undoRedoContext";
|
import { undoRedoContext } from "../../../../contexts/undoRedoContext";
|
||||||
import { APIClassType } from "../../../../types/api";
|
import { APIClassType } from "../../../../types/api";
|
||||||
import { FlowType, NodeType, targetHandleType } from "../../../../types/flow";
|
import { FlowType, NodeType, targetHandleType } from "../../../../types/flow";
|
||||||
import { FlowsState } from "../../../../types/tabs";
|
|
||||||
import {
|
import {
|
||||||
generateFlow,
|
generateFlow,
|
||||||
generateNodeFromFlow,
|
generateNodeFromFlow,
|
||||||
|
|
@ -72,7 +70,17 @@ export default function Page({
|
||||||
const reactFlowWrapper = useRef<HTMLDivElement>(null);
|
const reactFlowWrapper = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const { takeSnapshot } = useContext(undoRedoContext);
|
const { takeSnapshot } = useContext(undoRedoContext);
|
||||||
const { nodes, edges, setNodes, setEdges, onNodesChange, onEdgesChange, setPending, saveFlow, isPending } = useContext(FlowsContext);
|
const {
|
||||||
|
nodes,
|
||||||
|
edges,
|
||||||
|
setNodes,
|
||||||
|
setEdges,
|
||||||
|
onNodesChange,
|
||||||
|
onEdgesChange,
|
||||||
|
setPending,
|
||||||
|
saveFlow,
|
||||||
|
isPending,
|
||||||
|
} = useContext(FlowsContext);
|
||||||
|
|
||||||
const position = useRef({ x: 0, y: 0 });
|
const position = useRef({ x: 0, y: 0 });
|
||||||
const [lastSelection, setLastSelection] =
|
const [lastSelection, setLastSelection] =
|
||||||
|
|
@ -136,11 +144,7 @@ export default function Page({
|
||||||
document.removeEventListener("keydown", onKeyDown);
|
document.removeEventListener("keydown", onKeyDown);
|
||||||
document.removeEventListener("mousemove", handleMouseMove);
|
document.removeEventListener("mousemove", handleMouseMove);
|
||||||
};
|
};
|
||||||
}, [
|
}, [lastCopiedSelection, lastSelection, takeSnapshot]);
|
||||||
lastCopiedSelection,
|
|
||||||
lastSelection,
|
|
||||||
takeSnapshot,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const [selectionMenuVisible, setSelectionMenuVisible] = useState(false);
|
const [selectionMenuVisible, setSelectionMenuVisible] = useState(false);
|
||||||
|
|
||||||
|
|
@ -155,10 +159,12 @@ export default function Page({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
if(reactFlowInstance){
|
if (reactFlowInstance) {
|
||||||
reactFlowInstance.setNodes(flow?.data?.nodes ?? []);
|
reactFlowInstance.setNodes(flow?.data?.nodes ?? []);
|
||||||
reactFlowInstance.setEdges(flow?.data?.edges ?? []);
|
reactFlowInstance.setEdges(flow?.data?.edges ?? []);
|
||||||
reactFlowInstance.setViewport(flow?.data?.viewport ?? { zoom: 1, x: 0, y: 0 });
|
reactFlowInstance.setViewport(
|
||||||
|
flow?.data?.viewport ?? { zoom: 1, x: 0, y: 0 }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the previous timeout
|
// Clear the previous timeout
|
||||||
|
|
@ -370,8 +376,7 @@ export default function Page({
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onMove = useCallback(() => {
|
const onMove = useCallback(() => {
|
||||||
if(!isPending)
|
if (!isPending) setPending(true);
|
||||||
setPending(true);
|
|
||||||
}, [setPending]);
|
}, [setPending]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -479,9 +484,7 @@ export default function Page({
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ReactFlow>
|
</ReactFlow>
|
||||||
{!view && (
|
{!view && <Chat flow={flow} />}
|
||||||
<Chat flow={flow} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { useReactFlow } from "reactflow";
|
|
||||||
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
||||||
import IconComponent from "../../../../components/genericIconComponent";
|
import IconComponent from "../../../../components/genericIconComponent";
|
||||||
import {
|
import {
|
||||||
|
|
@ -64,7 +63,16 @@ export default function NodeToolbarComponent({
|
||||||
const isMinimal = canMinimize();
|
const isMinimal = canMinimize();
|
||||||
const isGroup = data.node?.flow ? true : false;
|
const isGroup = data.node?.flow ? true : false;
|
||||||
|
|
||||||
const { paste, saveComponent, version, flows, nodes, edges, setNodes, setEdges } = useContext(FlowsContext);
|
const {
|
||||||
|
paste,
|
||||||
|
saveComponent,
|
||||||
|
version,
|
||||||
|
flows,
|
||||||
|
nodes,
|
||||||
|
edges,
|
||||||
|
setNodes,
|
||||||
|
setEdges,
|
||||||
|
} = useContext(FlowsContext);
|
||||||
const { takeSnapshot } = useContext(undoRedoContext);
|
const { takeSnapshot } = useContext(undoRedoContext);
|
||||||
const [showModalAdvanced, setShowModalAdvanced] = useState(false);
|
const [showModalAdvanced, setShowModalAdvanced] = useState(false);
|
||||||
const [showconfirmShare, setShowconfirmShare] = useState(false);
|
const [showconfirmShare, setShowconfirmShare] = useState(false);
|
||||||
|
|
@ -155,8 +163,10 @@ export default function NodeToolbarComponent({
|
||||||
{
|
{
|
||||||
x: 50,
|
x: 50,
|
||||||
y: 10,
|
y: 10,
|
||||||
paneX: nodes.find((node) => node.id === data.id)?.position.x,
|
paneX: nodes.find((node) => node.id === data.id)?.position
|
||||||
paneY: nodes.find((node) => node.id === data.id)?.position.y,
|
.x,
|
||||||
|
paneY: nodes.find((node) => node.id === data.id)?.position
|
||||||
|
.y,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,17 @@ type RFState = {
|
||||||
onNodesChange: OnNodesChange;
|
onNodesChange: OnNodesChange;
|
||||||
onEdgesChange: OnEdgesChange;
|
onEdgesChange: OnEdgesChange;
|
||||||
onConnect: OnConnect;
|
onConnect: OnConnect;
|
||||||
setEdges: (edges: Edge[]) => void;
|
|
||||||
setNodes: (nodes: Node[]) => void;
|
|
||||||
deleteNode: (nodeId: string) => void;
|
deleteNode: (nodeId: string) => void;
|
||||||
deleteEdge: (edgeId: string) => void;
|
deleteEdge: (edgeId: string) => void;
|
||||||
|
isBuilt: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
||||||
const useStore = create<RFState>((set, get) => ({
|
const useStore = create<RFState>((set, get) => ({
|
||||||
nodes: [],
|
nodes: [],
|
||||||
edges: [],
|
edges: [],
|
||||||
|
isBuilt: false,
|
||||||
|
copiedSelection: { nodes: [], edges: [] },
|
||||||
onNodesChange: (changes: NodeChange[]) => {
|
onNodesChange: (changes: NodeChange[]) => {
|
||||||
set({
|
set({
|
||||||
nodes: applyNodeChanges(changes, get().nodes),
|
nodes: applyNodeChanges(changes, get().nodes),
|
||||||
|
|
@ -44,8 +45,6 @@ const useStore = create<RFState>((set, get) => ({
|
||||||
edges: addEdge(connection, get().edges),
|
edges: addEdge(connection, get().edges),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setEdges: (edges) => set({ edges }),
|
|
||||||
setNodes: (nodes) => set({ nodes }),
|
|
||||||
deleteNode: (nodeId) => {
|
deleteNode: (nodeId) => {
|
||||||
set({
|
set({
|
||||||
nodes: get().nodes.filter((node) => node.id !== nodeId),
|
nodes: get().nodes.filter((node) => node.id !== nodeId),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { FlowType } from "../flow";
|
import { FlowType } from "../flow";
|
||||||
|
|
||||||
export type ChatType = { flow: FlowType; };
|
export type ChatType = { flow: FlowType };
|
||||||
export type ChatMessageType = {
|
export type ChatMessageType = {
|
||||||
message: string | Object;
|
message: string | Object;
|
||||||
template?: string;
|
template?: string;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { XYPosition, Node, NodeChange, Edge, EdgeChange } from "reactflow";
|
import { Edge, EdgeChange, Node, NodeChange, XYPosition } from "reactflow";
|
||||||
import { tweakType } from "../components";
|
import { tweakType } from "../components";
|
||||||
import { FlowType, NodeDataType } from "../flow";
|
import { FlowType, NodeDataType } from "../flow";
|
||||||
import { Dispatch, SetStateAction } from "react";
|
|
||||||
|
|
||||||
type OnChange<ChangesType> = (changes: ChangesType[]) => void;
|
type OnChange<ChangesType> = (changes: ChangesType[]) => void;
|
||||||
|
|
||||||
|
|
@ -46,7 +45,9 @@ export type FlowsContextType = {
|
||||||
isPending: boolean;
|
isPending: boolean;
|
||||||
setPending: (pending: boolean) => void;
|
setPending: (pending: boolean) => void;
|
||||||
tabsState: FlowsState;
|
tabsState: FlowsState;
|
||||||
setTabsState: (update: FlowsState | ((oldState: FlowsState) => FlowsState)) => void;
|
setTabsState: (
|
||||||
|
update: FlowsState | ((oldState: FlowsState) => FlowsState)
|
||||||
|
) => void;
|
||||||
paste: (
|
paste: (
|
||||||
selection: { nodes: any; edges: any },
|
selection: { nodes: any; edges: any },
|
||||||
position: { x: number; y: number; paneX?: number; paneY?: number }
|
position: { x: number; y: number; paneX?: number; paneY?: number }
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ export function unselectAllNodes({ updateNodes, data }: unselectAllNodesType) {
|
||||||
export function isValidConnection(
|
export function isValidConnection(
|
||||||
{ source, target, sourceHandle, targetHandle }: Connection,
|
{ source, target, sourceHandle, targetHandle }: Connection,
|
||||||
nodes: Node[],
|
nodes: Node[],
|
||||||
edges: Edge[],
|
edges: Edge[]
|
||||||
) {
|
) {
|
||||||
const targetHandleObject: targetHandleType = scapeJSONParse(targetHandle!);
|
const targetHandleObject: targetHandleType = scapeJSONParse(targetHandle!);
|
||||||
const sourceHandleObject: sourceHandleType = scapeJSONParse(sourceHandle!);
|
const sourceHandleObject: sourceHandleType = scapeJSONParse(sourceHandle!);
|
||||||
|
|
@ -98,16 +98,12 @@ export function isValidConnection(
|
||||||
) {
|
) {
|
||||||
let targetNode = nodes.find((node) => node.id === target!)?.data?.node;
|
let targetNode = nodes.find((node) => node.id === target!)?.data?.node;
|
||||||
if (!targetNode) {
|
if (!targetNode) {
|
||||||
if (
|
if (!edges.find((e) => e.targetHandle === targetHandle)) {
|
||||||
!edges
|
|
||||||
.find((e) => e.targetHandle === targetHandle)
|
|
||||||
) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
(!targetNode.template[targetHandleObject.fieldName].list &&
|
(!targetNode.template[targetHandleObject.fieldName].list &&
|
||||||
!edges
|
!edges.find((e) => e.targetHandle === targetHandle)) ||
|
||||||
.find((e) => e.targetHandle === targetHandle)) ||
|
|
||||||
targetNode.template[targetHandleObject.fieldName].list
|
targetNode.template[targetHandleObject.fieldName].list
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -505,7 +501,7 @@ export function generateFlow(
|
||||||
edges: Edge[],
|
edges: Edge[],
|
||||||
name: string
|
name: string
|
||||||
): generateFlowType {
|
): generateFlowType {
|
||||||
const newFlowData = {nodes, edges, viewport: { zoom: 1, x: 0, y: 0 }};
|
const newFlowData = { nodes, edges, viewport: { zoom: 1, x: 0, y: 0 } };
|
||||||
const uid = new ShortUniqueId({ length: 5 });
|
const uid = new ShortUniqueId({ length: 5 });
|
||||||
/* remove edges that are not connected to selected nodes on both ends
|
/* remove edges that are not connected to selected nodes on both ends
|
||||||
in future we can save this edges to when ungrouping reconect to the old nodes
|
in future we can save this edges to when ungrouping reconect to the old nodes
|
||||||
|
|
@ -539,14 +535,10 @@ export function generateFlow(
|
||||||
export function filterFlow(
|
export function filterFlow(
|
||||||
selection: OnSelectionChangeParams,
|
selection: OnSelectionChangeParams,
|
||||||
setNodes: (update: Node[] | ((oldState: Node[]) => Node[])) => void,
|
setNodes: (update: Node[] | ((oldState: Node[]) => Node[])) => void,
|
||||||
setEdges: (update: Edge[] | ((oldState: Edge[]) => Edge[])) => void,
|
setEdges: (update: Edge[] | ((oldState: Edge[]) => Edge[])) => void
|
||||||
) {
|
) {
|
||||||
setNodes((nodes) =>
|
setNodes((nodes) => nodes.filter((node) => !selection.nodes.includes(node)));
|
||||||
nodes.filter((node) => !selection.nodes.includes(node))
|
setEdges((edges) => edges.filter((edge) => !selection.edges.includes(edge)));
|
||||||
);
|
|
||||||
setEdges((edges) =>
|
|
||||||
edges.filter((edge) => !selection.edges.includes(edge))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findLastNode({ nodes, edges }: findLastNodeType) {
|
export function findLastNode({ nodes, edges }: findLastNodeType) {
|
||||||
|
|
@ -572,7 +564,7 @@ export function updateFlowPosition(NewPosition: XYPosition, flow: FlowType) {
|
||||||
export function concatFlows(
|
export function concatFlows(
|
||||||
flow: FlowType,
|
flow: FlowType,
|
||||||
setNodes: (update: Node[] | ((oldState: Node[]) => Node[])) => void,
|
setNodes: (update: Node[] | ((oldState: Node[]) => Node[])) => void,
|
||||||
setEdges: (update: Edge[] | ((oldState: Edge[]) => Edge[])) => void,
|
setEdges: (update: Edge[] | ((oldState: Edge[]) => Edge[])) => void
|
||||||
) {
|
) {
|
||||||
const { nodes, edges } = flow.data!;
|
const { nodes, edges } = flow.data!;
|
||||||
setNodes((old) => [...old, ...nodes]);
|
setNodes((old) => [...old, ...nodes]);
|
||||||
|
|
|
||||||
|
|
@ -578,4 +578,4 @@ def test_async_task_processing_vector_store(client, added_vector_store, created_
|
||||||
# Validate that the task completed successfully and the result is as expected
|
# Validate that the task completed successfully and the result is as expected
|
||||||
assert "result" in task_status_json, task_status_json
|
assert "result" in task_status_json, task_status_json
|
||||||
assert "output" in task_status_json["result"], task_status_json["result"]
|
assert "output" in task_status_json["result"], task_status_json["result"]
|
||||||
assert "Langflow" in task_status_json["result"]["output"], task_status_json["result"]
|
assert "Langflow" in task_status_json["result"]["output"], task_status_json["result"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue