Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(callback): simplify import statements and type annotations for better readability #2793

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/backend/base/langflow/base/agents/callback.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
7 changes: 6 additions & 1 deletion src/backend/base/langflow/schema/log.py
Original file line number Diff line number Diff line change
@@ -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: ...
Loading