Ajeya95 commited on
Commit
c12219a
·
verified ·
1 Parent(s): 903dca2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -7
app.py CHANGED
@@ -4,19 +4,54 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
8
  from Gradio_UI import GradioUI
9
 
 
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import json
8
  from Gradio_UI import GradioUI
9
 
10
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
+ duckduckgo_tool=DuckDuckGoSearchTool()
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+
15
+
16
+ def animewatcher(anime_name: str) -> str:
17
+ """A tool that searches for anime details using DuckDuckGo.
18
  Args:
19
+ anime_name: The name of the anime to search for.
20
+ Returns:
21
+ A formatted string with anime search results or an error message.
22
  """
23
+ try:
24
+ search_query = f"{anime_name} anime details"
25
+ results = duckduckgo_tool(search_query) # Fetch results from DuckDuckGo
26
+
27
+ # Debugging: Print what we receive
28
+ print(f"Debug: Raw DuckDuckGo results -> {results} (Type: {type(results)})")
29
+
30
+ # If results is a string, try parsing it as JSON (if possible)
31
+ if isinstance(results, str):
32
+ try:
33
+ results = json.loads(results) # Attempt JSON parsing
34
+ except json.JSONDecodeError:
35
+ return f"Error: Unexpected response format. Raw output: {results}"
36
+
37
+ # Ensure results is a list
38
+ if not isinstance(results, list) or not results:
39
+ return f"No results found for '{anime_name}'. Maybe it's underrated!"
40
+
41
+ # Limit results to the first 3 entries
42
+ results = results[:3]
43
+
44
+ # Format response
45
+ response = f"🔍 **Anime Search Results for '{anime_name}':**\n\n"
46
+ for i, result in enumerate(results, 1):
47
+ title = result.get('title', 'No title available')
48
+ href = result.get('href', 'No link available')
49
+ response += f"{i}. **{title}**\n🔗 {href}\n\n"
50
+
51
+ return response.strip()
52
+
53
+ except Exception as e:
54
+ return f"⚠️ Error searching for '{anime_name}': {str(e)}"
55
 
56
  @tool
57
  def get_current_time_in_timezone(timezone: str) -> str: