Files
2026-matrix-ollama-gateway/tools/builtin.py
Nikita Tyukalov, ASUS, Linux 2bc979c9b4 Initial commit
2026-07-19 22:02:06 +03:00

26 lines
754 B
Python

"""
This module implements some builtin tools.
"""
import asyncio
import sys
from typing import Literal
async def builtin_network_ping(host: str) -> str:
"""Ping `host` to check if it is reachable."""
try:
param = '-n' if sys.platform.lower() == 'windows' else '-c'
cmd = ['ping', param, '1', host]
process = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
if process.returncode == 0:
return f"{host} is reachable"
else:
return f"{host} is unreachable"
except Exception as e:
return f"Exception happened: {e}"