🐛 fix(utils.py): add UnbuiltObject class to improve code readability and maintainability
🐛 fix(base.py): change the error message when _built_object is None to provide more specific information and handle the case when _built_object is an instance of UnbuiltObject
This commit is contained in:
parent
7933667973
commit
5cbb86b184
2 changed files with 14 additions and 3 deletions
|
|
@ -3,6 +3,10 @@ from typing import Any, Union
|
||||||
from langflow.interface.utils import extract_input_variables_from_prompt
|
from langflow.interface.utils import extract_input_variables_from_prompt
|
||||||
|
|
||||||
|
|
||||||
|
class UnbuiltObject:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def validate_prompt(prompt: str):
|
def validate_prompt(prompt: str):
|
||||||
"""Validate prompt."""
|
"""Validate prompt."""
|
||||||
if extract_input_variables_from_prompt(prompt):
|
if extract_input_variables_from_prompt(prompt):
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import ast
|
import ast
|
||||||
|
from langflow.graph.utils import UnbuiltObject
|
||||||
from langflow.interface.initialize import loading
|
from langflow.interface.initialize import loading
|
||||||
from langflow.interface.listing import ALL_TYPES_DICT
|
from langflow.interface.listing import ALL_TYPES_DICT
|
||||||
from langflow.utils.constants import DIRECT_TYPES
|
from langflow.utils.constants import DIRECT_TYPES
|
||||||
|
|
@ -22,7 +23,7 @@ class Vertex:
|
||||||
self.edges: List["Edge"] = []
|
self.edges: List["Edge"] = []
|
||||||
self.base_type: Optional[str] = base_type
|
self.base_type: Optional[str] = base_type
|
||||||
self._parse_data()
|
self._parse_data()
|
||||||
self._built_object = None
|
self._built_object = UnbuiltObject()
|
||||||
self._built = False
|
self._built = False
|
||||||
self.artifacts: Dict[str, Any] = {}
|
self.artifacts: Dict[str, Any] = {}
|
||||||
|
|
||||||
|
|
@ -245,8 +246,14 @@ class Vertex:
|
||||||
"""
|
"""
|
||||||
Checks if the built object is None and raises a ValueError if so.
|
Checks if the built object is None and raises a ValueError if so.
|
||||||
"""
|
"""
|
||||||
if self._built_object is None:
|
if isinstance(self._built_object, UnbuiltObject):
|
||||||
raise ValueError(f"Node type {self.vertex_type} not found")
|
raise ValueError(f"{self.vertex_type}: {self._built_object_repr()}")
|
||||||
|
elif self._built_object is None:
|
||||||
|
message = f"{self.vertex_type} returned None."
|
||||||
|
if self.base_type == "custom_components":
|
||||||
|
message += " Make sure your build method returns a component."
|
||||||
|
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
def build(self, force: bool = False) -> Any:
|
def build(self, force: bool = False) -> Any:
|
||||||
if not self._built or force:
|
if not self._built or force:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue