Fix custom component index function

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-11-24 16:21:17 -03:00
commit a16725b6c7
2 changed files with 11 additions and 1 deletions

View file

@ -5,6 +5,7 @@ from typing import Any, ClassVar, Optional
from cachetools import TTLCache, cachedmethod
from fastapi import HTTPException
from langflow.interface.custom.code_parser import CodeParser
from langflow.utils import validate

View file

@ -197,7 +197,6 @@ class CustomComponent(Component):
return get_credential
@property
def list_key_names(self):
if hasattr(self, "_user_id") and not self._user_id:
raise ValueError(f"User id is not set for {self.__class__.__name__}")
@ -206,6 +205,16 @@ class CustomComponent(Component):
with session_getter(db_service) as session:
return credential_service.list_credentials(user_id=self._user_id, session=session)
def index(self, value: int = 0):
"""Returns a function that returns the value at the given index in the iterable."""
def get_index(iterable: List[Any]):
if iterable:
return iterable[value]
return iterable
return get_index
@property
def get_function(self):
return validate.create_function(self.code, self.function_entrypoint_name)