Update tools/book_tool.py
Browse files- tools/book_tool.py +5 -5
tools/book_tool.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
from typing import List, Dict
|
2 |
import requests
|
3 |
-
from smolagents import Tool
|
4 |
|
5 |
class BookSearchTool(Tool):
|
6 |
name = "search_books"
|
7 |
description = "Search for books using the Open Library API"
|
8 |
-
|
9 |
output_type = List[Dict]
|
10 |
|
11 |
-
def
|
12 |
try:
|
13 |
url = f"https://openlibrary.org/search.json?q={query}&limit=5"
|
14 |
response = requests.get(url)
|
@@ -32,10 +32,10 @@ class BookSearchTool(Tool):
|
|
32 |
class BookDetailsTool(Tool):
|
33 |
name = "get_book_details"
|
34 |
description = "Get detailed information about a specific book from Open Library"
|
35 |
-
|
36 |
output_type = Dict
|
37 |
|
38 |
-
def
|
39 |
try:
|
40 |
url = f"https://openlibrary.org{book_key}.json"
|
41 |
response = requests.get(url)
|
|
|
1 |
from typing import List, Dict
|
2 |
import requests
|
3 |
+
from smolagents.tools import Tool
|
4 |
|
5 |
class BookSearchTool(Tool):
|
6 |
name = "search_books"
|
7 |
description = "Search for books using the Open Library API"
|
8 |
+
inputs = {'query': {'type': 'string', 'description': 'The search query to find books.'}}
|
9 |
output_type = List[Dict]
|
10 |
|
11 |
+
def forward(self, query: str) -> List[Dict]:
|
12 |
try:
|
13 |
url = f"https://openlibrary.org/search.json?q={query}&limit=5"
|
14 |
response = requests.get(url)
|
|
|
32 |
class BookDetailsTool(Tool):
|
33 |
name = "get_book_details"
|
34 |
description = "Get detailed information about a specific book from Open Library"
|
35 |
+
inputs = {'book_key': {'type': 'string', 'description': 'The Open Library key for the book.'}}
|
36 |
output_type = Dict
|
37 |
|
38 |
+
def forward(self, book_key: str) -> Dict:
|
39 |
try:
|
40 |
url = f"https://openlibrary.org{book_key}.json"
|
41 |
response = requests.get(url)
|