Skip to content

Commit b568898

Browse files
committed
Adds a timeout argument to call_func.
1 parent 958f8fa commit b568898

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

mellea/stdlib/base.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from PIL import Image as PILImage
1818

1919
from mellea.helpers.fancy_logger import FancyLogger
20+
import multiprocessing.pool
2021

2122

2223
class CBlock:
@@ -653,6 +654,14 @@ class ModelToolCall:
653654
func: Callable
654655
args: Mapping[str, Any]
655656

656-
def call_func(self) -> Any:
657-
"""A helper function for calling the function/tool represented by this object."""
658-
return self.func(**self.args)
657+
def call_func(self, timeout: float | None=None) -> Any:
658+
"""A helper function for calling the function/tool represented by this object.
659+
660+
Args:
661+
timeout: if set, the tool call will time-out and an exception will be thrown after `timeout` seconds."""
662+
if timeout:
663+
with multiprocessing.pool.ThreadPool() as pool:
664+
result = pool.apply_async(self.func, kwds=self.args).get(timeout=timeout)
665+
return result
666+
else:
667+
return self.func(**self.args)

0 commit comments

Comments
 (0)