Skip to content

Commit

Permalink
woohoo
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdai committed Jun 19, 2024
1 parent 47b218b commit c6b361d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions agentfile/tools/meta_service_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ async def from_tool_service(
tool_service_api_key: Optional[str] = None,
tool_service_name: Optional[str] = None,
publish_callback: Optional[PublishCallback] = None,
timeout: float = 10.0,
step_interval: float = 0.1,
) -> "MetaServiceTool":
if tool_service is not None:
res = await tool_service.get_tool_by_name(name)
Expand All @@ -82,6 +84,8 @@ async def from_tool_service(
message_queue=message_queue,
tool_service_name=tool_service.service_name,
publish_callback=publish_callback,
timeout=timeout,
step_interval=step_interval,
)
# TODO by requests
# make a http request, try to parse into BaseTool
Expand Down
25 changes: 25 additions & 0 deletions tests/test_meta_service_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,28 @@ async def test_tool_call_output(
assert tool_output.content == "9"
assert tool_output.tool_name == "multiply"
assert tool_output.raw_input == {"args": (), "kwargs": {"a": 1, "b": 9}}
assert len(meta_service_tool.tool_call_results) == 0


@pytest.mark.asyncio()
async def test_tool_call_timeout(
message_queue: SimpleMessageQueue, tool_service: ToolService
) -> None:
# arrange
meta_service_tool: MetaServiceTool = await MetaServiceTool.from_tool_service(
tool_service=tool_service,
message_queue=message_queue,
name="multiply",
timeout=1e-4,
)
await message_queue.register_consumer(meta_service_tool.as_consumer())
await message_queue.register_consumer(tool_service.as_consumer())
mq_task = asyncio.create_task(message_queue.start())
ts_task = asyncio.create_task(tool_service.processing_loop())

# act/assert
with pytest.raises(asyncio.exceptions.TimeoutError):
await meta_service_tool.acall(a=1, b=9)

mq_task.cancel()
ts_task.cancel()

0 comments on commit c6b361d

Please sign in to comment.