diff --git a/src/backend/langflow/graph/graph/utils.py b/src/backend/langflow/graph/graph/utils.py index 71b81fea1..a3299739e 100644 --- a/src/backend/langflow/graph/graph/utils.py +++ b/src/backend/langflow/graph/graph/utils.py @@ -28,23 +28,14 @@ def ungroup_node(group_node_data, base_flow): g_edges = flow["data"]["edges"] # Redirect edges to the correct proxy node - updated_edges = get_updated_edges( - base_flow, g_nodes, g_edges, group_node_data["id"] - ) + updated_edges = get_updated_edges(base_flow, g_nodes, g_edges, group_node_data["id"]) # Update template values update_template(template, g_nodes) - nodes = [ - n for n in base_flow["nodes"] if n["id"] != group_node_data["id"] - ] + g_nodes + nodes = [n for n in base_flow["nodes"] if n["id"] != group_node_data["id"]] + g_nodes edges = ( - [ - e - for e in base_flow["edges"] - if e["target"] != group_node_data["id"] - and e["source"] != group_node_data["id"] - ] + [e for e in base_flow["edges"] if e["target"] != group_node_data["id"] and e["source"] != group_node_data["id"]] + g_edges + updated_edges ) @@ -66,11 +57,7 @@ def process_flow(flow_object): if node_id in processed_nodes: return - if ( - node.get("data") - and node["data"].get("node") - and node["data"]["node"].get("flow") - ): + if node.get("data") and node["data"].get("node") and node["data"]["node"].get("flow"): process_flow(node["data"]["node"]["flow"]["data"]) new_nodes = ungroup_node(node["data"], cloned_flow) # Add new nodes to the queue for future processing @@ -108,26 +95,16 @@ def update_template(template, g_nodes): if node_index != -1: display_name = None show = g_nodes[node_index]["data"]["node"]["template"][field]["show"] - advanced = g_nodes[node_index]["data"]["node"]["template"][field][ - "advanced" - ] + advanced = g_nodes[node_index]["data"]["node"]["template"][field]["advanced"] if "display_name" in g_nodes[node_index]["data"]["node"]["template"][field]: - display_name = g_nodes[node_index]["data"]["node"]["template"][field][ - "display_name" - ] + display_name = g_nodes[node_index]["data"]["node"]["template"][field]["display_name"] else: - display_name = g_nodes[node_index]["data"]["node"]["template"][field][ - "name" - ] + display_name = g_nodes[node_index]["data"]["node"]["template"][field]["name"] g_nodes[node_index]["data"]["node"]["template"][field] = value g_nodes[node_index]["data"]["node"]["template"][field]["show"] = show - g_nodes[node_index]["data"]["node"]["template"][field][ - "advanced" - ] = advanced - g_nodes[node_index]["data"]["node"]["template"][field][ - "display_name" - ] = display_name + g_nodes[node_index]["data"]["node"]["template"][field]["advanced"] = advanced + g_nodes[node_index]["data"]["node"]["template"][field]["display_name"] = display_name def update_target_handle(new_edge, g_nodes, group_node_id): diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index cfcf6cd58..024017b2e 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -80,6 +80,14 @@ class Vertex: # If the Vertex.type is a power component # then we need to return the built object # instead of the result dict + if self.is_power_component and not isinstance(self._built_object, UnbuiltObject): + result = self._built_object + # if it is not a dict or a string and hasattr model_dump then + # return the model_dump + if not isinstance(result, (dict, str)) and hasattr(result, "content"): + return result.content + return result + if isinstance(self._built_result, UnbuiltResult): return {} return self._built_result if isinstance(self._built_result, dict) else {"result": self._built_result} diff --git a/src/backend/langflow/graph/vertex/types.py b/src/backend/langflow/graph/vertex/types.py index 19422b0c8..178d460bd 100644 --- a/src/backend/langflow/graph/vertex/types.py +++ b/src/backend/langflow/graph/vertex/types.py @@ -327,7 +327,7 @@ class ChatVertex(StatelessVertex): message=str(self._built_object), sender=sender, sender_name=sender_name, - ).dict() + ).model_dump() self._built_result = self._built_object else: diff --git a/src/backend/langflow/template/frontend_node/chains.py b/src/backend/langflow/template/frontend_node/chains.py index 6bd676522..a40b29577 100644 --- a/src/backend/langflow/template/frontend_node/chains.py +++ b/src/backend/langflow/template/frontend_node/chains.py @@ -141,7 +141,9 @@ class SeriesCharacterChainNode(FrontendNode): ), ], ) - description: str = "SeriesCharacterChain is a chain you can use to have a conversation with a character from a series." # noqa + description: str = ( + "SeriesCharacterChain is a chain you can use to have a conversation with a character from a series." # noqa + ) base_classes: list[str] = [ "LLMChain", "BaseCustomChain", diff --git a/src/frontend/src/components/newChatView/index.tsx b/src/frontend/src/components/newChatView/index.tsx index a6158d96c..a40c063ee 100644 --- a/src/frontend/src/components/newChatView/index.tsx +++ b/src/frontend/src/components/newChatView/index.tsx @@ -34,7 +34,7 @@ export default function newChatView(): JSX.Element { const inputTypes = inputs.map((obj) => obj.type); const inputIds = inputs.map((obj) => obj.id); - const outputIds = outputs.map((obj) => obj.id) + const outputIds = outputs.map((obj) => obj.id); //build chat history useEffect(() => { diff --git a/src/frontend/src/types/zustand/flow/index.ts b/src/frontend/src/types/zustand/flow/index.ts index 514954fbf..937197efd 100644 --- a/src/frontend/src/types/zustand/flow/index.ts +++ b/src/frontend/src/types/zustand/flow/index.ts @@ -35,8 +35,8 @@ export type FlowPoolType = { export type FlowStoreType = { flowPool: FlowPoolType; - inputs: Array<{ type: string; id: string; }>; - outputs: Array<{ type: string; id: string; }>; + inputs: Array<{ type: string; id: string }>; + outputs: Array<{ type: string; id: string }>; hasIO: boolean; setFlowPool: (flowPool: FlowPoolType) => void; addDataToFlowPool: (data: any, nodeId: string) => void; diff --git a/tests/locust/locustfile.py b/tests/locust/locustfile.py index aca0d1de9..1fc91ee2c 100644 --- a/tests/locust/locustfile.py +++ b/tests/locust/locustfile.py @@ -66,9 +66,7 @@ class NameTest(FastHttpUser): result1, session_id = self.process(name, self.flow_id, payload1) payload2 = { - "inputs": { - "text": "What is my name? Please, answer like this: Your name is " - }, + "inputs": {"text": "What is my name? Please, answer like this: Your name is "}, "session_id": session_id, "sync": False, } @@ -88,9 +86,7 @@ class NameTest(FastHttpUser): logged_in_headers = {"Authorization": f"Bearer {a_token}"} print("Logged in") with open( - Path(__file__).parent.parent - / "data" - / "BasicChatwithPromptandHistory.json", + Path(__file__).parent.parent / "data" / "BasicChatwithPromptandHistory.json", "r", ) as f: json_flow = f.read() @@ -115,11 +111,7 @@ class NameTest(FastHttpUser): ) print(response.json()) user_id = next( - ( - user["id"] - for user in response.json()["users"] - if user["username"] == "superuser" - ), + (user["id"] for user in response.json()["users"] if user["username"] == "superuser"), None, ) # Create api key diff --git a/tests/test_api_key.py b/tests/test_api_key.py index 43b91fa43..7988793d4 100644 --- a/tests/test_api_key.py +++ b/tests/test_api_key.py @@ -6,9 +6,7 @@ from langflow.services.database.models.api_key import ApiKeyCreate def api_key(client, logged_in_headers, active_user): api_key = ApiKeyCreate(name="test-api-key") - response = client.post( - "api/v1/api_key", data=api_key.json(), headers=logged_in_headers - ) + response = client.post("api/v1/api_key", data=api_key.json(), headers=logged_in_headers) assert response.status_code == 200, response.text return response.json() @@ -28,9 +26,7 @@ def test_get_api_keys(client, logged_in_headers, api_key): def test_create_api_key(client, logged_in_headers): api_key_name = "test-api-key" - response = client.post( - "api/v1/api_key", json={"name": api_key_name}, headers=logged_in_headers - ) + response = client.post("api/v1/api_key", json={"name": api_key_name}, headers=logged_in_headers) assert response.status_code == 200 data = response.json() assert "name" in data and data["name"] == api_key_name diff --git a/tests/test_custom_types.py b/tests/test_custom_types.py index b65f58d0a..ba54b7023 100644 --- a/tests/test_custom_types.py +++ b/tests/test_custom_types.py @@ -18,9 +18,7 @@ def test_python_function_tool(): with pytest.raises(SyntaxError): code = pytest.CODE_WITH_SYNTAX_ERROR func = get_function(code) - func = PythonFunctionTool( - name="Test", description="Testing", code=code, func=func - ) + func = PythonFunctionTool(name="Test", description="Testing", code=code, func=func) def test_python_function(): diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 5016eb704..c4c9ee322 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -31,9 +31,7 @@ def test_websocket_endpoint(client: TestClient, active_user, logged_in_headers): # Assuming your websocket_endpoint uses chat_service which caches data from stream_build access_token = logged_in_headers["Authorization"].split(" ")[1] with pytest.raises(WebSocketDisconnect): - with client.websocket_connect( - f"api/v1/chat/non_existing_client_id?token={access_token}" - ) as websocket: + with client.websocket_connect(f"api/v1/chat/non_existing_client_id?token={access_token}") as websocket: websocket.send_json({"type": "test"}) data = websocket.receive_json() assert "Please, build the flow before sending messages" in data["message"]