File size: 636 Bytes
65464fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# app/tools/http.py
import httpx, asyncio
from .base import Tool, ToolSpec

class HttpGet(Tool):
    spec = ToolSpec(
        name="http_get",
        description="Fetch JSON/HTML from a URL.",
        schema={
          "type":"object","properties":{"url":{"type":"string","format":"uri"}}, "required":["url"]
        }
    )

    async def run(self, url:str) -> dict:
        async with httpx.AsyncClient(timeout=10) as s:
            r = await s.get(url)
            r.raise_for_status()
            ctype = r.headers.get("content-type","")
            return {"status": r.status_code, "content_type": ctype, "text": r.text[:200000]}