code format
This commit is contained in:
parent
a368991d39
commit
bc7e612cfb
9 changed files with 50 additions and 56 deletions
|
|
@ -12,8 +12,7 @@ from dotenv import load_dotenv
|
|||
from langflow.main import setup_app
|
||||
from langflow.services.database.utils import session_getter
|
||||
from langflow.services.deps import get_db_service, get_settings_service
|
||||
from langflow.services.utils import (initialize_services,
|
||||
initialize_settings_service)
|
||||
from langflow.services.utils import initialize_services, initialize_settings_service
|
||||
from langflow.utils.logger import configure, logger
|
||||
from multiprocess import Process, cpu_count # type: ignore
|
||||
from rich import box
|
||||
|
|
@ -328,18 +327,22 @@ def superuser(
|
|||
|
||||
|
||||
@app.command()
|
||||
def migration(test: bool = typer.Option(True, help="Run migrations in test mode."),
|
||||
fix: bool = typer.Option(False, help="Fix migrations. This is a destructive operation, and should only be used if you know what you are doing.")
|
||||
def migration(
|
||||
test: bool = typer.Option(True, help="Run migrations in test mode."),
|
||||
fix: bool = typer.Option(
|
||||
False,
|
||||
help="Fix migrations. This is a destructive operation, and should only be used if you know what you are doing.",
|
||||
),
|
||||
):
|
||||
"""
|
||||
Run or test migrations.
|
||||
"""
|
||||
if fix:
|
||||
if not typer.confirm("This will delete all data necessary to fix migrations. Are you sure you want to continue?"):
|
||||
if not typer.confirm(
|
||||
"This will delete all data necessary to fix migrations. Are you sure you want to continue?"
|
||||
):
|
||||
raise typer.Abort()
|
||||
|
||||
|
||||
|
||||
initialize_services(fix_migration=fix)
|
||||
db_service = get_db_service()
|
||||
if not test:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
from typing import TYPE_CHECKING, List
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -83,8 +82,8 @@ def update_frontend_node_with_template_values(frontend_node, raw_template_data):
|
|||
|
||||
return frontend_node
|
||||
|
||||
def validate_is_component(flows: List["Flow"]):
|
||||
|
||||
def validate_is_component(flows: List["Flow"]):
|
||||
for flow in flows:
|
||||
if not flow.data or flow.is_component is not None:
|
||||
continue
|
||||
|
|
@ -97,7 +96,6 @@ def validate_is_component(flows: List["Flow"]):
|
|||
return flows
|
||||
|
||||
|
||||
|
||||
def get_is_component_from_data(data: dict):
|
||||
"""Returns True if the data is a component."""
|
||||
return data.get("is_component")
|
||||
return data.get("is_component")
|
||||
|
|
|
|||
|
|
@ -1,9 +1,27 @@
|
|||
from .constants import (AgentExecutor, BaseChatMemory, BaseLanguageModel,
|
||||
BaseLLM, BaseLoader, BaseMemory, BaseOutputParser,
|
||||
BasePromptTemplate, BaseRetriever, Callable, Chain,
|
||||
ChatPromptTemplate, Data, Document, Embeddings,
|
||||
NestedDict, Object, Prompt, PromptTemplate,
|
||||
TextSplitter, Tool, VectorStore)
|
||||
from .constants import (
|
||||
AgentExecutor,
|
||||
BaseChatMemory,
|
||||
BaseLanguageModel,
|
||||
BaseLLM,
|
||||
BaseLoader,
|
||||
BaseMemory,
|
||||
BaseOutputParser,
|
||||
BasePromptTemplate,
|
||||
BaseRetriever,
|
||||
Callable,
|
||||
Chain,
|
||||
ChatPromptTemplate,
|
||||
Data,
|
||||
Document,
|
||||
Embeddings,
|
||||
NestedDict,
|
||||
Object,
|
||||
Prompt,
|
||||
PromptTemplate,
|
||||
TextSplitter,
|
||||
Tool,
|
||||
VectorStore,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"NestedDict",
|
||||
|
|
@ -27,5 +45,5 @@ __all__ = [
|
|||
"Callable",
|
||||
"BasePromptTemplate",
|
||||
"ChatPromptTemplate",
|
||||
"Prompt"
|
||||
"Prompt",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ from langchain.chains.base import Chain
|
|||
from langchain.document_loaders.base import BaseLoader
|
||||
from langchain.llms.base import BaseLLM
|
||||
from langchain.memory.chat_memory import BaseChatMemory
|
||||
from langchain.prompts import (BasePromptTemplate, ChatPromptTemplate,
|
||||
PromptTemplate)
|
||||
from langchain.prompts import BasePromptTemplate, ChatPromptTemplate, PromptTemplate
|
||||
from langchain.schema import BaseOutputParser, BaseRetriever, Document
|
||||
from langchain.schema.embeddings import Embeddings
|
||||
from langchain.schema.language_model import BaseLanguageModel
|
||||
|
|
@ -26,6 +25,7 @@ class Object:
|
|||
class Data:
|
||||
pass
|
||||
|
||||
|
||||
class Prompt:
|
||||
pass
|
||||
|
||||
|
|
@ -48,7 +48,6 @@ LANGCHAIN_BASE_TYPES = {
|
|||
"BaseOutputParser": BaseOutputParser,
|
||||
"BaseMemory": BaseMemory,
|
||||
"BaseChatMemory": BaseChatMemory,
|
||||
|
||||
}
|
||||
# Langchain base types plus Python base types
|
||||
CUSTOM_COMPONENT_SUPPORTED_TYPES = {
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
@ -57,9 +56,6 @@ class CodeParser:
|
|||
ast.Assign: self.parse_global_vars,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
def __get_tree(self):
|
||||
"""
|
||||
Parses the provided code to validate its syntax.
|
||||
|
|
@ -83,7 +79,6 @@ class CodeParser:
|
|||
if handler := self.handlers.get(type(node)): # type: ignore
|
||||
handler(node) # type: ignore
|
||||
|
||||
|
||||
def parse_imports(self, node: Union[ast.Import, ast.ImportFrom]) -> None:
|
||||
"""
|
||||
Extracts "imports" from the code, including aliases.
|
||||
|
|
@ -154,17 +149,15 @@ class CodeParser:
|
|||
# Handle cases where the type is not found in the constructed environment
|
||||
pass
|
||||
|
||||
|
||||
func = CallableCodeDetails(
|
||||
name=node.name,
|
||||
doc=ast.get_docstring(node),
|
||||
args= self.parse_function_args(node),
|
||||
body= self.parse_function_body(node),
|
||||
args=self.parse_function_args(node),
|
||||
body=self.parse_function_body(node),
|
||||
return_type=return_type or get_data_type(),
|
||||
has_return=self.parse_return_statement(node),
|
||||
)
|
||||
|
||||
|
||||
return func.model_dump()
|
||||
|
||||
def parse_function_args(self, node: ast.FunctionDef) -> List[Dict[str, Any]]:
|
||||
|
|
@ -246,7 +239,6 @@ class CodeParser:
|
|||
|
||||
return any(isinstance(n, ast.Return) for n in node.body)
|
||||
|
||||
|
||||
def parse_assign(self, stmt):
|
||||
"""
|
||||
Parses an Assign statement and returns a dictionary
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ from langflow.interface.custom.component import Component
|
|||
from langflow.interface.custom.directory_reader import DirectoryReader
|
||||
from langflow.interface.custom.utils import (
|
||||
extract_inner_type_from_generic_alias,
|
||||
extract_union_types_from_generic_alias)
|
||||
extract_union_types_from_generic_alias,
|
||||
)
|
||||
from langflow.services.database.models.flow import Flow
|
||||
from langflow.services.database.utils import session_getter
|
||||
from langflow.services.deps import get_credential_service, get_db_service
|
||||
|
|
@ -33,8 +34,6 @@ class CustomComponent(Component):
|
|||
self.cache = TTLCache(maxsize=1024, ttl=60)
|
||||
super().__init__(**data)
|
||||
|
||||
|
||||
|
||||
def custom_repr(self):
|
||||
if self.repr_value == "":
|
||||
self.repr_value = self.status
|
||||
|
|
@ -75,8 +74,6 @@ class CustomComponent(Component):
|
|||
def validate(self) -> bool:
|
||||
return self._class_template_validation(self.code) if self.code else False
|
||||
|
||||
|
||||
|
||||
@property
|
||||
def tree(self):
|
||||
return self.get_code_tree(self.code)
|
||||
|
|
@ -109,8 +106,6 @@ class CustomComponent(Component):
|
|||
if not self.code:
|
||||
return []
|
||||
|
||||
|
||||
|
||||
component_classes = [cls for cls in self.tree["classes"] if self.code_class_base_inheritance in cls["bases"]]
|
||||
if not component_classes:
|
||||
return []
|
||||
|
|
@ -124,7 +119,6 @@ class CustomComponent(Component):
|
|||
if not build_methods:
|
||||
return []
|
||||
|
||||
|
||||
return build_methods[0]
|
||||
|
||||
@property
|
||||
|
|
@ -156,7 +150,6 @@ class CustomComponent(Component):
|
|||
if not self.code:
|
||||
return ""
|
||||
|
||||
|
||||
base_name = self.code_class_base_inheritance
|
||||
method_name = self.function_entrypoint_name
|
||||
|
||||
|
|
@ -175,7 +168,6 @@ class CustomComponent(Component):
|
|||
if not self.code:
|
||||
return {}
|
||||
|
||||
|
||||
attributes = [
|
||||
main_class["attributes"]
|
||||
for main_class in self.tree.get("classes", [])
|
||||
|
|
@ -222,8 +214,7 @@ class CustomComponent(Component):
|
|||
return validate.create_function(self.code, self.function_entrypoint_name)
|
||||
|
||||
async def load_flow(self, flow_id: str, tweaks: Optional[dict] = None) -> Any:
|
||||
from langflow.processing.process import (build_sorted_vertices,
|
||||
process_tweaks)
|
||||
from langflow.processing.process import build_sorted_vertices, process_tweaks
|
||||
|
||||
db_service = get_db_service()
|
||||
with session_getter(db_service) as session:
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ from langflow.interface.vector_store.base import vectorstore_creator
|
|||
from langflow.interface.wrappers.base import wrapper_creator
|
||||
from langflow.template.field.base import TemplateField
|
||||
from langflow.template.frontend_node.constants import CLASSES_TO_REMOVE
|
||||
from langflow.template.frontend_node.custom_components import \
|
||||
CustomComponentFrontendNode
|
||||
from langflow.template.frontend_node.custom_components import CustomComponentFrontendNode
|
||||
from langflow.utils.util import get_base_classes
|
||||
from loguru import logger
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class DatabaseService(Service):
|
|||
|
||||
try:
|
||||
command.check(alembic_cfg)
|
||||
except util.exc.AutogenerateDiffsDetected as exc:
|
||||
except util.exc.AutogenerateDiffsDetected:
|
||||
logger.exception("AutogenerateDiffsDetected: {exc}")
|
||||
if not fix:
|
||||
raise RuntimeError("Something went wrong running migrations. Please, run `langflow migration --fix`")
|
||||
|
|
@ -169,7 +169,6 @@ class DatabaseService(Service):
|
|||
command.check(alembic_cfg)
|
||||
break
|
||||
except util.exc.AutogenerateDiffsDetected as exc:
|
||||
|
||||
# downgrade to base and upgrade again
|
||||
logger.warning(f"AutogenerateDiffsDetected: {exc}")
|
||||
command.downgrade(alembic_cfg, f"-{i}")
|
||||
|
|
@ -177,8 +176,6 @@ class DatabaseService(Service):
|
|||
time.sleep(3)
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
|
||||
|
||||
|
||||
def run_migrations_test(self):
|
||||
# This method is used for testing purposes only
|
||||
# We will check that all models are in the database
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ from langflow.services.auth.utils import create_super_user, verify_password
|
|||
from langflow.services.database.utils import initialize_database
|
||||
from langflow.services.manager import service_manager
|
||||
from langflow.services.schema import ServiceType
|
||||
from langflow.services.settings.constants import (DEFAULT_SUPERUSER,
|
||||
DEFAULT_SUPERUSER_PASSWORD)
|
||||
from langflow.services.settings.constants import DEFAULT_SUPERUSER, DEFAULT_SUPERUSER_PASSWORD
|
||||
from loguru import logger
|
||||
from sqlmodel import Session
|
||||
|
||||
|
|
@ -16,8 +15,7 @@ def get_factories_and_deps():
|
|||
from langflow.services.chat import factory as chat_factory
|
||||
from langflow.services.credentials import factory as credentials_factory
|
||||
from langflow.services.database import factory as database_factory
|
||||
from langflow.services.session import \
|
||||
factory as session_service_factory # type: ignore
|
||||
from langflow.services.session import factory as session_service_factory # type: ignore
|
||||
from langflow.services.settings import factory as settings_factory
|
||||
from langflow.services.store import factory as store_factory
|
||||
from langflow.services.task import factory as task_factory
|
||||
|
|
@ -173,8 +171,7 @@ def initialize_session_service():
|
|||
Initialize the session manager.
|
||||
"""
|
||||
from langflow.services.cache import factory as cache_factory
|
||||
from langflow.services.session import \
|
||||
factory as session_service_factory # type: ignore
|
||||
from langflow.services.session import factory as session_service_factory # type: ignore
|
||||
|
||||
initialize_settings_service()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue