Hetfield08 commited on
Commit
a89dc41
·
verified ·
1 Parent(s): 64e6eab

nfl_tool Added

Browse files
Files changed (1) hide show
  1. app.py +33 -3
app.py CHANGED
@@ -3,7 +3,10 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
6
  from tools.final_answer import FinalAnswerTool
 
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -18,9 +21,36 @@ 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
- from datasets import load_dataset
 
22
 
23
- ds = load_dataset("nfliu/decontextualization")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  @tool
26
  def tool_calculator(num1: int, num2: int, operation: str) -> int:
@@ -90,7 +120,7 @@ with open("prompts.yaml", 'r') as stream:
90
 
91
  agent = CodeAgent(
92
  model=model,
93
- tools=[final_answer,tool_calculator], ## add your tools here (don't remove final answer)
94
  max_steps=6,
95
  verbosity_level=1,
96
  grammar=None,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+
7
  from tools.final_answer import FinalAnswerTool
8
+ from duckduckgo_search import DDGS
9
+
10
 
11
  from Gradio_UI import GradioUI
12
 
 
21
  """
22
  return "What magic will you build ?"
23
 
24
+ #from datasets import load_dataset
25
+ #ds = load_dataset("nfliu/decontextualization")
26
 
27
+ @tool
28
+ def nfl_tool(question: str ) -> str:
29
+
30
+ """
31
+ A tool to answer all questions about the NFL rules, tactics and players.
32
+
33
+ Args:
34
+ question: The user question to lookup the answer
35
+ """
36
+
37
+ # Prepare the duckduckgo query
38
+ query = f"{question}"
39
+ print(f"🔍 Searching DuckDuckGo with query: {query}") # Debug
40
+ with DDGS() as ddgs:
41
+ results = list(ddgs.text(query, max_results=5)) # Otteniamo i primi 5 risultati
42
+
43
+ print(f"📊 Found {len(results)} results") # Debug
44
+
45
+ if not results:
46
+ return ["❌ We haven't founded answers to this question."]
47
+
48
+ # SHow results
49
+ for r in results:
50
+ print(f"📌 {r['title']} - {r['href']}")
51
+
52
+ return [f"{r['title']} - {r['href']}" for r in results]
53
+
54
 
55
  @tool
56
  def tool_calculator(num1: int, num2: int, operation: str) -> int:
 
120
 
121
  agent = CodeAgent(
122
  model=model,
123
+ tools=[final_answer,tool_calculator,nfl_tool], ## add your tools here (don't remove final answer)
124
  max_steps=6,
125
  verbosity_level=1,
126
  grammar=None,