@sap-ai-sdk/orchestration
Version:
SAP Cloud SDK for AI is the official Software Development Kit (SDK) for **SAP AI Core**, **SAP Generative AI Hub**, and **Orchestration Service**.
57 lines • 2.24 kB
JavaScript
import { supportedAzureFilterThresholds } from '../orchestration-types.js';
/**
* Convenience function to build Azure content filter.
* @param type - Type of the filter, either 'input' or 'output'.
* @param config - Configuration for Azure content safety filter.
* If skipped, the default configuration of `ALLOW_SAFE_LOW` is used for all filter categories.
* @returns Azure content safety configuration.
* @example "buildAzureContentSafetyFilter('input', { hate: 'ALLOW_SAFE', violence: 'ALLOW_SAFE_LOW_MEDIUM' })"
*/
export function buildAzureContentSafetyFilter(type, config) {
if (!config) {
return {
type: 'azure_content_safety'
};
}
if (!Object.keys(config).length) {
throw new Error('Filtering parameters cannot be empty');
}
if (type === 'input') {
const { prompt_shield, ...rest } = config;
return {
type: 'azure_content_safety',
config: {
...Object.fromEntries(Object.entries(rest).map(([key, value]) => [
key,
supportedAzureFilterThresholds[value]
])),
...(prompt_shield !== undefined && { prompt_shield })
}
};
}
const { protected_material_code, ...restConfig } = config;
return {
type: 'azure_content_safety',
config: {
...Object.fromEntries(Object.entries(restConfig).map(([key, value]) => [
key,
supportedAzureFilterThresholds[value]
])),
...(protected_material_code !== undefined && { protected_material_code })
}
};
}
/**
* Convenience function to build Llama Guard 3 8B filter.
* @param type - Type of the filter, either `input` or `output`.
* @param categories - Categories to be enabled for filtering. Provide at least one category.
* @returns Llama Guard 3 8B filter configuration.
* @example buildLlamaGuard38BFilter('input', ['elections', 'hate'])
*/
export function buildLlamaGuard38BFilter(type, categories) {
return {
type: 'llama_guard_3_8b',
config: Object.fromEntries([...categories].map(category => [category, true]))
};
}
//# sourceMappingURL=filtering.js.map