mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-23 23:13:58 +08:00
refactor(callback): simplify import statements and type annotations for better readability (#2793)
* refactor: add LogFunctionType protocol for type hint The LogFunctionType protocol is introduced to define the structure of a logging function that takes a message and an optional name parameter. This protocol will be used to ensure consistency and compatibility with other parts of the codebase when logging messages. * refactor(callback.py): simplify import statements and type annotations for better readability
This commit is contained in:
committed by
GitHub
parent
6ffe579c7d
commit
6ca5780908
@ -1,16 +1,16 @@
|
||||
from typing import Any, Callable, Concatenate, Dict, List
|
||||
from typing import Any, Dict, List
|
||||
from uuid import UUID
|
||||
|
||||
from langchain.callbacks.base import AsyncCallbackHandler
|
||||
from langchain_core.agents import AgentAction, AgentFinish
|
||||
|
||||
from langflow.schema.log import LoggableType
|
||||
from langflow.schema.log import LogFunctionType
|
||||
|
||||
|
||||
class AgentAsyncHandler(AsyncCallbackHandler):
|
||||
"""Async callback handler that can be used to handle callbacks from langchain."""
|
||||
|
||||
def __init__(self, log_function: Callable[Concatenate[LoggableType | list[LoggableType], ...], None] | None = None):
|
||||
def __init__(self, log_function: LogFunctionType | None = None):
|
||||
self.log_function = log_function
|
||||
|
||||
async def on_tool_start(
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
from typing import Union
|
||||
from typing import Optional, Union
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import Protocol
|
||||
|
||||
LoggableType = Union[str, dict, list, int, float, bool, None, BaseModel]
|
||||
|
||||
|
||||
class LogFunctionType(Protocol):
|
||||
def __call__(self, message: Union[LoggableType, list[LoggableType]], *, name: Optional[str] = None) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user