@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**.
56 lines • 2.11 kB
JavaScript
import { supportedAzureFilterThresholds } from '../orchestration-types.js';
/**
* Convenience function to build Azure content filter.
* @param filter - Filtering configuration for Azure filter. If skipped, the default Azure content filter configuration is used.
* @returns An object with the Azure filtering configuration.
* @deprecated Since 1.8.0. Use {@link buildAzureContentSafetyFilter()} instead.
*/
export function buildAzureContentFilter(filter) {
if (filter && !Object.keys(filter).length) {
throw new Error('Filter property cannot be an empty object');
}
return {
filters: [
{
type: 'azure_content_safety',
...(filter && { config: filter })
}
]
};
}
/**
* Convenience function to build Azure content filter.
* @param config - Configuration for Azure content safety filter.
* If skipped, the default configuration of `ALLOW_SAFE_LOW` is used for all filter categories.
* @returns Filter config object.
* @example "buildAzureContentSafetyFilter({ Hate: 'ALLOW_SAFE', Violence: 'ALLOW_SAFE_LOW_MEDIUM' })"
*/
export function buildAzureContentSafetyFilter(config) {
if (config && !Object.keys(config).length) {
throw new Error('Filtering configuration cannot be an empty object');
}
return {
type: 'azure_content_safety',
...(config && {
config: {
...Object.fromEntries(Object.entries(config).map(([key, value]) => [
key,
supportedAzureFilterThresholds[value]
]))
}
})
};
}
/**
* Convenience function to build Llama guard filter.
* @param categories - Categories to be enabled for filtering. Provide at least one category.
* @returns Filter config object.
* @example "buildLlamaGuardFilter('self_harm', 'hate')"
*/
export function buildLlamaGuardFilter(...categories) {
return {
type: 'llama_guard_3_8b',
config: Object.fromEntries([...categories].map(category => [category, true]))
};
}
//# sourceMappingURL=filtering.js.map