innafomina commited on
Commit
932c307
·
verified ·
1 Parent(s): 9feb97d

Update app.py

Browse files

joke generator tool

Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -1,4 +1,6 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
 
 
2
  import datetime
3
  import requests
4
  import pytz
@@ -18,6 +20,26 @@ def get_domain_name(email:str)-> str: #it's import to specify the return type
18
  domain = email.split('@')[1]
19
  return domain
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.
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
+ from datasets import load_dataset
3
+ import random
4
  import datetime
5
  import requests
6
  import pytz
 
20
  domain = email.split('@')[1]
21
  return domain
22
 
23
+ @tool
24
+ def generate_jokes(joke_type:str)-> str: #it's import to specify the return type
25
+ #Keep this format for the description / args / args description but feel free to modify the tool
26
+ """A tool that retrieves a joke of specified type. Two types are accepted 'dad jokes' and regular jokes
27
+ Args:
28
+ joke_type: a string that specifies the type of joke to retrieve. Accepted arguments 'dad' or 'regular'
29
+ """
30
+ if joke_type == 'dad':
31
+ path = 'gnumanth/dad-jokes'
32
+ col = 'joke'
33
+ else:
34
+ path = 'Amirkid/jokes'
35
+ col = 'text'
36
+ dataset = load_dataset(path, split = "train")[col]
37
+ # shuffle to make sure examples will be random
38
+ dataset = dataset.shuffle()
39
+ random_example = dataset[[col]][0]
40
+
41
+ return random_example
42
+
43
  @tool
44
  def get_current_time_in_timezone(timezone: str) -> str:
45
  """A tool that fetches the current local time in a specified timezone.