Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,73 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -35,6 +102,9 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -55,7 +125,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
|
| 22 |
+
@tool
|
| 23 |
+
def get_asoiaf_book(book_id: int) -> str:
|
| 24 |
+
"""Retrieves information about a book from 'A Song of Ice and Fire' series by ID.
|
| 25 |
+
Args:
|
| 26 |
+
book_id: The numeric ID of the book (1-12)
|
| 27 |
+
"""
|
| 28 |
+
try:
|
| 29 |
+
response = requests.get(f"https://anapioficeandfire.com/api/books/{book_id}")
|
| 30 |
+
if response.status_code == 200:
|
| 31 |
+
book = response.json()
|
| 32 |
+
return (
|
| 33 |
+
f"Book {book_id}: {book['name']}\n"
|
| 34 |
+
f"Authors: {', '.join(book['authors'])}\n"
|
| 35 |
+
f"Pages: {book['numberOfPages']}\n"
|
| 36 |
+
f"Characters: {len(book['characters'])}"
|
| 37 |
+
)
|
| 38 |
+
return f"Error: Book with ID {book_id} not found"
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"API Error: {str(e)}"
|
| 41 |
+
|
| 42 |
+
@tool
|
| 43 |
+
def get_asoiaf_character(name: str) -> str:
|
| 44 |
+
"""Searches for a character by name in the Game of Thrones universe.
|
| 45 |
+
Args:
|
| 46 |
+
name: The full name of the character (e.g., 'Jon Snow')
|
| 47 |
+
"""
|
| 48 |
+
try:
|
| 49 |
+
response = requests.get(
|
| 50 |
+
"https://anapioficeandfire.com/api/characters",
|
| 51 |
+
params={"name": name}
|
| 52 |
+
)
|
| 53 |
+
if response.status_code == 200:
|
| 54 |
+
characters = response.json()
|
| 55 |
+
if characters:
|
| 56 |
+
char = characters[0]
|
| 57 |
+
return (
|
| 58 |
+
f"Character: {char['name']}\n"
|
| 59 |
+
f"Aliases: {', '.join(char['aliases'])}\n"
|
| 60 |
+
f"Titles: {', '.join(char['titles'])}\n"
|
| 61 |
+
f"Played by: {char['playedBy'][0] if char['playedBy'] else 'Unknown'}"
|
| 62 |
+
)
|
| 63 |
+
return f"No character named '{name}' found"
|
| 64 |
+
return f"API Error: HTTP {response.status_code}"
|
| 65 |
+
except Exception as e:
|
| 66 |
+
return f"Search Error: {str(e)}"
|
| 67 |
+
|
| 68 |
+
@tool
|
| 69 |
+
def get_asoiaf_house(region: str) -> str:
|
| 70 |
+
"""Finds houses from a specific region in Westeros.
|
| 71 |
+
Args:
|
| 72 |
+
region: The region to search (e.g., 'The North', 'The Vale')
|
| 73 |
+
"""
|
| 74 |
+
try:
|
| 75 |
+
response = requests.get(
|
| 76 |
+
"https://anapioficeandfire.com/api/houses",
|
| 77 |
+
params={"region": region}
|
| 78 |
+
)
|
| 79 |
+
if response.status_code == 200:
|
| 80 |
+
houses = response.json()
|
| 81 |
+
if houses:
|
| 82 |
+
return f"Found {len(houses)} houses in {region}\nFirst result: {houses[0]['name']}"
|
| 83 |
+
return f"No houses found in {region}"
|
| 84 |
+
return f"API Error: HTTP {response.status_code}"
|
| 85 |
+
except Exception as e:
|
| 86 |
+
return f"Region Search Error: {str(e)}"
|
| 87 |
+
|
| 88 |
@tool
|
| 89 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 90 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
final_answer = FinalAnswerTool()
|
| 105 |
+
house = get_asoiaf_character()
|
| 106 |
+
book = get_asoiaf_book()
|
| 107 |
+
character = get_asoiaf_character()
|
| 108 |
|
| 109 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 110 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 125 |
|
| 126 |
agent = CodeAgent(
|
| 127 |
model=model,
|
| 128 |
+
tools=[final_answer, book, character, house], ## add your tools here (don't remove final answer)
|
| 129 |
max_steps=6,
|
| 130 |
verbosity_level=1,
|
| 131 |
grammar=None,
|