Elffuss BraidHub

kikocis/llama-stack public

ef5ef25e9193 · 1.8 KiBRawPermalink
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the terms described in the LICENSE file in
5# the root directory of this source tree.
6
7from enum import Enum
8from typing import List, Optional
9
10from llama_models.sku_list import CoreModelId, safety_models
11
12from pydantic import BaseModel, validator
13
14
15class MetaReferenceShieldType(Enum):
16 llama_guard = "llama_guard"
17 code_scanner_guard = "code_scanner_guard"
18 injection_shield = "injection_shield"
19 jailbreak_shield = "jailbreak_shield"
20
21
22class LlamaGuardShieldConfig(BaseModel):
23 model: str = "Llama-Guard-3-8B"
24 excluded_categories: List[str] = []
25 disable_input_check: bool = False
26 disable_output_check: bool = False
27
28 @validator("model")
29 @classmethod
30 def validate_model(cls, model: str) -> str:
31 permitted_models = [
32 m.descriptor()
33 for m in safety_models()
34 if m.core_model_id == CoreModelId.llama_guard_3_8b
35 ]
36 if model not in permitted_models:
37 raise ValueError(
38 f"Invalid model: {model}. Must be one of {permitted_models}"
39 )
40 return model
41
42
43class PromptGuardShieldConfig(BaseModel):
44 model: str = "Prompt-Guard-86M"
45
46 @validator("model")
47 @classmethod
48 def validate_model(cls, model: str) -> str:
49 permitted_models = [
50 m.descriptor()
51 for m in safety_models()
52 if m.core_model_id == CoreModelId.prompt_guard_86m
53 ]
54 if model not in permitted_models:
55 raise ValueError(
56 f"Invalid model: {model}. Must be one of {permitted_models}"
57 )
58 return model
59
60
61class SafetyConfig(BaseModel):
62 llama_guard_shield: Optional[LlamaGuardShieldConfig] = None
63 prompt_guard_shield: Optional[PromptGuardShieldConfig] = None