forked from mattambrogi/agent-implementation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
63 lines (57 loc) · 1.59 KB
/
tools.py
File metadata and controls
63 lines (57 loc) · 1.59 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
56
57
58
59
60
61
62
63
import httpx
def wikipedia(q):
"""
wikipedia:
e.g. wikipedia: Django
Returns a summary from searching Wikipedia
"""
return httpx.get("https://en.wikipedia.org/w/api.php", params={
"action": "query",
"list": "search",
"srsearch": q,
"format": "json"
}).json()["query"]["search"][0]["snippet"]
def simon_blog_search(q):
"""
simon_blog_search:
e.g. simon_blog_search: Django
Search Simon's blog for that term
"""
results = httpx.get("https://datasette.simonwillison.net/simonwillisonblog.json", params={
"sql": """
select
blog_entry.title || ': ' || substr(html_strip_tags(blog_entry.body), 0, 1000) as text,
blog_entry.created
from
blog_entry join blog_entry_fts on blog_entry.rowid = blog_entry_fts.rowid
where
blog_entry_fts match escape_fts(:q)
order by
blog_entry_fts.rank
limit
1""".strip(),
"_shape": "array",
"q": q,
}).json()
return results[0]["text"]
def calculate(what):
"""
calculate:
e.g. calculate: 4 * 7 / 3
Runs a calculation and returns the number - uses Python so be sure to use floating point syntax if necessary
"""
return eval(what)
def fetch_last_todo(input=None):
"""
fetch_last_todo:
e.g. fetch_last_todo: none
Returns the last todo item from the fetched todos list. No input required.
"""
url = "https://jsonplaceholder.typicode.com/todos/1"
response = httpx.get(url)
if response.status_code == 200:
print(response.json())
return response.json()
else:
print('failed')
return "Failed to fetch data"