Yuthana commited on
Commit
5994087
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -9,14 +9,32 @@ 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:
 
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:
13
+ """A tool that searches for 3 PDF files related to the user's request using DuckDuckGoSearchTool.
14
+
15
  Args:
16
+ arg1: the first argument (string), interpreted as the search query.
17
+ arg2: the second argument (integer), potentially controlling how many results to fetch.
18
  """
19
+ # We'll use DuckDuckGoSearchRun from langchain to perform the actual search.
20
+ search = DuckDuckGoSearchRun()
21
+
22
+ # Construct the query, searching specifically for PDF documents.
23
+ query = f"{arg1} filetype:pdf"
24
+
25
+ # Use arg2 to limit the number of results to fetch (if you prefer, you can hardcode num_results=3).
26
+ num_results = min(arg2, 3) if arg2 > 0 else 3
27
+
28
+ # Execute the search
29
+ results = search.run(query, num_results=num_results)
30
+
31
+ # If results is a string describing the search outcome, just return it.
32
+ # If results is a list of links, you might parse them. For simplicity, we'll cast it to string and return.
33
+ if not results:
34
+ return "No PDF files found."
35
+
36
+ # Convert the results to a string for returning; you can format or parse further if desired.
37
+ return f"Top {num_results} PDF results for '{arg1}':\n\n{str(results)}"
38
 
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str: