patruff commited on
Commit
d33239b
·
verified ·
1 Parent(s): a8990cc

Upload tool

Browse files
Files changed (1) hide show
  1. tool.py +6 -16
tool.py CHANGED
@@ -1,16 +1,16 @@
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
@@ -20,19 +20,9 @@ class ParodyWordSuggestionTool(Tool):
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)
 
1
  from smolagents.tools import Tool
 
2
  import pronouncing
3
  import json
4
+ import string
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_str': {'type': 'string', 'description': 'Comma-separated list of words to check for similarity'}, '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: str, min_similarity: str = "0.7") -> str:
14
  """Get phonetically similar funny word suggestions."""
15
  import pronouncing
16
  import string
 
20
  min_similarity = float(min_similarity)
21
  suggestions = []
22
 
23
+ # Parse comma-separated word list
24
+ word = ""
25
+ words = [word.strip() for word in word_list_str.split(',')]
 
 
 
 
 
 
 
 
 
 
26
 
27
  # Get target pronunciation
28
  target_phones = pronouncing.phones_for_word(target)