-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
55 lines (48 loc) · 1.44 KB
/
tools.py
File metadata and controls
55 lines (48 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from agents import function_tool
import requests
from pydantic import BaseModel
import logging
# Set root logger to WARNING (suppresses most library logs)
logging.basicConfig(level=logging.WARNING)
# Configure your logger to INFO
logger = logging.getLogger("hateoas.tools")
logger.setLevel(logging.INFO)
class HttpResponse(BaseModel):
status_code: int
body: dict | list | None
@function_tool
def get_request(url: str) -> HttpResponse:
logger.info(f"GET: {url}")
response = requests.get(url)
return HttpResponse(
status_code=response.status_code,
body=response.json()
)
@function_tool(strict_mode=False)
def post_request(url: str, body: dict) -> HttpResponse:
logger.info(f"POST: {url}")
response = requests.post(url, json=body)
return HttpResponse(
status_code=response.status_code,
body=response.json()
)
@function_tool
def delete_request(url: str) -> HttpResponse:
logger.info(f"DELETE: {url}")
response = requests.delete(url)
try:
json_body = response.json()
except ValueError:
json_body = None
return HttpResponse(
status_code=response.status_code,
body=json_body
)
@function_tool(strict_mode=False)
def put_request(url: str, body: dict) -> HttpResponse:
logger.info(f"PUT: {url}")
response = requests.put(url, json=body)
return HttpResponse(
status_code=response.status_code,
body=response.json()
)