Skip to content

Commit

Permalink
feat: content filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Apr 17, 2024
1 parent b87c2f5 commit 5681069
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/routes/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ async def make_stream():

@run_router.put(f"{env.base}/single/{{template}}")
async def step_run(data: ChainInput, node: Node = Depends(get_node)):
for msg in data.messages:
for string in env.banned_substrings:
if string in msg.content:
return PlainTextResponse(env.banned_response)

async def make_stream():
last = ""
async for c in node.astream(data.context, find_llm(data.model).generate, **data.config):
Expand Down
3 changes: 3 additions & 0 deletions src/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class Config(BaseSettings):

base_path: str = ""

banned_substrings: list[str] = []
banned_response: str = "Sorry, I can't help with that."

@property
def base(self):
return f"/{self.base_path}" if self.base_path else ""
Expand Down

0 comments on commit 5681069

Please sign in to comment.