patruff commited on
Commit
c0a5ec1
·
verified ·
1 Parent(s): 235a36b

Upload tool

Browse files
Files changed (1) hide show
  1. tool.py +26 -24
tool.py CHANGED
@@ -1,41 +1,39 @@
1
  from smolagents.tools import Tool
2
- import json
3
  import pronouncing
 
4
 
5
  class ParodyWordSuggestionTool(Tool):
6
  name = "parody_word_suggester"
7
  description = """Suggests phonetically similar funny words using CMU dictionary pronunciations.
8
  Returns similar words from a curated list of funny words, along with their similarity scores."""
9
- inputs = {'target': {'type': 'string', 'description': 'The word you want to find funny alternatives for'}, 'min_similarity': {'type': 'string', 'description': 'Minimum similarity threshold (0.0-1.0)', 'nullable': True}}
10
  output_type = "string"
11
 
12
- def __init__(self):
13
- # Initialize with funny word list
14
- self.funny_words = [
15
- # Original words
16
- "poop", "loop", "soup", "boop", "dupe", "goop",
17
- "scoop", "whoop", "droop", "snoop", "coop",
18
- "fart", "toot", "burp", "squish", "squash",
19
- "wiggle", "jiggle", "wobble", "nincompoop", "dingleberry",
20
- # Additional middle school humor words
21
- "stinky", "booboo", "smelly", "goo", "turd", "pee", "peepee",
22
- "potty", "butt", "tooty", "booger", "snot", "doody", "doodoo",
23
- "weewee", "wedgie", "undies", "fartface", "poopyhead",
24
- "butthead", "stinkbomb", "stinkface", "dork", "nerd",
25
- "goober", "doofus", "dingus", "yahoo", "weirdo",
26
- "stinkypants", "bubblebutt", "zonked", "zoop", "zoinks"
27
- ]
28
-
29
-
30
- def forward(self, target: str, min_similarity: str = "0.7") -> str:
31
  """Get phonetically similar funny word suggestions."""
32
  import pronouncing
 
33
  import json
34
 
35
- target = target.lower().strip()
36
  min_similarity = float(min_similarity)
37
  suggestions = []
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  # Get target pronunciation
40
  target_phones = pronouncing.phones_for_word(target)
41
  if not target_phones:
@@ -46,8 +44,8 @@ class ParodyWordSuggestionTool(Tool):
46
 
47
  target_phones = target_phones[0].split()
48
 
49
- # Check each funny word
50
- for word in self.funny_words:
51
  phones = pronouncing.phones_for_word(word)
52
  if phones: # Only process if word is in dictionary
53
  phones = phones[0].split()
@@ -75,3 +73,7 @@ class ParodyWordSuggestionTool(Tool):
75
 
76
  return json.dumps(result, indent=2)
77
 
 
 
 
 
 
1
  from smolagents.tools import Tool
2
+ import string
3
  import pronouncing
4
+ import json
5
 
6
  class ParodyWordSuggestionTool(Tool):
7
  name = "parody_word_suggester"
8
  description = """Suggests phonetically similar funny words using CMU dictionary pronunciations.
9
  Returns similar words from a curated list of funny words, along with their similarity scores."""
10
+ inputs = {'target': {'type': 'string', 'description': 'The word you want to find funny alternatives for'}, 'word_list': {'type': 'string', 'description': 'JSON string of words list, e.g. \'["word1", "word2"]\''}, 'min_similarity': {'type': 'string', 'description': 'Minimum similarity threshold (0.0-1.0)', 'nullable': True}}
11
  output_type = "string"
12
 
13
+ def forward(self, target: str, word_list: str, min_similarity: str = "0.7") -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  """Get phonetically similar funny word suggestions."""
15
  import pronouncing
16
+ import string
17
  import json
18
 
19
+ target = target.lower().strip(string.punctuation)
20
  min_similarity = float(min_similarity)
21
  suggestions = []
22
 
23
+ # Parse word list from JSON string
24
+ try:
25
+ words = json.loads(word_list)
26
+ if not isinstance(words, list):
27
+ return json.dumps({
28
+ "error": "word_list must be a JSON string representing a list of words",
29
+ "suggestions": []
30
+ }, indent=2)
31
+ except json.JSONDecodeError:
32
+ return json.dumps({
33
+ "error": "Invalid JSON string for word_list",
34
+ "suggestions": []
35
+ }, indent=2)
36
+
37
  # Get target pronunciation
38
  target_phones = pronouncing.phones_for_word(target)
39
  if not target_phones:
 
44
 
45
  target_phones = target_phones[0].split()
46
 
47
+ # Check each word
48
+ for word in words:
49
  phones = pronouncing.phones_for_word(word)
50
  if phones: # Only process if word is in dictionary
51
  phones = phones[0].split()
 
73
 
74
  return json.dumps(result, indent=2)
75
 
76
+
77
+ def __init__(self, *args, **kwargs):
78
+ self.is_initialized = False
79
+