Elffuss BraidHub

kikocis/llama-stack public

make shield imports more lazy
Changeset7bf84b9a642df18653214cd669a83fc27dae09c8bfa8194638c07991bec9a40b
AuthorAshwin Bharambe <ashwin.bharambe@gmail.com> · 2024-09-17 21:27 -07:00
CommitterAshwin Bharambe <ashwin.bharambe@gmail.com> · 2024-09-17 21:27 -07:00
Parents182309f5cec0

Browse the files at this changeset

2 files changed

modified llama_stack/providers/impls/meta_reference/safety/shields/code_scanner.py +2 −1
@@ -4,7 +4,6 @@
44 # This source code is licensed under the terms described in the LICENSE file in
55 # the root directory of this source tree.
66
7-from codeshield.cs import CodeShield
87 from termcolor import cprint
98
109 from .base import ShieldResponse, TextShield
@@ -16,6 +15,8 @@
1615 return BuiltinShield.code_scanner_guard
1716
1817 async def run_impl(self, text: str) -> ShieldResponse:
18+ from codeshield.cs import CodeShield
19+
1920 cprint(f"Running CodeScannerShield on {text[50:]}", color="magenta")
2021 result = await CodeShield.scan_code(text)
2122 if result.is_insecure:
modified llama_stack/providers/impls/meta_reference/safety/shields/prompt_guard.py +2 −1
@@ -11,7 +11,6 @@
1111
1212 from llama_models.llama3.api.datatypes import Message
1313 from termcolor import cprint
14-from transformers import AutoModelForSequenceClassification, AutoTokenizer
1514
1615 from .base import message_content_as_str, OnViolationAction, ShieldResponse, TextShield
1716 from llama_stack.apis.safety import * # noqa: F403
@@ -61,6 +60,8 @@
6160 raise ValueError("Temperature must be greater than 0")
6261 self.device = "cuda"
6362 if PromptGuardShield._model_cache is None:
63+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
64+
6465 # load model and tokenizer
6566 tokenizer = AutoTokenizer.from_pretrained(model_dir)
6667 model = AutoModelForSequenceClassification.from_pretrained(