support async

This commit is contained in:
2025-12-29 21:59:11 +08:00
parent 53ecbebb0a
commit ab5dda1f21
8 changed files with 429 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
from typing import List, Callable, Tuple, Dict
from typing import List, Callable, Tuple, Dict, AsyncIterator
from abc import ABC, abstractmethod
from PIL import Image
from io import BytesIO
@@ -26,6 +26,10 @@ class GraphBase(ABC):
def invoke(self, *nargs, **kwargs):
pass
async def ainvoke(self, *nargs, **kwargs):
"""Async version of invoke. Subclasses should override for true async support."""
raise NotImplementedError("Subclass should implement ainvoke for async support")
def show_graph(self, ret_img:bool=False):
#NOTE: just a useful tool for debugging; has zero useful functionality
@@ -59,4 +63,8 @@ class ToolNodeBase(GraphBase):
@abstractmethod
def invoke(self, inp)->Dict[str, List[BaseMessage]]:
pass
pass
async def ainvoke(self, inp)->Dict[str, List[BaseMessage]]:
"""Async version of invoke. Subclasses should override for true async support."""
raise NotImplementedError("Subclass should implement ainvoke for async support")