kikocis/llama-stack public
Changesets · Branches · Tags · Compare
| Changeset | 7bf84b9a642df18653214cd669a83fc27dae09c8bfa8194638c07991bec9a40b |
|---|---|
| Author | Ashwin Bharambe <ashwin.bharambe@gmail.com> · 2024-09-17 21:27 -07:00 |
| Committer | Ashwin Bharambe <ashwin.bharambe@gmail.com> · 2024-09-17 21:27 -07:00 |
| Parents | 182309f5cec0 |
2 files changed
modified llama_stack/providers/impls/meta_reference/safety/shields/code_scanner.py +2 −1
| @@ -4,7 +4,6 @@ | ||
| 4 | 4 | # This source code is licensed under the terms described in the LICENSE file in |
| 5 | 5 | # the root directory of this source tree. |
| 6 | 6 | |
| 7 | -from codeshield.cs import CodeShield | |
| 8 | 7 | from termcolor import cprint |
| 9 | 8 | |
| 10 | 9 | from .base import ShieldResponse, TextShield |
| @@ -16,6 +15,8 @@ | ||
| 16 | 15 | return BuiltinShield.code_scanner_guard |
| 17 | 16 | |
| 18 | 17 | async def run_impl(self, text: str) -> ShieldResponse: |
| 18 | + from codeshield.cs import CodeShield | |
| 19 | + | |
| 19 | 20 | cprint(f"Running CodeScannerShield on {text[50:]}", color="magenta") |
| 20 | 21 | result = await CodeShield.scan_code(text) |
| 21 | 22 | if result.is_insecure: |
modified llama_stack/providers/impls/meta_reference/safety/shields/prompt_guard.py +2 −1
| @@ -11,7 +11,6 @@ | ||
| 11 | 11 | |
| 12 | 12 | from llama_models.llama3.api.datatypes import Message |
| 13 | 13 | from termcolor import cprint |
| 14 | -from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| 15 | 14 | |
| 16 | 15 | from .base import message_content_as_str, OnViolationAction, ShieldResponse, TextShield |
| 17 | 16 | from llama_stack.apis.safety import * # noqa: F403 |
| @@ -61,6 +60,8 @@ | ||
| 61 | 60 | raise ValueError("Temperature must be greater than 0") |
| 62 | 61 | self.device = "cuda" |
| 63 | 62 | if PromptGuardShield._model_cache is None: |
| 63 | + from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| 64 | + | |
| 64 | 65 | # load model and tokenizer |
| 65 | 66 | tokenizer = AutoTokenizer.from_pretrained(model_dir) |
| 66 | 67 | model = AutoModelForSequenceClassification.from_pretrained( |