Spaces:
Sleeping
Sleeping
Update tools/polite_guard.py
Browse files- tools/polite_guard.py +3 -6
tools/polite_guard.py
CHANGED
|
@@ -14,7 +14,7 @@ class PoliteGuardTool(Tool):
|
|
| 14 |
output_type = "any"
|
| 15 |
|
| 16 |
def forward(self, input_text: Any) -> Any:
|
| 17 |
-
self.label
|
| 18 |
return self.label
|
| 19 |
|
| 20 |
def __init__(self, *args, **kwargs):
|
|
@@ -23,7 +23,7 @@ class PoliteGuardTool(Tool):
|
|
| 23 |
self.score = None
|
| 24 |
|
| 25 |
#@tool
|
| 26 |
-
def ask_polite_guard(self, input_text: str) ->
|
| 27 |
"""
|
| 28 |
|
| 29 |
Args:
|
|
@@ -35,10 +35,7 @@ class PoliteGuardTool(Tool):
|
|
| 35 |
try:
|
| 36 |
classifier = pipeline("text-classification", "Intel/polite-guard")
|
| 37 |
|
| 38 |
-
return
|
| 39 |
-
"label": classifier['label'],
|
| 40 |
-
"score": classifier['score']
|
| 41 |
-
}
|
| 42 |
|
| 43 |
except Exception as e:
|
| 44 |
return f"Error fetching classification for text '{input_text}': {str(e)}"
|
|
|
|
| 14 |
output_type = "any"
|
| 15 |
|
| 16 |
def forward(self, input_text: Any) -> Any:
|
| 17 |
+
self.label = self.ask_polite_guard(input_text)
|
| 18 |
return self.label
|
| 19 |
|
| 20 |
def __init__(self, *args, **kwargs):
|
|
|
|
| 23 |
self.score = None
|
| 24 |
|
| 25 |
#@tool
|
| 26 |
+
def ask_polite_guard(self, input_text: str) -> str:
|
| 27 |
"""
|
| 28 |
|
| 29 |
Args:
|
|
|
|
| 35 |
try:
|
| 36 |
classifier = pipeline("text-classification", "Intel/polite-guard")
|
| 37 |
|
| 38 |
+
return classifier['label']
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
return f"Error fetching classification for text '{input_text}': {str(e)}"
|