Spaces:
Sleeping
Sleeping
Adding polite guard transformer
Browse files
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
|
| 14 |
-
|
| 15 |
-
|
| 16 |
Args:
|
| 17 |
arg1: the first argument
|
| 18 |
arg2: the second argument
|
| 19 |
"""
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|
| 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,
|