mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-24 06:54:57 +08:00
test/tools: cover workspace, file, run_command and PTY
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from plyngent.agent import ToolDefinition
|
||||
|
||||
|
||||
def call_sync(definition: ToolDefinition, *args: object, **kwargs: object) -> str:
|
||||
result: Any = definition.handler(*args, **kwargs)
|
||||
assert not inspect.isawaitable(result)
|
||||
return cast("str", result)
|
||||
|
||||
|
||||
async def call_async(definition: ToolDefinition, *args: object, **kwargs: object) -> str:
|
||||
result: Any = definition.handler(*args, **kwargs)
|
||||
if inspect.isawaitable(result):
|
||||
result = await result
|
||||
return cast("str", result)
|
||||
Reference in New Issue
Block a user