Update handler.py
Browse files- handler.py +13 -13
handler.py
CHANGED
|
@@ -270,23 +270,23 @@ class EndpointHandler:
|
|
| 270 |
decoded_output = self.tokenizer.decode(output[0], skip_special_tokens=True)
|
| 271 |
|
| 272 |
# Extract the generated part (after the prompt)
|
| 273 |
-
response_text = decoded_output[len(prompt):].strip()
|
| 274 |
-
print(response_text)
|
| 275 |
|
| 276 |
-
# Parse the response to extract safety assessment
|
| 277 |
-
safety_result = self.extract_and_parse_json(response_text)
|
| 278 |
|
| 279 |
-
# Determine if the input is safe or not
|
| 280 |
-
is_safe = safety_result.get("Prompt Safety", "").lower() == "safe" and \
|
| 281 |
-
|
| 282 |
|
| 283 |
-
# Prepare the final response
|
| 284 |
-
response = {
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
}
|
| 288 |
|
| 289 |
-
return
|
| 290 |
|
| 291 |
# For local testing
|
| 292 |
if __name__ == "__main__":
|
|
|
|
| 270 |
decoded_output = self.tokenizer.decode(output[0], skip_special_tokens=True)
|
| 271 |
|
| 272 |
# Extract the generated part (after the prompt)
|
| 273 |
+
# response_text = decoded_output[len(prompt):].strip()
|
| 274 |
+
# print(response_text)
|
| 275 |
|
| 276 |
+
# # Parse the response to extract safety assessment
|
| 277 |
+
# safety_result = self.extract_and_parse_json(response_text)
|
| 278 |
|
| 279 |
+
# # Determine if the input is safe or not
|
| 280 |
+
# is_safe = safety_result.get("Prompt Safety", "").lower() == "safe" and \
|
| 281 |
+
# safety_result.get("Response Safety", "").lower() == "safe"
|
| 282 |
|
| 283 |
+
# # Prepare the final response
|
| 284 |
+
# response = {
|
| 285 |
+
# "is_safe": is_safe,
|
| 286 |
+
# "safety_result": safety_result
|
| 287 |
+
# }
|
| 288 |
|
| 289 |
+
return decoded_output
|
| 290 |
|
| 291 |
# For local testing
|
| 292 |
if __name__ == "__main__":
|