Skip to content

Commit 485e21b

Browse files
authored
feat: Support protected_material_code (#1285)
1 parent 0401a30 commit 485e21b

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

.changeset/smooth-showers-throw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sap-ai-sdk/orchestration': minor
3+
---
4+
5+
[New Functionality] Added support for `protected_material_code` property to `buildAzureContentSafetyFilter()` function for output filter configuration to allow detecting protected code content from known github repositories.

packages/orchestration/src/orchestration-types.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ export interface GroundingModule {
296296
metadata_params?: string[];
297297
};
298298
}
299-
300299
/**
301300
* Represents a filter configuration for the Document Grounding Service.
302301
*/
@@ -361,10 +360,7 @@ export type DpiMaskingConfig = Omit<
361360
mask_grounding_input?: boolean;
362361
};
363362

364-
/**
365-
* Output Parameters for Azure content safety output filter.
366-
*/
367-
export interface AzureContentSafetyFilterOutputParameters {
363+
interface AzureContentSafetyFilterBaseParameters {
368364
/**
369365
* The filter category for hate content.
370366
*/
@@ -382,16 +378,27 @@ export interface AzureContentSafetyFilterOutputParameters {
382378
*/
383379
violence?: AzureFilterThreshold;
384380
}
381+
382+
/**
383+
* Output Parameters for Azure content safety output filter.
384+
*/
385+
export interface AzureContentSafetyFilterOutputParameters
386+
extends AzureContentSafetyFilterBaseParameters {
387+
/**
388+
* Detect protected code content from known GitHub repositories. The scan includes software libraries, source code, algorithms, and other proprietary programming content.
389+
*/
390+
protected_material_code?: boolean;
391+
}
385392
/**
386393
* Input parameters for Azure content safety input filter.
387394
*/
388-
export type AzureContentSafetyFilterInputParameters =
389-
AzureContentSafetyFilterOutputParameters & {
390-
/**
391-
* A flag to use prompt shield.
392-
*/
393-
prompt_shield?: boolean;
394-
};
395+
export interface AzureContentSafetyFilterInputParameters
396+
extends AzureContentSafetyFilterBaseParameters {
397+
/**
398+
* A flag to use prompt shield.
399+
*/
400+
prompt_shield?: boolean;
401+
}
395402

396403
/**
397404
* A descriptive constant for Azure content safety filter threshold.

packages/orchestration/src/util/filtering.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ describe('Content filter util', () => {
3333
'Filtering parameters cannot be empty'
3434
);
3535
});
36+
37+
it('builds output filter config with protected_material_code', async () => {
38+
const filterConfig = buildAzureContentSafetyFilter('output', {
39+
hate: 'ALLOW_SAFE',
40+
protected_material_code: true
41+
});
42+
const expectedFilterConfig = {
43+
type: 'azure_content_safety',
44+
config: {
45+
hate: 0,
46+
protected_material_code: true
47+
}
48+
};
49+
expect(filterConfig).toEqual(expectedFilterConfig);
50+
});
3651
});
3752

3853
describe('Llama Guard filter', () => {

packages/orchestration/src/util/filtering.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ export function buildAzureContentSafetyFilter<T extends ConfigType>(
4747
} as AzureContentSafetyFilterReturnType<T>;
4848
}
4949

50+
const { protected_material_code, ...restConfig } =
51+
config as AzureContentSafetyFilterParameters<'output'>;
5052
return {
5153
type: 'azure_content_safety',
5254
config: {
5355
...Object.fromEntries(
54-
Object.entries(config).map(([key, value]) => [
56+
Object.entries(restConfig).map(([key, value]) => [
5557
key,
5658
supportedAzureFilterThresholds[value as AzureFilterThreshold]
5759
])
58-
)
60+
),
61+
...(protected_material_code !== undefined && { protected_material_code })
5962
}
6063
} as AzureContentSafetyFilterReturnType<T>;
6164
}

tests/type-tests/test/orchestration.test-d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,20 @@ expectError<AzureContentSafetyFilterReturnType<'output'>>(
417417
})
418418
);
419419

420+
expectType<AzureContentSafetyFilterReturnType<'output'>>(
421+
buildAzureContentSafetyFilter('output', {
422+
hate: 'ALLOW_SAFE',
423+
protected_material_code: true
424+
})
425+
);
426+
427+
expectError<AzureContentSafetyFilterReturnType<'input'>>(
428+
buildAzureContentSafetyFilter('input', {
429+
hate: 'ALLOW_SAFE',
430+
protected_material_code: true
431+
})
432+
);
433+
420434
/**
421435
* Filtering Util for Llama guard.
422436
*/

0 commit comments

Comments
 (0)