devsu commited on
Commit
dc0b2ec
·
verified ·
1 Parent(s): 5639173

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -1
app.py CHANGED
@@ -7,6 +7,13 @@ 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
@@ -18,6 +25,39 @@ 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.
@@ -55,7 +95,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,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ from typing import Union, List
11
+ from collections import defaultdict
12
+
13
+ # Carica il dizionario italiano una volta sola
14
+ with open("280000_parole_italiane.txt", "r", encoding="utf-8") as f:
15
+ italian_dict = set(word.strip().lower() for word in f if word.strip().isalpha())
16
+
17
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
18
  @tool
19
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
25
  """
26
  return "What magic will you build ?"
27
 
28
+ @tool
29
+ def find_anagrams_in_italian(words: Union[str, List[str]]) -> str:
30
+ """
31
+ Trova gli anagrammi italiani validi per ciascuna parola in input.
32
+
33
+ Args:
34
+ words: una parola singola o una lista di parole
35
+
36
+ Returns:
37
+ Una stringa che descrive per ciascuna parola i suoi anagrammi validi in italiano.
38
+ """
39
+ if isinstance(words, str):
40
+ words = [words]
41
+
42
+ results = []
43
+
44
+ for word in words:
45
+ word_clean = word.lower()
46
+ if word_clean not in italian_dict:
47
+ results.append(f"'{word}': non è presente nel dizionario italiano.")
48
+ continue
49
+
50
+ # Trova tutti gli anagrammi possibili della parola
51
+ key = ''.join(sorted(word_clean))
52
+ anagrams = [w for w in italian_dict if ''.join(sorted(w)) == key and w != word_clean]
53
+
54
+ if anagrams:
55
+ results.append(f"'{word}': anagrammi trovati -> {', '.join(sorted(anagrams))}")
56
+ else:
57
+ results.append(f"'{word}': nessun anagramma trovato nel dizionario italiano.")
58
+
59
+ return '\n'.join(results)
60
+
61
  @tool
62
  def get_current_time_in_timezone(timezone: str) -> str:
63
  """A tool that fetches the current local time in a specified timezone.
 
95
 
96
  agent = CodeAgent(
97
  model=model,
98
+ tools=[final_answer, find_anagrams_in_italian], ## add your tools here (don't remove final answer)
99
  max_steps=6,
100
  verbosity_level=1,
101
  grammar=None,