Skip to content

Commit 900424e

Browse files
committed
remove unwanted
1 parent 0b429da commit 900424e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

llama_stack/providers/inline/safety/code_scanner/code_scanner.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
import logging
88
import uuid
9-
from typing import Any
9+
from typing import TYPE_CHECKING, Any
1010

11-
from codeshield.cs import CodeShield, CodeShieldScanResult
11+
if TYPE_CHECKING:
12+
from codeshield.cs import CodeShieldScanResult
1213

1314
from llama_stack.apis.inference import Message
1415
from llama_stack.apis.safety import (
@@ -59,6 +60,8 @@ async def run_shield(
5960
if not shield:
6061
raise ValueError(f"Shield {shield_id} not found")
6162

63+
from codeshield.cs import CodeShield
64+
6265
text = "\n".join([interleaved_content_as_str(m.content) for m in messages])
6366
log.info(f"Running CodeScannerShield on {text[50:]}")
6467
result = await CodeShield.scan_code(text)
@@ -72,7 +75,7 @@ async def run_shield(
7275
)
7376
return RunShieldResponse(violation=violation)
7477

75-
def get_moderation_object_results(self, scan_result: CodeShieldScanResult) -> ModerationObjectResults:
78+
def get_moderation_object_results(self, scan_result: "CodeShieldScanResult") -> ModerationObjectResults:
7679
categories = {}
7780
category_scores = {}
7881
category_applied_input_types = {}
@@ -102,6 +105,8 @@ async def run_moderation(self, input: str | list[str], model: str) -> Moderation
102105
inputs = input if isinstance(input, list) else [input]
103106
results = []
104107

108+
from codeshield.cs import CodeShield
109+
105110
for text_input in inputs:
106111
log.info(f"Running CodeScannerShield moderation on input: {text_input[:100]}...")
107112
scan_result = await CodeShield.scan_code(text_input)

llama_stack/providers/inline/safety/llama_guard/llama_guard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def create_moderation_object(self, model: str, unsafe_code: str | None = None) -
455455

456456
def is_content_safe(self, response: str, unsafe_code: str | None = None) -> bool:
457457
"""Check if content is safe based on response and unsafe code."""
458-
if response.strip() == SAFE_RESPONSE:
458+
if response.strip().lower().startswith(SAFE_RESPONSE):
459459
return True
460460

461461
if unsafe_code:

0 commit comments

Comments
 (0)