Elffuss BraidHub

kikocis/llama-stack public

main · 1.2 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 Any, Dict, List, Protocol
9
10from llama_models.schema_utils import json_schema_type, webmethod
11from pydantic import BaseModel
12
13from llama_models.llama3.api.datatypes import * # noqa: F403
14
15
16@json_schema_type
17class ViolationLevel(Enum):
18 INFO = "info"
19 WARN = "warn"
20 ERROR = "error"
21
22
23@json_schema_type
24class SafetyViolation(BaseModel):
25 violation_level: ViolationLevel
26
27 # what message should you convey to the user
28 user_message: Optional[str] = None
29
30 # additional metadata (including specific violation codes) more for
31 # debugging, telemetry
32 metadata: Dict[str, Any] = Field(default_factory=dict)
33
34
35@json_schema_type
36class RunShieldResponse(BaseModel):
37 violation: Optional[SafetyViolation] = None
38
39
40class Safety(Protocol):
41 @webmethod(route="/safety/run_shield")
42 async def run_shield(
43 self, shield_type: str, messages: List[Message], params: Dict[str, Any] = None
44 ) -> RunShieldResponse: ...