Spaces:
Runtime error
Runtime error
Modified the input screener to be simple profanity check.
Browse files- requirements.txt +1 -0
- src/architectures.py +4 -8
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
pandas==2.1.1
|
2 |
plotly==5.17.0
|
3 |
chromadb==0.4.15
|
|
|
|
1 |
pandas==2.1.1
|
2 |
plotly==5.17.0
|
3 |
chromadb==0.4.15
|
4 |
+
|
src/architectures.py
CHANGED
@@ -12,6 +12,7 @@ from abc import ABC, abstractmethod
|
|
12 |
from enum import Enum
|
13 |
from time import time
|
14 |
from typing import List
|
|
|
15 |
|
16 |
from src.common import config_dir, data_dir, hf_api_token
|
17 |
from src.models import HFLlamaChatModel
|
@@ -258,18 +259,13 @@ class Architecture:
|
|
258 |
|
259 |
|
260 |
class InputRequestScreener(ArchitectureComponent):
|
261 |
-
description = "
|
262 |
|
263 |
def process_request(self, request: ArchitectureRequest) -> None:
|
264 |
-
|
265 |
-
llm = HFLlamaChatModel.for_model('meta-llama/Llama-2-7b-chat-hf')
|
266 |
-
if llm is None:
|
267 |
-
raise ValueError(f'Screener model "meta-llama/Llama-2-7b-chat-hf" not set up')
|
268 |
-
response = llm(request.request, system_prompt=system_prompt)
|
269 |
-
if response[0:2].lower() != 'no': # Lean cautious even if the model fails to return yes/no
|
270 |
request.response = "Sorry - I cannot answer this question. Please try and rephrase it."
|
271 |
request.early_exit = True
|
272 |
-
request.early_exit_message =
|
273 |
|
274 |
|
275 |
class OutputResponseScreener(ArchitectureComponent):
|
|
|
12 |
from enum import Enum
|
13 |
from time import time
|
14 |
from typing import List
|
15 |
+
from better_profanity import profanity
|
16 |
|
17 |
from src.common import config_dir, data_dir, hf_api_token
|
18 |
from src.models import HFLlamaChatModel
|
|
|
259 |
|
260 |
|
261 |
class InputRequestScreener(ArchitectureComponent):
|
262 |
+
description = "Simplistic input screener for demonstration. Screens inputs for profanity."
|
263 |
|
264 |
def process_request(self, request: ArchitectureRequest) -> None:
|
265 |
+
if profanity.contains_profanity(request.request):
|
|
|
|
|
|
|
|
|
|
|
266 |
request.response = "Sorry - I cannot answer this question. Please try and rephrase it."
|
267 |
request.early_exit = True
|
268 |
+
request.early_exit_message = "Profanity detected in request"
|
269 |
|
270 |
|
271 |
class OutputResponseScreener(ArchitectureComponent):
|