🐛 fix(base.py): add *args and **kwargs to build method in Vertex class to allow for additional arguments to be passed

🐛 fix(types.py): add *args and **kwargs to build method in AgentVertex, LLMVertex, WrapperVertex, ChainVertex, and PromptVertex classes to allow for additional arguments to be passed
🐛 fix(utils.py): change return type annotation in api_key_security function from Optional[ApiKey] to Optional[User] to reflect the actual return type
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-28 18:05:43 -03:00
commit 9804d58d32
3 changed files with 14 additions and 10 deletions

View file

@ -258,9 +258,9 @@ class Vertex:
raise ValueError(message) raise ValueError(message)
def build(self, force: bool = False, user_id=None) -> Any: def build(self, force: bool = False, user_id=None, *args, **kwargs) -> Any:
if not self._built or force: if not self._built or force:
self._build(user_id) self._build(user_id, *args, **kwargs)
return self._built_object return self._built_object

View file

@ -21,7 +21,7 @@ class AgentVertex(Vertex):
elif isinstance(source_node, ChainVertex): elif isinstance(source_node, ChainVertex):
self.chains.append(source_node) self.chains.append(source_node)
def build(self, force: bool = False, user_id=None) -> Any: def build(self, force: bool = False, user_id=None, *args, **kwargs) -> Any:
if not self._built or force: if not self._built or force:
self._set_tools_and_chains() self._set_tools_and_chains()
# First, build the tools # First, build the tools
@ -49,7 +49,7 @@ class LLMVertex(Vertex):
def __init__(self, data: Dict): def __init__(self, data: Dict):
super().__init__(data, base_type="llms") super().__init__(data, base_type="llms")
def build(self, force: bool = False, user_id=None) -> Any: def build(self, force: bool = False, user_id=None, *args, **kwargs) -> Any:
# LLM is different because some models might take up too much memory # LLM is different because some models might take up too much memory
# or time to load. So we only load them when we need them.ß # or time to load. So we only load them when we need them.ß
if self.vertex_type == self.built_node_type: if self.vertex_type == self.built_node_type:
@ -77,7 +77,7 @@ class WrapperVertex(Vertex):
def __init__(self, data: Dict): def __init__(self, data: Dict):
super().__init__(data, base_type="wrappers") super().__init__(data, base_type="wrappers")
def build(self, force: bool = False, user_id=None) -> Any: def build(self, force: bool = False, user_id=None, *args, **kwargs) -> Any:
if not self._built or force: if not self._built or force:
if "headers" in self.params: if "headers" in self.params:
self.params["headers"] = ast.literal_eval(self.params["headers"]) self.params["headers"] = ast.literal_eval(self.params["headers"])
@ -148,14 +148,16 @@ class ChainVertex(Vertex):
def build( def build(
self, self,
force: bool = False, force: bool = False,
tools: Optional[List[Union[ToolkitVertex, ToolVertex]]] = None,
user_id=None, user_id=None,
*args,
**kwargs,
) -> Any: ) -> Any:
if not self._built or force: if not self._built or force:
# Check if the chain requires a PromptVertex # Check if the chain requires a PromptVertex
for key, value in self.params.items(): for key, value in self.params.items():
if isinstance(value, PromptVertex): if isinstance(value, PromptVertex):
# Build the PromptVertex, passing the tools if available # Build the PromptVertex, passing the tools if available
tools = kwargs.get("tools", None)
self.params[key] = value.build(tools=tools, force=force) self.params[key] = value.build(tools=tools, force=force)
self._build(user_id=user_id) self._build(user_id=user_id)
@ -170,8 +172,10 @@ class PromptVertex(Vertex):
def build( def build(
self, self,
force: bool = False, force: bool = False,
tools: Optional[List[Union[ToolkitVertex, ToolVertex]]] = None,
user_id=None, user_id=None,
tools: Optional[List[Union[ToolkitVertex, ToolVertex]]] = None,
*args,
**kwargs,
) -> Any: ) -> Any:
if not self._built or force: if not self._built or force:
if ( if (

View file

@ -2,7 +2,7 @@ from datetime import datetime, timedelta, timezone
from fastapi import Depends, HTTPException, Security, status from fastapi import Depends, HTTPException, Security, status
from fastapi.security import APIKeyHeader, APIKeyQuery, OAuth2PasswordBearer from fastapi.security import APIKeyHeader, APIKeyQuery, OAuth2PasswordBearer
from jose import JWTError, jwt from jose import JWTError, jwt
from typing import Annotated, Coroutine, Optional from typing import Annotated, Coroutine, Optional, Union
from uuid import UUID from uuid import UUID
from langflow.services.database.models.api_key.api_key import ApiKey from langflow.services.database.models.api_key.api_key import ApiKey
from langflow.services.database.models.api_key.crud import check_key from langflow.services.database.models.api_key.crud import check_key
@ -32,9 +32,9 @@ async def api_key_security(
query_param: str = Security(api_key_query), query_param: str = Security(api_key_query),
header_param: str = Security(api_key_header), header_param: str = Security(api_key_header),
db: Session = Depends(get_session), db: Session = Depends(get_session),
) -> Optional[ApiKey]: ) -> Optional[User]:
settings_manager = get_settings_manager() settings_manager = get_settings_manager()
result = None result: Optional[Union[ApiKey, User]] = None
if settings_manager.auth_settings.AUTO_LOGIN: if settings_manager.auth_settings.AUTO_LOGIN:
# Get the first user # Get the first user
settings_manager.auth_settings.FIRST_SUPERUSER settings_manager.auth_settings.FIRST_SUPERUSER