yetessam commited on
Commit
4397750
·
verified ·
1 Parent(s): 1066fc5

Adding polite guard transformer

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, LiteLLMModel
 
2
  import datetime
3
  import requests
4
  import pytz
@@ -9,15 +10,25 @@ from tools.final_answer import FinalAnswerTool
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
12
  @tool
13
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
14
- #Keep this format for the description / args / args description but feel free to modify the tool
15
- """A tool that does nothing yet
16
  Args:
17
  arg1: the first argument
18
  arg2: the second argument
19
  """
20
- return "What magic will you build ?" + arg1 * arg2
 
 
 
 
 
 
 
 
 
21
 
22
  @tool
23
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -62,7 +73,7 @@ with open("prompts.yaml", 'r') as stream:
62
 
63
  agent = CodeAgent(
64
  model=model,
65
- tools=[final_answer, my_custom_tool, get_current_time_in_timezone ], ## add your tools here (don't remove final answer)
66
  max_steps=6,
67
  verbosity_level=1,
68
  grammar=None,
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, LiteLLMModel
2
+ from transformers import pipeline
3
  import datetime
4
  import requests
5
  import pytz
 
10
  from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
+
14
  @tool
15
+ def ask_polite_guard(input_text:str)-> str: specify the return type
16
+ """ A tool that classifies text into four categories: polite, somewhat polite, neutral and impolite
17
+
18
  Args:
19
  arg1: the first argument
20
  arg2: the second argument
21
  """
22
+
23
+ try:
24
+
25
+ if input_text:
26
+ classifier = pipeline("text-classification", "Intel/polite-guard")
27
+ text = "str"
28
+ return classifier(input_text)
29
+ catch:
30
+ return f"Error fetching classification for text '{input_text}': {str(e)}"
31
+
32
 
33
  @tool
34
  def get_current_time_in_timezone(timezone: str) -> str:
 
73
 
74
  agent = CodeAgent(
75
  model=model,
76
+ tools=[final_answer, ask_polite_guard, get_current_time_in_timezone ], ## add your tools here (don't remove final answer)
77
  max_steps=6,
78
  verbosity_level=1,
79
  grammar=None,