From 6737c845ebecb0558e3f74193fdb94e1ea852ef5 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 27 Mar 2024 23:46:11 -0300 Subject: [PATCH] Refactor code and fix formatting issues --- .../database/models/variable/model.py | 14 ++-- .../components/codeTabsComponent/index.tsx | 5 +- .../src/components/inputComponent/index.tsx | 3 +- .../components/inputGlobalComponent/index.tsx | 2 +- src/frontend/src/icons/AstraDB/AstraDB.jsx | 38 +++++++---- .../components/nodeToolbarComponent/index.tsx | 14 ++-- src/frontend/src/types/components/index.ts | 17 +++-- .../tests/end-to-end/assets/collection.json | 67 +++++-------------- .../end-to-end/assets/flow_group_test.json | 46 +++---------- .../tests/end-to-end/assets/flowtest.json | 30 +++------ src/frontend/tests/end-to-end/group.spec.ts | 30 +++++---- 11 files changed, 101 insertions(+), 165 deletions(-) diff --git a/src/backend/base/langflow/services/database/models/variable/model.py b/src/backend/base/langflow/services/database/models/variable/model.py index 5ad2af23b..1c314d756 100644 --- a/src/backend/base/langflow/services/database/models/variable/model.py +++ b/src/backend/base/langflow/services/database/models/variable/model.py @@ -1,4 +1,4 @@ -from datetime import datetime,timezone +from datetime import datetime, timezone from typing import TYPE_CHECKING, Optional from uuid import UUID, uuid4 @@ -26,16 +26,10 @@ class Variable(VariableBase, table=True): description="Unique ID for the variable", ) # name is unique per user - created_at: datetime = Field( - default_factory=utc_now, description="Creation time of the variable" - ) - updated_at: Optional[datetime] = Field( - None, description="Last update time of the variable" - ) + created_at: datetime = Field(default_factory=utc_now, description="Creation time of the variable") + updated_at: Optional[datetime] = Field(None, description="Last update time of the variable") # foreign key to user table - user_id: UUID = Field( - description="User ID associated with this variable", foreign_key="user.id" - ) + user_id: UUID = Field(description="User ID associated with this variable", foreign_key="user.id") user: "User" = Relationship(back_populates="variables") diff --git a/src/frontend/src/components/codeTabsComponent/index.tsx b/src/frontend/src/components/codeTabsComponent/index.tsx index 5f981a938..53e3b9e82 100644 --- a/src/frontend/src/components/codeTabsComponent/index.tsx +++ b/src/frontend/src/components/codeTabsComponent/index.tsx @@ -246,10 +246,7 @@ export default function CodeTabsComponent({ ) .map((templateField, indx) => { return ( - + {templateField} diff --git a/src/frontend/src/components/inputComponent/index.tsx b/src/frontend/src/components/inputComponent/index.tsx index 2b8c9c0e3..7746f0e32 100644 --- a/src/frontend/src/components/inputComponent/index.tsx +++ b/src/frontend/src/components/inputComponent/index.tsx @@ -127,7 +127,8 @@ export default function InputComponent({ if (password) { // check if all chars are • if ( - e.target.value.split("").every((char) => char === "•") && e.target.value !== "" + e.target.value.split("").every((char) => char === "•") && + e.target.value !== "" ) { setErrorData({ title: `Invalid characters: ${e.target.value}`, diff --git a/src/frontend/src/components/inputGlobalComponent/index.tsx b/src/frontend/src/components/inputGlobalComponent/index.tsx index 94df382ba..19f12e9d4 100644 --- a/src/frontend/src/components/inputGlobalComponent/index.tsx +++ b/src/frontend/src/components/inputGlobalComponent/index.tsx @@ -4,12 +4,12 @@ import DeleteConfirmationModal from "../../modals/DeleteConfirmationModal"; import useAlertStore from "../../stores/alertStore"; import { useGlobalVariablesStore } from "../../stores/globalVariables"; import { ResponseErrorDetailAPI } from "../../types/api"; +import { InputGlobalComponentType } from "../../types/components"; import { cn } from "../../utils/utils"; import AddNewVariableButton from "../addNewVariableButtonComponent/addNewVariableButton"; import ForwardedIconComponent from "../genericIconComponent"; import InputComponent from "../inputComponent"; import { CommandItem } from "../ui/command"; -import { InputGlobalComponentType } from "../../types/components"; export default function InputGlobalComponent({ disabled, diff --git a/src/frontend/src/icons/AstraDB/AstraDB.jsx b/src/frontend/src/icons/AstraDB/AstraDB.jsx index 4f20ce65b..c54bee90a 100644 --- a/src/frontend/src/icons/AstraDB/AstraDB.jsx +++ b/src/frontend/src/icons/AstraDB/AstraDB.jsx @@ -1,16 +1,28 @@ const AstraSVG = (props) => ( - - -{/* */} - - - - - - - - - - + + + {/* */} + + + + + + + + + ); export default AstraSVG; diff --git a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx index ae3b0b561..17b4b2225 100644 --- a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx @@ -617,12 +617,14 @@ export default function NodeToolbarComponent({ open={showModalAdvanced} setOpen={setShowModalAdvanced} /> - {showconfirmShare&&} + {showconfirmShare && ( + + )} {hasCode && (
void, - setDb: (value: boolean) => void, - name: string, - data: NodeDataType, - editNode?: boolean, - }; +export type InputGlobalComponentType = { + disabled: boolean; + onChange: (value: string) => void; + setDb: (value: boolean) => void; + name: string; + data: NodeDataType; + editNode?: boolean; +}; export type KeyPairListComponentType = { value: any; diff --git a/src/frontend/tests/end-to-end/assets/collection.json b/src/frontend/tests/end-to-end/assets/collection.json index 7b58fdadf..269afc8c9 100644 --- a/src/frontend/tests/end-to-end/assets/collection.json +++ b/src/frontend/tests/end-to-end/assets/collection.json @@ -305,10 +305,7 @@ "_type": "initialize_agent" }, "description": "Construct a zero shot agent from an LLM and tools.", - "base_classes": [ - "AgentExecutor", - "function" - ], + "base_classes": ["AgentExecutor", "function"], "display_name": "AgentInitializer" }, "id": "AgentInitializer-QiQ4x", @@ -372,9 +369,7 @@ "_type": "PythonFunctionTool" }, "description": "Python function to be executed.", - "base_classes": [ - "Tool" - ], + "base_classes": ["Tool"], "display_name": "PythonFunctionTool" }, "id": "PythonFunctionTool-kX99N", @@ -434,9 +429,7 @@ "selected": false, "data": { "sourceHandle": { - "baseClasses": [ - "Tool" - ], + "baseClasses": ["Tool"], "dataType": "PythonFunctionTool", "id": "PythonFunctionTool-kX99N" }, @@ -822,10 +815,7 @@ "_type": "initialize_agent" }, "description": "Construct a zero shot agent from an LLM and tools.", - "base_classes": [ - "AgentExecutor", - "function" - ], + "base_classes": ["AgentExecutor", "function"], "display_name": "AgentInitializer" }, "id": "AgentInitializer-YJgqs", @@ -889,9 +879,7 @@ "_type": "PythonFunctionTool" }, "description": "Python function to be executed.", - "base_classes": [ - "Tool" - ], + "base_classes": ["Tool"], "display_name": "PythonFunctionTool" }, "id": "PythonFunctionTool-gqQDg", @@ -951,9 +939,7 @@ "selected": false, "data": { "sourceHandle": { - "baseClasses": [ - "Tool" - ], + "baseClasses": ["Tool"], "dataType": "PythonFunctionTool", "id": "PythonFunctionTool-gqQDg" }, @@ -1339,10 +1325,7 @@ "_type": "initialize_agent" }, "description": "Construct a zero shot agent from an LLM and tools.", - "base_classes": [ - "AgentExecutor", - "function" - ], + "base_classes": ["AgentExecutor", "function"], "display_name": "AgentInitializer" }, "id": "AgentInitializer-grV0u", @@ -1406,9 +1389,7 @@ "_type": "PythonFunctionTool" }, "description": "Python function to be executed.", - "base_classes": [ - "Tool" - ], + "base_classes": ["Tool"], "display_name": "PythonFunctionTool" }, "id": "PythonFunctionTool-SctM2", @@ -1468,9 +1449,7 @@ "selected": false, "data": { "sourceHandle": { - "baseClasses": [ - "Tool" - ], + "baseClasses": ["Tool"], "dataType": "PythonFunctionTool", "id": "PythonFunctionTool-SctM2" }, @@ -2210,10 +2189,7 @@ "_type": "initialize_agent" }, "description": "Construct a zero shot agent from an LLM and tools.", - "base_classes": [ - "AgentExecutor", - "function" - ], + "base_classes": ["AgentExecutor", "function"], "display_name": "AgentInitializer" }, "id": "AgentInitializer-EE8R4", @@ -2277,9 +2253,7 @@ "_type": "PythonFunctionTool" }, "description": "Python function to be executed.", - "base_classes": [ - "Tool" - ], + "base_classes": ["Tool"], "display_name": "PythonFunctionTool" }, "id": "PythonFunctionTool-YKkDL", @@ -2339,9 +2313,7 @@ "selected": false, "data": { "sourceHandle": { - "baseClasses": [ - "Tool" - ], + "baseClasses": ["Tool"], "dataType": "PythonFunctionTool", "id": "PythonFunctionTool-YKkDL" }, @@ -2727,10 +2699,7 @@ "_type": "initialize_agent" }, "description": "Construct a zero shot agent from an LLM and tools.", - "base_classes": [ - "AgentExecutor", - "function" - ], + "base_classes": ["AgentExecutor", "function"], "display_name": "AgentInitializer" }, "id": "AgentInitializer-goPm2", @@ -2794,9 +2763,7 @@ "_type": "PythonFunctionTool" }, "description": "Python function to be executed.", - "base_classes": [ - "Tool" - ], + "base_classes": ["Tool"], "display_name": "PythonFunctionTool" }, "id": "PythonFunctionTool-SQikY", @@ -2856,9 +2823,7 @@ "selected": false, "data": { "sourceHandle": { - "baseClasses": [ - "Tool" - ], + "baseClasses": ["Tool"], "dataType": "PythonFunctionTool", "id": "PythonFunctionTool-SQikY" }, @@ -2881,4 +2846,4 @@ "user_id": "6f6ebc2c-9e7a-4c35-84fc-51760db10d9b" } ] -} \ No newline at end of file +} diff --git a/src/frontend/tests/end-to-end/assets/flow_group_test.json b/src/frontend/tests/end-to-end/assets/flow_group_test.json index efd5478b3..c88576305 100644 --- a/src/frontend/tests/end-to-end/assets/flow_group_test.json +++ b/src/frontend/tests/end-to-end/assets/flow_group_test.json @@ -46,9 +46,7 @@ "dynamic": false, "info": "", "title_case": false, - "input_types": [ - "Text" - ] + "input_types": ["Text"] }, "name": { "type": "str", @@ -66,9 +64,7 @@ "dynamic": false, "info": "", "title_case": false, - "input_types": [ - "Text" - ] + "input_types": ["Text"] }, "return_direct": { "type": "bool", @@ -90,10 +86,7 @@ "_type": "PythonFunctionTool" }, "description": "Python function to be executed.", - "base_classes": [ - "BaseTool", - "Tool" - ], + "base_classes": ["BaseTool", "Tool"], "display_name": "PythonFunctionTool", "documentation": "", "custom_fields": {}, @@ -208,9 +201,7 @@ "dynamic": false, "info": "", "title_case": false, - "input_types": [ - "Text" - ] + "input_types": ["Text"] }, "code": { "type": "code", @@ -269,10 +260,7 @@ "max_iterations": null, "memory": null }, - "output_types": [ - "AgentExecutor", - "Callable" - ], + "output_types": ["AgentExecutor", "Callable"], "field_formatters": {}, "pinned": false, "beta": true @@ -372,9 +360,7 @@ "dynamic": false, "info": "", "title_case": false, - "input_types": [ - "Text" - ] + "input_types": ["Text"] }, "openai_api_base": { "type": "str", @@ -392,9 +378,7 @@ "dynamic": false, "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1.\n\nYou can change this to use other APIs like JinaChat, LocalAI and Prem.", "title_case": false, - "input_types": [ - "Text" - ] + "input_types": ["Text"] }, "openai_api_key": { "type": "str", @@ -412,9 +396,7 @@ "dynamic": false, "info": "", "title_case": false, - "input_types": [ - "Text" - ] + "input_types": ["Text"] }, "temperature": { "type": "float", @@ -462,10 +444,7 @@ "openai_api_key": null, "temperature": null }, - "output_types": [ - "BaseLanguageModel", - "BaseLLM" - ], + "output_types": ["BaseLanguageModel", "BaseLLM"], "field_formatters": {}, "pinned": false, "beta": true @@ -528,10 +507,7 @@ "type": "Tool" }, "sourceHandle": { - "baseClasses": [ - "BaseTool", - "Tool" - ], + "baseClasses": ["BaseTool", "Tool"], "dataType": "PythonFunctionTool", "id": "PythonFunctionTool-RfJui" } @@ -553,4 +529,4 @@ "name": "Untitled document (20)", "last_tested_version": "0.7.0a0", "is_component": false -} \ No newline at end of file +} diff --git a/src/frontend/tests/end-to-end/assets/flowtest.json b/src/frontend/tests/end-to-end/assets/flowtest.json index 6ef790455..c4de3d778 100644 --- a/src/frontend/tests/end-to-end/assets/flowtest.json +++ b/src/frontend/tests/end-to-end/assets/flowtest.json @@ -62,27 +62,21 @@ "name": "text_input", "display_name": "Text Input", "advanced": false, - "input_types": [ - "str" - ], + "input_types": ["str"], "dynamic": false, "info": "", "value": "" }, "_type": "CustomComponent" }, - "base_classes": [ - "str" - ], + "base_classes": ["str"], "display_name": "text checkpoint", "documentation": "http://docs.langflow.org/components/custom", "custom_fields": { "save_path": null, "text_input": null }, - "output_types": [ - "str" - ], + "output_types": ["str"], "field_formatters": {}, "beta": true }, @@ -161,18 +155,14 @@ "_type": "CustomComponent" }, "description": "Converts audio to text using OpenAI's Whisper.", - "base_classes": [ - "str" - ], + "base_classes": ["str"], "display_name": "Whisper Transcriber", "documentation": "", "custom_fields": { "OpenAIKey": null, "audio": null }, - "output_types": [ - "str" - ], + "output_types": ["str"], "field_formatters": {}, "beta": true }, @@ -196,15 +186,11 @@ "targetHandle": { "fieldName": "text_input", "id": "CustomComponent-MtJjl", - "inputTypes": [ - "str" - ], + "inputTypes": ["str"], "type": "str" }, "sourceHandle": { - "baseClasses": [ - "str" - ], + "baseClasses": ["str"], "dataType": "CustomComponent", "id": "CustomComponent-7NQoq" } @@ -228,4 +214,4 @@ "folder": null, "id": "1b0814b7-2964-4e09-9b4b-f7413c4fb50b", "user_id": "8b5cf798-f1b8-4108-88fd-d7274d08d471" -} \ No newline at end of file +} diff --git a/src/frontend/tests/end-to-end/group.spec.ts b/src/frontend/tests/end-to-end/group.spec.ts index 4e6b9c081..633997915 100644 --- a/src/frontend/tests/end-to-end/group.spec.ts +++ b/src/frontend/tests/end-to-end/group.spec.ts @@ -6,20 +6,24 @@ test.describe("group node test", () => { await page.goto("/"); await page.locator('//*[@id="new-project-btn"]').click(); - await page.getByRole('heading', { name: 'Data Ingestion' }).click(); + await page.getByRole("heading", { name: "Data Ingestion" }).click(); await page.waitForTimeout(2000); - await page.getByLabel('fit view').click(); - await page.keyboard.down('Control'); - await page.getByTestId("title-OpenAIEmbeddings").click({modifiers: ['Control']}); - await page.getByTestId("title-URL").click({modifiers: ['Control']}); - await page.getByTestId("title-Recursive Character Text Splitter").click({modifiers: ['Control']}); - await page.keyboard.up('Control'); - await page.getByRole('button', { name: 'Group' }).click(); + await page.getByLabel("fit view").click(); + await page.keyboard.down("Control"); + await page + .getByTestId("title-OpenAIEmbeddings") + .click({ modifiers: ["Control"] }); + await page.getByTestId("title-URL").click({ modifiers: ["Control"] }); + await page + .getByTestId("title-Recursive Character Text Splitter") + .click({ modifiers: ["Control"] }); + await page.keyboard.up("Control"); + await page.getByRole("button", { name: "Group" }).click(); await page.getByTestId(/input-collection_name_Chroma-.*/).click(); - await page.getByTestId(/input-collection_name_Chroma-.*/).fill('test'); + await page.getByTestId(/input-collection_name_Chroma-.*/).fill("test"); await page.getByTestId("title-Group").click(); - await page.keyboard.press("Control+g") - const value = await page.getByTestId('input-collection_name').inputValue() - expect(value).toBe('test'); - }) + await page.keyboard.press("Control+g"); + const value = await page.getByTestId("input-collection_name").inputValue(); + expect(value).toBe("test"); + }); });