Refactor Component class in custom_component/component.py
This commit is contained in:
parent
aba5d9c20f
commit
96d733c04d
1 changed files with 5 additions and 9 deletions
|
|
@ -5,7 +5,6 @@ from typing import Any, ClassVar, Optional
|
||||||
import emoji
|
import emoji
|
||||||
from cachetools import TTLCache, cachedmethod
|
from cachetools import TTLCache, cachedmethod
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
from langflow.interface.custom.code_parser import CodeParser
|
from langflow.interface.custom.code_parser import CodeParser
|
||||||
from langflow.interface.custom.eval import eval_custom_component_code
|
from langflow.interface.custom.eval import eval_custom_component_code
|
||||||
from langflow.utils import validate
|
from langflow.utils import validate
|
||||||
|
|
@ -38,10 +37,6 @@ class Component:
|
||||||
else:
|
else:
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
# Validate the emoji at the icon field
|
|
||||||
if hasattr(self, "icon") and self.icon:
|
|
||||||
self.icon = self.validate_icon(self.icon)
|
|
||||||
|
|
||||||
def __setattr__(self, key, value):
|
def __setattr__(self, key, value):
|
||||||
if key == "_user_id" and hasattr(self, "_user_id"):
|
if key == "_user_id" and hasattr(self, "_user_id"):
|
||||||
warnings.warn("user_id is immutable and cannot be changed.")
|
warnings.warn("user_id is immutable and cannot be changed.")
|
||||||
|
|
@ -70,8 +65,8 @@ class Component:
|
||||||
|
|
||||||
return validate.create_function(self.code, self._function_entrypoint_name)
|
return validate.create_function(self.code, self._function_entrypoint_name)
|
||||||
|
|
||||||
def getattr_return_str(self, component, value):
|
def getattr_return_str(self, value):
|
||||||
value = getattr(component, value)
|
|
||||||
return str(value) if value else ""
|
return str(value) if value else ""
|
||||||
|
|
||||||
def build_template_config(self) -> dict:
|
def build_template_config(self) -> dict:
|
||||||
|
|
@ -91,7 +86,8 @@ class Component:
|
||||||
|
|
||||||
for attribute, func in attributes_func_mapping.items():
|
for attribute, func in attributes_func_mapping.items():
|
||||||
if hasattr(component_instance, attribute):
|
if hasattr(component_instance, attribute):
|
||||||
template_config[attribute] = func(component=component_instance, value=attribute)
|
value = getattr(component_instance, attribute)
|
||||||
|
template_config[attribute] = func(value=value)
|
||||||
|
|
||||||
return template_config
|
return template_config
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue