Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,20 +35,32 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
|
| 37 |
@tool
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
@tool
|
| 38 |
+
import random
|
| 39 |
+
from typing import List
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
@tool
|
| 43 |
+
def get_something_to_read(user_tip: str) -> str:
|
| 44 |
+
"""
|
| 45 |
+
该工具根据用户提示随机推荐书籍。
|
| 46 |
+
Args:
|
| 47 |
+
user_tip: 一个字符串,代表用户提供的书籍推荐偏好或关键词,例如'fiction'(小说)、'history'(历史)、'romance'(浪漫)等。
|
| 48 |
+
Returns:
|
| 49 |
+
一个字符串,代表随机推荐的书籍名称。
|
| 50 |
+
"""
|
| 51 |
+
fiction_books = ["To Kill a Mockingbird", "1984", "Pride and Prejudice"]
|
| 52 |
+
history_books = ["Sapiens: A Brief History of Humankind", "The Guns of August", "Guns, Germs, and Steel"]
|
| 53 |
+
romance_books = ["Jane Eyre", "Wuthering Heights", "Outlander"]
|
| 54 |
+
|
| 55 |
+
if "fiction" in user_tip.lower():
|
| 56 |
+
return random.choice(fiction_books)
|
| 57 |
+
elif "history" in user_tip.lower():
|
| 58 |
+
return random.choice(history_books)
|
| 59 |
+
elif "romance" in user_tip.lower():
|
| 60 |
+
return random.choice(romance_books)
|
| 61 |
+
else:
|
| 62 |
+
all_books: List[str] = fiction_books + history_books + romance_books
|
| 63 |
+
return random.choice(all_books)
|
| 64 |
|
| 65 |
|
| 66 |
|