Tools
Defining custom tools
# Sync tool
def get_current_time(timezone: Annotated[str, "The timezone to get the current time in. e-g Europe/Paris"]) -> str:
"""Return the current time in the given timezone in iso format"""
return datetime.now(ZoneInfo(timezone)).isoformat()
# Tools can also be async
async def get_latest_pip_version(package_name: Annotated[str, "The name of the pip package to check"]) -> str:
"""Fetch the latest version of a pip package from PyPI"""
url = f"https://pypi.org/pypi/{package_name}/json"
async with httpx.AsyncClient() as client:
response = await client.get(url)
response.raise_for_status()
data = response.json()
return data['info']['version']Hosted tools
Last updated