mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-23 08:33:09 +00:00
feat: Add responses and safety impl with extra body
This commit is contained in:
parent
548ccff368
commit
e09401805f
15 changed files with 877 additions and 9 deletions
|
@ -247,12 +247,17 @@ class LlamaGuardShield:
|
|||
self.safety_categories = safety_categories
|
||||
|
||||
def check_unsafe_response(self, response: str) -> str | None:
|
||||
# Check for "unsafe\n<code>" format
|
||||
match = re.match(r"^unsafe\n(.*)$", response)
|
||||
if match:
|
||||
# extracts the unsafe code
|
||||
extracted = match.group(1)
|
||||
return extracted
|
||||
|
||||
# Check for direct category code format (e.g., "S1", "S2", etc.)
|
||||
if re.match(r"^S\d+$", response):
|
||||
return response
|
||||
|
||||
return None
|
||||
|
||||
def get_safety_categories(self) -> list[str]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue