Changed component.py to fix bug
This commit is contained in:
parent
6c9a87bed7
commit
e38cf0dd6c
1 changed files with 18 additions and 15 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import ast
|
||||||
import operator
|
import operator
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, ClassVar, Optional
|
from typing import Any, ClassVar, Optional
|
||||||
|
|
@ -5,9 +6,7 @@ from typing import Any, ClassVar, Optional
|
||||||
from cachetools import TTLCache, cachedmethod
|
from cachetools import TTLCache, cachedmethod
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
from langflow.interface.custom.attributes import ATTR_FUNC_MAPPING
|
|
||||||
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.utils import validate
|
from langflow.utils import validate
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -39,7 +38,6 @@ class Component:
|
||||||
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.")
|
||||||
else:
|
|
||||||
super().__setattr__(key, value)
|
super().__setattr__(key, value)
|
||||||
|
|
||||||
@cachedmethod(cache=operator.attrgetter("cache"))
|
@cachedmethod(cache=operator.attrgetter("cache"))
|
||||||
|
|
@ -65,19 +63,24 @@ class Component:
|
||||||
|
|
||||||
return validate.create_function(self.code, self._function_entrypoint_name)
|
return validate.create_function(self.code, self._function_entrypoint_name)
|
||||||
|
|
||||||
def build_template_config(self) -> dict:
|
def build_template_config(self, attributes) -> dict:
|
||||||
if not self.code:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
cc_class = eval_custom_component_code(self.code)
|
|
||||||
component_instance = cc_class()
|
|
||||||
template_config = {}
|
template_config = {}
|
||||||
|
|
||||||
for attribute, func in ATTR_FUNC_MAPPING.items():
|
for item in attributes:
|
||||||
if hasattr(component_instance, attribute):
|
item_name = item.get("name")
|
||||||
value = getattr(component_instance, attribute)
|
|
||||||
if value is not None:
|
if item_value := item.get("value"):
|
||||||
template_config[attribute] = func(value=value)
|
if "display_name" in item_name:
|
||||||
|
template_config["display_name"] = ast.literal_eval(item_value)
|
||||||
|
|
||||||
|
elif "description" in item_name:
|
||||||
|
template_config["description"] = ast.literal_eval(item_value)
|
||||||
|
|
||||||
|
elif "beta" in item_name:
|
||||||
|
template_config["beta"] = ast.literal_eval(item_value)
|
||||||
|
|
||||||
|
elif "documentation" in item_name:
|
||||||
|
template_config["documentation"] = ast.literal_eval(item_value)
|
||||||
|
|
||||||
return template_config
|
return template_config
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue