From b9b8937eda87123ac32891bb8d65ae45d0b0c0fe Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 30 Nov 2023 17:34:40 -0300 Subject: [PATCH] formatting --- src/backend/langflow/api/utils.py | 1 - src/backend/langflow/api/v1/validate.py | 10 ++++-- .../langflow/interface/custom/code_parser.py | 3 +- .../langflow/template/frontend_node/base.py | 3 +- src/backend/langflow/utils/validate.py | 31 ++++++++++++++----- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/backend/langflow/api/utils.py b/src/backend/langflow/api/utils.py index ee2dfd401..832cf6b89 100644 --- a/src/backend/langflow/api/utils.py +++ b/src/backend/langflow/api/utils.py @@ -68,7 +68,6 @@ def update_frontend_node_with_template_values(frontend_node, raw_template_data): if key == "code" or not isinstance(value_dict, dict) or not frontend_field: continue - value = value_dict.get("value") template_field_type = value_dict.get("type") frontend_node_field_type = frontend_field.get("type") diff --git a/src/backend/langflow/api/v1/validate.py b/src/backend/langflow/api/v1/validate.py index e17a95fb8..51d0f0d76 100644 --- a/src/backend/langflow/api/v1/validate.py +++ b/src/backend/langflow/api/v1/validate.py @@ -1,7 +1,11 @@ from fastapi import APIRouter, HTTPException -from langflow.api.v1.base import (Code, CodeValidationResponse, - PromptValidationResponse, - ValidatePromptRequest, validate_prompt) +from langflow.api.v1.base import ( + Code, + CodeValidationResponse, + PromptValidationResponse, + ValidatePromptRequest, + validate_prompt, +) from langflow.template.field.base import TemplateField from langflow.utils.validate import validate_code from loguru import logger diff --git a/src/backend/langflow/interface/custom/code_parser.py b/src/backend/langflow/interface/custom/code_parser.py index dbb56773e..cb42b8142 100644 --- a/src/backend/langflow/interface/custom/code_parser.py +++ b/src/backend/langflow/interface/custom/code_parser.py @@ -6,8 +6,7 @@ from typing import Any, Dict, List, Type, Union from cachetools import TTLCache, cachedmethod, keys from fastapi import HTTPException -from langflow.interface.custom.schema import (CallableCodeDetails, - ClassCodeDetails) +from langflow.interface.custom.schema import CallableCodeDetails, ClassCodeDetails class CodeSyntaxError(HTTPException): diff --git a/src/backend/langflow/template/frontend_node/base.py b/src/backend/langflow/template/frontend_node/base.py index 361d644dc..04467a094 100644 --- a/src/backend/langflow/template/frontend_node/base.py +++ b/src/backend/langflow/template/frontend_node/base.py @@ -3,8 +3,7 @@ from collections import defaultdict from typing import ClassVar, Dict, List, Optional from langflow.template.field.base import TemplateField -from langflow.template.frontend_node.constants import (CLASSES_TO_REMOVE, - FORCE_SHOW_FIELDS) +from langflow.template.frontend_node.constants import CLASSES_TO_REMOVE, FORCE_SHOW_FIELDS from langflow.template.frontend_node.formatter import field_formatters from langflow.template.template.base import Template from langflow.utils import constants diff --git a/src/backend/langflow/utils/validate.py b/src/backend/langflow/utils/validate.py index 3944391e5..d18e64c7f 100644 --- a/src/backend/langflow/utils/validate.py +++ b/src/backend/langflow/utils/validate.py @@ -161,7 +161,7 @@ def create_class(code, class_name): class_code = extract_class_code(module, class_name) compiled_class = compile_class_code(class_code) - return build_class_constructor( compiled_class, exec_globals, class_name) + return build_class_constructor(compiled_class, exec_globals, class_name) def create_type_ignore_class(): @@ -228,7 +228,7 @@ def compile_class_code(class_code): return code_obj -def build_class_constructor( compiled_class, exec_globals, class_name): +def build_class_constructor(compiled_class, exec_globals, class_name): """ Builds a constructor function for the dynamically created class. @@ -267,11 +267,27 @@ def get_default_imports(code_string): } langflow_imports = [ - "AgentExecutor", "BaseChatMemory", "BaseLanguageModel", "BaseLLM", - "BaseLoader", "BaseMemory", "BaseOutputParser", "BasePromptTemplate", - "BaseRetriever", "Callable", "Chain", "ChatPromptTemplate", "Data", - "Document", "Embeddings", "NestedDict", "Object", "PromptTemplate", - "TextSplitter", "Tool", "VectorStore" + "AgentExecutor", + "BaseChatMemory", + "BaseLanguageModel", + "BaseLLM", + "BaseLoader", + "BaseMemory", + "BaseOutputParser", + "BasePromptTemplate", + "BaseRetriever", + "Callable", + "Chain", + "ChatPromptTemplate", + "Data", + "Document", + "Embeddings", + "NestedDict", + "Object", + "PromptTemplate", + "TextSplitter", + "Tool", + "VectorStore", ] necessary_imports = find_names_in_code(code_string, langflow_imports + ["Optional", "List", "Dict", "Union"]) langflow_module = importlib.import_module("langflow.field_typing") @@ -279,6 +295,7 @@ def get_default_imports(code_string): return default_imports + def find_names_in_code(code, names): """ Finds if any of the specified names are present in the given code string.