feat: Activate ruff rules UP(pyupgrade) (#3871)

* Activate ruff rules UP(pyupgrade)

* Set ruff target version

* Fix threading.Lock | None error
Due to https://github.com/python/cpython/issues/114315

* Fix Text in custom component supported typed

* Fix mypy issues

---------

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
Christophe Bornet 2024-09-25 19:38:50 +02:00 • committed by GitHub
commit f8a2a7d3b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
186 changed files with 911 additions and 983 deletions

View file

@ -4,7 +4,6 @@ import sys
import time
import warnings
from pathlib import Path
from typing import Optional
import click
import httpx
@ -84,7 +83,7 @@ def run(
workers: int = typer.Option(1, help="Number of worker processes.", envvar="LANGFLOW_WORKERS"),
timeout: int = typer.Option(300, help="Worker timeout in seconds.", envvar="LANGFLOW_WORKER_TIMEOUT"),
port: int = typer.Option(7860, help="Port to listen on.", envvar="LANGFLOW_PORT"),
components_path: Optional[Path] = typer.Option(
components_path: Path | None = typer.Option(
Path(__file__).parent / "components",
help="Path to the directory containing custom components.",
envvar="LANGFLOW_COMPONENTS_PATH",
@ -93,7 +92,7 @@ def run(
env_file: Path = typer.Option(None, help="Path to the .env file containing environment variables."),
log_level: str = typer.Option("critical", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"),
log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file.", envvar="LANGFLOW_LOG_FILE"),
cache: Optional[str] = typer.Option(
cache: str | None = typer.Option(
envvar="LANGFLOW_LANGCHAIN_CACHE",
help="Type of cache to use. (InMemoryCache, SQLiteCache)",
default=None,
@ -161,7 +160,7 @@ def run(
health_check_max_retries=health_check_max_retries,
)
# create path object if path is provided
static_files_dir: Optional[Path] = Path(path) if path else None
static_files_dir: Path | None = Path(path) if path else None
settings_service = get_settings_service()
settings_service.set("backend_only", backend_only)
app = setup_app(static_files_dir=static_files_dir, backend_only=backend_only)

View file

@ -1,3 +1,5 @@
from __future__ import annotations
import uuid
import warnings
from typing import TYPE_CHECKING, Any
@ -69,7 +71,7 @@ def build_input_keys_response(langchain_object, artifacts):
return input_keys_response
def validate_is_component(flows: list["Flow"]):
def validate_is_component(flows: list[Flow]):
for flow in flows:
if not flow.data or flow.is_component is not None:
continue
@ -152,7 +154,7 @@ async def build_graph_from_db_no_cache(flow_id: str, session: Session):
return await build_graph_from_data(flow_id, flow.data, flow_name=flow.name, user_id=str(flow.user_id))
async def build_graph_from_db(flow_id: str, session: Session, chat_service: "ChatService"):
async def build_graph_from_db(flow_id: str, session: Session, chat_service: ChatService):
graph = await build_graph_from_db_no_cache(flow_id, session)
await chat_service.set_cache(flow_id, graph)
return graph
@ -160,7 +162,7 @@ async def build_graph_from_db(flow_id: str, session: Session, chat_service: "Cha
async def build_and_cache_graph_from_data(
flow_id: str,
chat_service: "ChatService",
chat_service: ChatService,
graph_data: dict,
): # -> Graph | Any:
"""Build and cache the graph."""

View file

@ -1,3 +1,5 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from uuid import UUID
@ -25,7 +27,7 @@ class AsyncStreamingLLMCallbackHandleSIO(AsyncCallbackHandler):
def __init__(self, session_id: str):
self.chat_service = get_chat_service()
self.client_id = session_id
self.socketio_service: "SocketIOService" = get_socket_service()
self.socketio_service: SocketIOService = get_socket_service()
self.sid = session_id
# self.socketio_service = self.chat_service.active_connections[self.client_id]

View file

@ -1,3 +1,5 @@
from __future__ import annotations
import asyncio
import json
import time
@ -72,9 +74,9 @@ async def retrieve_vertices_order(
data: Annotated[FlowDataRequest | None, Body(embed=True)] | None = None,
stop_component_id: str | None = None,
start_component_id: str | None = None,
chat_service: "ChatService" = Depends(get_chat_service),
chat_service: ChatService = Depends(get_chat_service),
session=Depends(get_session),
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
telemetry_service: TelemetryService = Depends(get_telemetry_service),
):
"""
Retrieve the vertices order for a given flow.
@ -148,12 +150,12 @@ async def build_flow(
stop_component_id: str | None = None,
start_component_id: str | None = None,
log_builds: bool | None = True,
chat_service: "ChatService" = Depends(get_chat_service),
chat_service: ChatService = Depends(get_chat_service),
current_user=Depends(get_current_active_user),
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
telemetry_service: TelemetryService = Depends(get_telemetry_service),
session=Depends(get_session),
):
async def build_graph_and_get_order() -> tuple[list[str], list[str], "Graph"]:
async def build_graph_and_get_order() -> tuple[list[str], list[str], Graph]:
start_time = time.perf_counter()
components_count = None
try:
@ -205,7 +207,7 @@ async def build_flow(
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc
async def _build_vertex(vertex_id: str, graph: "Graph", event_manager: "EventManager") -> VertexBuildResponse:
async def _build_vertex(vertex_id: str, graph: Graph, event_manager: EventManager) -> VertexBuildResponse:
flow_id_str = str(flow_id)
next_runnable_vertices = []
@ -320,9 +322,9 @@ async def build_flow(
async def build_vertices(
vertex_id: str,
graph: "Graph",
graph: Graph,
client_consumed_queue: asyncio.Queue,
event_manager: "EventManager",
event_manager: EventManager,
) -> None:
build_task = asyncio.create_task(asyncio.to_thread(asyncio.run, _build_vertex(vertex_id, graph, event_manager)))
try:
@ -457,9 +459,9 @@ async def build_vertex(
background_tasks: BackgroundTasks,
inputs: Annotated[InputValueRequest | None, Body(embed=True)] = None,
files: list[str] | None = None,
chat_service: "ChatService" = Depends(get_chat_service),
chat_service: ChatService = Depends(get_chat_service),
current_user=Depends(get_current_active_user),
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
telemetry_service: TelemetryService = Depends(get_telemetry_service),
):
"""Build a vertex instead of the entire graph.
@ -489,7 +491,7 @@ async def build_vertex(
if not cache:
# If there's no cache
logger.warning(f"No cache found for {flow_id_str}. Building graph starting at {vertex_id}")
graph: "Graph" = await build_graph_from_db(
graph: Graph = await build_graph_from_db(
flow_id=flow_id_str, session=next(get_session()), chat_service=chat_service
)
else:
@ -609,8 +611,8 @@ async def build_vertex_stream(
flow_id: uuid.UUID,
vertex_id: str,
session_id: str | None = None,
chat_service: "ChatService" = Depends(get_chat_service),
session_service: "SessionService" = Depends(get_session_service),
chat_service: ChatService = Depends(get_chat_service),
session_service: SessionService = Depends(get_session_service),
):
"""Build a vertex instead of the entire graph.
@ -650,7 +652,7 @@ async def build_vertex_stream(
else:
graph = cache.get("result")
vertex: "InterfaceVertex" = graph.get_vertex(vertex_id)
vertex: InterfaceVertex = graph.get_vertex(vertex_id)
if not hasattr(vertex, "stream"):
raise ValueError(f"Vertex {vertex_id} does not support streaming")
if isinstance(vertex._built_result, str) and vertex._built_result:

View file

@ -1,3 +1,5 @@
from __future__ import annotations
import time
from asyncio import Lock
from http import HTTPStatus
@ -62,7 +64,7 @@ router = APIRouter(tags=["Base"])
@router.get("/all", dependencies=[Depends(get_current_active_user)])
async def get_all(
settings_service=Depends(get_settings_service),
cache_service: "CacheService" = Depends(dependency=get_cache_service),
cache_service: CacheService = Depends(dependency=get_cache_service),
force_refresh: bool = False,
):
from langflow.interface.types import get_and_cache_all_types_dict
@ -181,7 +183,7 @@ async def simplified_run_flow(
input_request: SimplifiedAPIRequest = SimplifiedAPIRequest(),
stream: bool = False,
api_key_user: UserRead = Depends(api_key_security),
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
telemetry_service: TelemetryService = Depends(get_telemetry_service),
):
"""
Executes a specified flow by ID with input customization, performance enhancements through caching, and optional data streaming.
@ -290,7 +292,7 @@ async def webhook_run_flow(
user: Annotated[User, Depends(get_user_by_flow_id_or_endpoint_name)],
request: Request,
background_tasks: BackgroundTasks,
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
telemetry_service: TelemetryService = Depends(get_telemetry_service),
):
"""
Run a flow using a webhook request.
@ -484,7 +486,7 @@ async def process(
tweaks: dict | None = None,
clear_cache: Annotated[bool, Body(embed=True)] = False, # noqa: F821
session_id: Annotated[None | str, Body(embed=True)] = None, # noqa: F821
task_service: "TaskService" = Depends(get_task_service),
task_service: TaskService = Depends(get_task_service),
api_key_user: UserRead = Depends(api_key_security),
sync: Annotated[bool, Body(embed=True)] = True, # noqa: F821
session_service: SessionService = Depends(get_session_service),
@ -633,7 +635,7 @@ def get_config():
try:
from langflow.services.deps import get_settings_service
settings_service: "SettingsService" = get_settings_service() # type: ignore
settings_service: SettingsService = get_settings_service() # type: ignore
return settings_service.settings.model_dump()
except Exception as exc:
logger.exception(exc)

View file

@ -1,5 +1,5 @@
from abc import abstractmethod
from typing import List, Optional, Union, cast
from typing import cast
from langchain.agents import AgentExecutor, BaseMultiActionAgent, BaseSingleActionAgent
from langchain.agents.agent import RunnableAgent
@ -20,7 +20,7 @@ from langflow.utils.constants import MESSAGE_SENDER_AI
class LCAgentComponent(Component):
trace_type = "agent"
_base_inputs: List[InputTypes] = [
_base_inputs: list[InputTypes] = [
MessageTextInput(name="input_value", display_name="Input"),
BoolInput(
name="handle_parsing_errors",
@ -89,7 +89,7 @@ class LCAgentComponent(Component):
}
return {**base, "agent_executor_kwargs": agent_kwargs}
def get_chat_history_data(self) -> Optional[List[Data]]:
def get_chat_history_data(self) -> list[Data] | None:
# might be overridden in subclasses
return None
@ -128,7 +128,7 @@ class LCToolsAgentComponent(LCAgentComponent):
async def run_agent(
self,
agent: Union[Runnable, BaseSingleActionAgent, BaseMultiActionAgent, AgentExecutor],
agent: Runnable | BaseSingleActionAgent | BaseMultiActionAgent | AgentExecutor,
) -> Text:
if isinstance(agent, AgentExecutor):
runnable = agent

View file

@ -1,4 +1,4 @@
from typing import Any, Dict, List
from typing import Any
from uuid import UUID
from langchain.callbacks.base import AsyncCallbackHandler
@ -15,14 +15,14 @@ class AgentAsyncHandler(AsyncCallbackHandler):
async def on_tool_start(
self,
serialized: Dict[str, Any],
serialized: dict[str, Any],
input_str: str,
*,
run_id: UUID,
parent_run_id: UUID | None = None,
tags: List[str] | None = None,
metadata: Dict[str, Any] | None = None,
inputs: Dict[str, Any] | None = None,
tags: list[str] | None = None,
metadata: dict[str, Any] | None = None,
inputs: dict[str, Any] | None = None,
**kwargs: Any,
) -> None:
if self.log_function is None:
@ -62,7 +62,7 @@ class AgentAsyncHandler(AsyncCallbackHandler):
*,
run_id: UUID,
parent_run_id: UUID | None = None,
tags: List[str] | None = None,
tags: list[str] | None = None,
**kwargs: Any,
) -> None:
if self.log_function is None:
@ -85,7 +85,7 @@ class AgentAsyncHandler(AsyncCallbackHandler):
*,
run_id: UUID,
parent_run_id: UUID | None = None,
tags: List[str] | None = None,
tags: list[str] | None = None,
**kwargs: Any,
) -> None:
if self.log_function is None:

View file

@ -1,4 +1,5 @@
from typing import Callable, List, Tuple, Union, cast
from collections.abc import Callable
from typing import cast
from crewai import Agent, Crew, Process, Task # type: ignore
from crewai.task import TaskOutput # type: ignore
@ -62,7 +63,7 @@ class BaseCrewComponent(Component):
def get_step_callback(
self,
) -> Callable:
def step_callback(agent_output: Union[AgentFinish, List[Tuple[AgentAction, str]]]):
def step_callback(agent_output: AgentFinish | list[tuple[AgentAction, str]]):
_id = self._vertex.id if self._vertex else self.display_name
if isinstance(agent_output, AgentFinish):
messages = agent_output.messages

View file

@ -1,4 +1,5 @@
from typing import Any, Callable, Dict, List, Optional, Sequence, Union
from collections.abc import Callable, Sequence
from typing import Any
from langchain.agents import (
create_json_chat_agent,
@ -24,17 +25,17 @@ class AgentSpec(BaseModel):
BaseLanguageModel,
Sequence[BaseTool],
BasePromptTemplate | ChatPromptTemplate,
Optional[Callable[[List[BaseTool]], str]],
Optional[Union[bool, List[str]]],
Callable[[list[BaseTool]], str] | None,
bool | list[str] | None,
],
Any,
]
prompt: Optional[Any] = None
fields: List[str]
hub_repo: Optional[str] = None
prompt: Any | None = None
fields: list[str]
hub_repo: str | None = None
def data_to_messages(data: List[Data]) -> List[BaseMessage]:
def data_to_messages(data: list[Data]) -> list[BaseMessage]:
"""
Convert a list of data to a list of messages.
@ -51,9 +52,9 @@ def validate_and_create_xml_agent(
llm: BaseLanguageModel,
tools: Sequence[BaseTool],
prompt: BasePromptTemplate,
tools_renderer: Callable[[List[BaseTool]], str] = render_text_description,
tools_renderer: Callable[[list[BaseTool]], str] = render_text_description,
*,
stop_sequence: Union[bool, List[str]] = True,
stop_sequence: bool | list[str] = True,
):
return create_xml_agent(
llm=llm,
@ -68,9 +69,9 @@ def validate_and_create_openai_tools_agent(
llm: BaseLanguageModel,
tools: Sequence[BaseTool],
prompt: ChatPromptTemplate,
tools_renderer: Callable[[List[BaseTool]], str] = render_text_description,
tools_renderer: Callable[[list[BaseTool]], str] = render_text_description,
*,
stop_sequence: Union[bool, List[str]] = True,
stop_sequence: bool | list[str] = True,
):
return create_openai_tools_agent(
llm=llm,
@ -83,9 +84,9 @@ def validate_and_create_tool_calling_agent(
llm: BaseLanguageModel,
tools: Sequence[BaseTool],
prompt: ChatPromptTemplate,
tools_renderer: Callable[[List[BaseTool]], str] = render_text_description,
tools_renderer: Callable[[list[BaseTool]], str] = render_text_description,
*,
stop_sequence: Union[bool, List[str]] = True,
stop_sequence: bool | list[str] = True,
):
return create_tool_calling_agent(
llm=llm,
@ -98,9 +99,9 @@ def validate_and_create_json_chat_agent(
llm: BaseLanguageModel,
tools: Sequence[BaseTool],
prompt: ChatPromptTemplate,
tools_renderer: Callable[[List[BaseTool]], str] = render_text_description,
tools_renderer: Callable[[list[BaseTool]], str] = render_text_description,
*,
stop_sequence: Union[bool, List[str]] = True,
stop_sequence: bool | list[str] = True,
):
return create_json_chat_agent(
llm=llm,
@ -111,7 +112,7 @@ def validate_and_create_json_chat_agent(
)
AGENTS: Dict[str, AgentSpec] = {
AGENTS: dict[str, AgentSpec] = {
"Tool Calling Agent": AgentSpec(
func=validate_and_create_tool_calling_agent,
prompt=None,

View file

@ -153,13 +153,13 @@ def parse_context(curl_command):
# proxy_auth = parsed_args.proxy_user
if parsed_args.proxy and parsed_args.proxy_user:
proxies = {
"http": "http://{}@{}/".format(parsed_args.proxy_user, parsed_args.proxy),
"https": "http://{}@{}/".format(parsed_args.proxy_user, parsed_args.proxy),
"http": f"http://{parsed_args.proxy_user}@{parsed_args.proxy}/",
"https": f"http://{parsed_args.proxy_user}@{parsed_args.proxy}/",
}
elif parsed_args.proxy:
proxies = {
"http": "http://{}/".format(parsed_args.proxy),
"https": "http://{}/".format(parsed_args.proxy),
"http": f"http://{parsed_args.proxy}/",
"https": f"http://{parsed_args.proxy}/",
}
return ParsedContext(

View file

@ -1,8 +1,8 @@
import unicodedata
import xml.etree.ElementTree as ET
from collections.abc import Callable
from concurrent import futures
from pathlib import Path
from typing import Callable, List, Optional
import chardet
import orjson
@ -49,8 +49,8 @@ def retrieve_file_paths(
load_hidden: bool,
recursive: bool,
depth: int,
types: List[str] = TEXT_FILE_TYPES,
) -> List[str]:
types: list[str] = TEXT_FILE_TYPES,
) -> list[str]:
path_obj = Path(path)
if not path_obj.exists() or not path_obj.is_dir():
raise ValueError(f"Path {path} must exist and be a directory.")
@ -75,7 +75,7 @@ def retrieve_file_paths(
return file_paths
def partition_file_to_data(file_path: str, silent_errors: bool) -> Optional[Data]:
def partition_file_to_data(file_path: str, silent_errors: bool) -> Data | None:
# Use the partition function to load the file
from unstructured.partition.auto import partition # type: ignore
@ -103,7 +103,7 @@ def read_text_file(file_path: str) -> str:
if encoding in ["Windows-1252", "Windows-1254", "MacRoman"]:
encoding = "utf-8"
with open(file_path, "r", encoding=encoding) as f:
with open(file_path, encoding=encoding) as f:
return f.read()
@ -122,7 +122,7 @@ def parse_pdf_to_text(file_path: str) -> str:
return "\n\n".join([page.extract_text() for page in reader.pages])
def parse_text_file_to_data(file_path: str, silent_errors: bool) -> Optional[Data]:
def parse_text_file_to_data(file_path: str, silent_errors: bool) -> Data | None:
try:
if file_path.endswith(".pdf"):
text = parse_pdf_to_text(file_path)
@ -171,11 +171,11 @@ def parse_text_file_to_data(file_path: str, silent_errors: bool) -> Optional[Dat
def parallel_load_data(
file_paths: List[str],
file_paths: list[str],
silent_errors: bool,
max_concurrency: int,
load_function: Callable = parse_text_file_to_data,
) -> List[Optional[Data]]:
) -> list[Data | None]:
with futures.ThreadPoolExecutor(max_workers=max_concurrency) as executor:
loaded_files = executor.map(
lambda file_path: load_function(file_path, silent_errors),

View file

@ -1,5 +1,3 @@
from typing import List
from loguru import logger
from langflow.graph.schema import ResultData, RunOutputs
@ -7,7 +5,7 @@ from langflow.schema import Data
from langflow.schema.message import Message
def build_data_from_run_outputs(run_outputs: RunOutputs) -> List[Data]:
def build_data_from_run_outputs(run_outputs: RunOutputs) -> list[Data]:
"""
Build a list of data from the given RunOutputs.
@ -27,7 +25,7 @@ def build_data_from_run_outputs(run_outputs: RunOutputs) -> List[Data]:
return data
def build_data_from_result_data(result_data: ResultData, get_final_results_only: bool = True) -> List[Data]:
def build_data_from_result_data(result_data: ResultData, get_final_results_only: bool = True) -> list[Data]:
"""
Build a list of data from the given ResultData.
@ -80,7 +78,7 @@ def build_data_from_result_data(result_data: ResultData, get_final_results_only:
return data
def format_flow_output_data(data: List[Data]) -> str:
def format_flow_output_data(data: list[Data]) -> str:
"""
Format the flow output data into a string.

View file

@ -1,4 +1,4 @@
from typing import AsyncIterator, Iterator, Optional, Union
from collections.abc import AsyncIterator, Iterator
from langflow.custom import Component
from langflow.memory import store_message
@ -54,7 +54,7 @@ class ChatComponent(Component):
def _stream_message(self, message: Message, message_id: str) -> str:
iterator = message.text
if not isinstance(iterator, (AsyncIterator, Iterator)):
if not isinstance(iterator, AsyncIterator | Iterator):
raise ValueError("The message must be an iterator or an async iterator.")
if isinstance(iterator, AsyncIterator):
@ -68,12 +68,12 @@ class ChatComponent(Component):
def build_with_data(
self,
sender: Optional[str] = "User",
sender_name: Optional[str] = "User",
input_value: Optional[Union[str, Data, Message]] = None,
files: Optional[list[str]] = None,
session_id: Optional[str] = None,
return_message: Optional[bool] = False,
sender: str | None = "User",
sender_name: str | None = "User",
input_value: str | Data | Message | None = None,
files: list[str] | None = None,
session_id: str | None = None,
return_message: bool | None = False,
) -> Message:
message: Message | None = None

View file

@ -1,5 +1,5 @@
from abc import abstractmethod
from typing import Sequence, Union
from collections.abc import Sequence
from langflow.custom import Component
from langflow.field_typing import Tool
@ -24,7 +24,7 @@ class LCToolComponent(Component):
raise ValueError(f"Method '{method_name}' must be defined.")
@abstractmethod
def run_model(self) -> Union[Data, list[Data]]:
def run_model(self) -> Data | list[Data]:
"""
Run model and return the output.
"""

View file

@ -1,5 +1,3 @@
from typing import Optional
from langflow.custom import CustomComponent
from langflow.schema import Data
from langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_USER
@ -45,6 +43,6 @@ class BaseMemoryComponent(CustomComponent):
raise NotImplementedError
def add_message(
self, sender: str, sender_name: str, text: str, session_id: str, metadata: Optional[dict] = None, **kwargs
self, sender: str, sender_name: str, text: str, session_id: str, metadata: dict | None = None, **kwargs
):
raise NotImplementedError

View file

@ -1,7 +1,6 @@
import json
import warnings
from abc import abstractmethod
from typing import List, Optional, Union
from langchain_core.language_models.llms import LLM
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage
@ -20,7 +19,7 @@ class LCModelComponent(Component):
description: str = "Model Description"
trace_type = "llm"
_base_inputs: List[InputTypes] = [
_base_inputs: list[InputTypes] = [
MessageInput(name="input_value", display_name="Input"),
MessageTextInput(
name="system_message",
@ -138,9 +137,9 @@ class LCModelComponent(Component):
runnable: LanguageModel,
stream: bool,
input_value: str | Message,
system_message: Optional[str] = None,
system_message: str | None = None,
):
messages: list[Union[BaseMessage]] = []
messages: list[BaseMessage] = []
if not input_value and not system_message:
raise ValueError("The message you want to send to the model is empty.")
system_message_added = False
@ -161,7 +160,7 @@ class LCModelComponent(Component):
if system_message and not system_message_added:
messages.append(SystemMessage(content=system_message))
inputs: Union[list, dict] = messages or {}
inputs: list | dict = messages or {}
try:
runnable = runnable.with_config( # type: ignore
{

View file

@ -1,5 +1,5 @@
from collections import defaultdict
from typing import Any, Dict, List, Optional
from typing import Any
from fastapi import HTTPException
from langchain_core.prompts import PromptTemplate
@ -198,7 +198,7 @@ def update_input_variables_field(input_variables, template):
def process_prompt_template(
template: str, name: str, custom_fields: Optional[Dict[str, List[str]]], frontend_node_template: Dict[str, Any]
template: str, name: str, custom_fields: dict[str, list[str]] | None, frontend_node_template: dict[str, Any]
):
"""Process and validate prompt template, update template and custom fields."""
# Validate the prompt template and extract input variables

View file

@ -1,5 +1,5 @@
import warnings
from typing import Any, List, Optional, Type
from typing import Any
from langchain_core.runnables import RunnableConfig
from langchain_core.tools import BaseTool, ToolException
@ -15,10 +15,10 @@ from langflow.utils.async_helpers import run_until_complete
class FlowTool(BaseTool):
name: str
description: str
graph: Optional[Graph] = None
flow_id: Optional[str] = None
user_id: Optional[str] = None
inputs: List["Vertex"] = []
graph: Graph | None = None
flow_id: str | None = None
user_id: str | None = None
inputs: list["Vertex"] = []
get_final_results_only: bool = True
@property
@ -26,7 +26,7 @@ class FlowTool(BaseTool):
schema = self.get_input_schema()
return schema.schema()["properties"]
def get_input_schema(self, config: Optional[RunnableConfig] = None) -> Type[BaseModel]:
def get_input_schema(self, config: RunnableConfig | None = None) -> type[BaseModel]:
"""The tool's input schema."""
if self.args_schema is not None:
return self.args_schema
@ -68,7 +68,7 @@ class FlowTool(BaseTool):
data.extend(build_data_from_result_data(output, get_final_results_only=self.get_final_results_only))
return format_flow_output_data(data)
def validate_inputs(self, args_names: List[dict[str, str]], args: Any, kwargs: Any):
def validate_inputs(self, args_names: list[dict[str, str]], args: Any, kwargs: Any):
"""Validate the inputs."""
if len(args) > 0 and len(args) != len(args_names):

View file

@ -1,6 +1,6 @@
from abc import ABC, ABCMeta, abstractmethod
from functools import wraps
from typing import List, cast
from typing import cast
from langchain_core.documents import Document
from loguru import logger
@ -94,7 +94,7 @@ class LCVectorStoreComponent(Component, ABC, metaclass=EnforceCacheDecoratorMeta
vector_store: VectorStore,
k=10,
**kwargs,
) -> List[Data]:
) -> list[Data]:
"""
Search for data in the vector store based on the input value and search type.
@ -110,7 +110,7 @@ class LCVectorStoreComponent(Component, ABC, metaclass=EnforceCacheDecoratorMeta
ValueError: If invalid inputs are provided.
"""
docs: List[Document] = []
docs: list[Document] = []
if input_value and isinstance(input_value, str) and hasattr(vector_store, "search"):
docs = vector_store.search(query=input_value, search_type=search_type.lower(), k=k, **kwargs)
else:
@ -140,7 +140,7 @@ class LCVectorStoreComponent(Component, ABC, metaclass=EnforceCacheDecoratorMeta
else:
raise ValueError(f"Vector Store {vector_store.__class__.__name__} does not have an as_retriever method.")
def search_documents(self) -> List[Data]:
def search_documents(self) -> list[Data]:
"""
Search for documents in the vector store.
"""

View file

@ -1,5 +1,5 @@
import json
from typing import Any, Dict, Union
from typing import Any
import requests
from bs4 import BeautifulSoup
@ -54,7 +54,7 @@ class AddContentToPage(LCToolComponent):
args_schema=self.AddContentToPageSchema,
)
def _add_content_to_page(self, markdown_text: str, block_id: str) -> Union[Dict[str, Any], str]:
def _add_content_to_page(self, markdown_text: str, block_id: str) -> dict[str, Any] | str:
try:
html_text = markdown(markdown_text)
soup = BeautifulSoup(html_text, "html.parser")
@ -209,7 +209,7 @@ class AddContentToPage(LCToolComponent):
return blocks
def create_block(self, block_type: str, content: str, **kwargs) -> Dict[str, Any]:
def create_block(self, block_type: str, content: str, **kwargs) -> dict[str, Any]:
block: dict[str, Any] = {
"object": "block",
"type": block_type,

Some files were not shown because too many files have changed in this diff Show more