diff --git a/src/backend/langflow/interface/custom/component.py b/src/backend/langflow/interface/custom/component.py index 0f3d25d5d..dfd7c0b00 100644 --- a/src/backend/langflow/interface/custom/component.py +++ b/src/backend/langflow/interface/custom/component.py @@ -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 diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index eb8670aba..98be2299e 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -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)