File size: 1,851 Bytes
447ebeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
export enum GuardrailProviders {
    PresidioPII = "Presidio PII",
    Bedrock = "Bedrock Guardrail",
    Lakera = "Lakera"
}

export const guardrail_provider_map: Record<string, string> = {
    PresidioPII: "presidio",
    Bedrock: "bedrock",
    Lakera: "lakera_v2"
};


// Decides if we should render the PII config settings for a given provider
// For now we only support PII config settings for Presidio PII
export const shouldRenderPIIConfigSettings = (provider: string | null) => {
    if (!provider) {
        return false;
    }
    // cast provider to GuardrailProviders enum
    const providerEnum = GuardrailProviders[provider as keyof typeof GuardrailProviders];
    return providerEnum === GuardrailProviders.PresidioPII;
};

const asset_logos_folder = '../ui/assets/logos/';

export const guardrailLogoMap: Record<string, string> = {
    [GuardrailProviders.PresidioPII]: `${asset_logos_folder}presidio.png`,
    [GuardrailProviders.Bedrock]: `${asset_logos_folder}bedrock.svg`,
    [GuardrailProviders.Lakera]: `${asset_logos_folder}lakeraai.jpeg`
};

export const getGuardrailLogoAndName = (guardrailValue: string): { logo: string, displayName: string } => {
    if (!guardrailValue) {
        return { logo: "", displayName: "-" };
    }

    // Find the enum key by matching guardrail_provider_map values
    const enumKey = Object.keys(guardrail_provider_map).find(
        key => guardrail_provider_map[key].toLowerCase() === guardrailValue.toLowerCase()
    );

    if (!enumKey) {
        return { logo: "", displayName: guardrailValue };
    }

    // Get the display name from GuardrailProviders enum and logo from map
    const displayName = GuardrailProviders[enumKey as keyof typeof GuardrailProviders];
    const logo = guardrailLogoMap[displayName as keyof typeof guardrailLogoMap];

    return { logo, displayName };
};