Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,6 +35,36 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
final_answer = FinalAnswerTool()
|
| 40 |
web_search = DuckDuckGoSearchTool()
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 37 |
|
| 38 |
+
@tool
|
| 39 |
+
def search_for_books(author: search_term: str) -> str:
|
| 40 |
+
"""A tool that searches for books by author keywords or words in the title of the book
|
| 41 |
+
Args:
|
| 42 |
+
search_term: A string representing a search terms. Can be part of the book title or the author's name.
|
| 43 |
+
"""
|
| 44 |
+
json_data = response.json() if response and response.status_code == 200 else None
|
| 45 |
+
try:
|
| 46 |
+
params = {"search": search_terms}
|
| 47 |
+
base_url = 'gutendex.com/books'
|
| 48 |
+
response = requests.get(base_url', params=params)
|
| 49 |
+
|
| 50 |
+
if response and response.status_code != 200:
|
| 51 |
+
return f"Error fetching book data for 'search term: {search_term}'"
|
| 52 |
+
|
| 53 |
+
results = []
|
| 54 |
+
json_data = response.json()
|
| 55 |
+
for book in json_data:
|
| 56 |
+
book_info = {
|
| 57 |
+
'title': book['title']
|
| 58 |
+
'authors': book['authors']
|
| 59 |
+
'subjects': book['subjects']
|
| 60 |
+
'summaries': book['summaries']
|
| 61 |
+
}
|
| 62 |
+
results.append(book_info)
|
| 63 |
+
return results
|
| 64 |
+
except Exception as e:
|
| 65 |
+
return f"There was an error with function search_for_books"
|
| 66 |
+
|
| 67 |
+
|
| 68 |
|
| 69 |
final_answer = FinalAnswerTool()
|
| 70 |
web_search = DuckDuckGoSearchTool()
|