Skip to content

Commit

Permalink
fix: Disallow additional properties to be added in the filter config (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jjtang1985 authored Nov 7, 2024
1 parent 6fe32b8 commit bf17e17
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sap-ai-sdk/orchestration': minor
---
[Fixed Issue] Fix input and output filters to disallow additional properties as part of the filter config.

[Compatibility Note] `FilteringConfig` type has been renamed to `InputFilteringConfig` and `OutputFilteringConfig` for future extensibility.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
*
* This is a generated file powered by the SAP Cloud SDK for JavaScript.
*/
import type { FilteringConfig } from './filtering-config.js';
import { InputFilteringConfig } from './input-filtering-config.js';
import { OutputFilteringConfig } from './output-filtering-config.js';
/**
* Representation of the 'FilteringModuleConfig' schema.
*/
export type FilteringModuleConfig = {
/**
* List of provider type and filters.
*/
input?: FilteringConfig;
input?: InputFilteringConfig;
/**
* List of provider type and filters.
*/
output?: FilteringConfig;
output?: OutputFilteringConfig;
};
3 changes: 2 additions & 1 deletion packages/orchestration/src/client/api/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export * from './llm-choice.js';
export * from './token-usage.js';
export * from './templating-module-config.js';
export * from './filtering-module-config.js';
export * from './filtering-config.js';
export * from './input-filtering-config.js';
export * from './output-filtering-config.js';
export * from './filter-config.js';
export * from './azure-content-safety-filter-config.js';
export * from './azure-content-safety.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/
import type { FilterConfig } from './filter-config.js';
/**
* Representation of the 'FilteringConfig' schema.
* Representation of the 'InputFilteringConfig' schema.
*/
export type FilteringConfig = {
export type InputFilteringConfig = {
/**
* Configuration for content filtering services that should be used for the given filtering step (input filtering or output filtering).
* Min Items: 1.
*/
filters: FilterConfig[];
} & Record<string, any>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved.
*
* This is a generated file powered by the SAP Cloud SDK for JavaScript.
*/
import type { FilterConfig } from './filter-config.js';
/**
* Representation of the 'OutputFilteringConfig' schema.
*/
export type OutputFilteringConfig = {
/**
* Configuration for content filtering services that should be used for the given filtering step (input filtering or output filtering).
* Min Items: 1.
*/
filters: FilterConfig[];
};
3 changes: 2 additions & 1 deletion packages/orchestration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export type {
LlmChoice,
GenericModuleResult,
FilteringModuleConfig,
FilteringConfig,
InputFilteringConfig,
OutputFilteringConfig,
FilterConfig,
ErrorResponse,
DpiEntities,
Expand Down
5 changes: 3 additions & 2 deletions packages/orchestration/src/orchestration-filter-utility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
AzureContentSafety,
FilteringConfig
InputFilteringConfig,
OutputFilteringConfig
} from './client/api/schema/index.js';

/**
Expand All @@ -10,7 +11,7 @@ import type {
*/
export function buildAzureContentFilter(
filter?: AzureContentSafety
): FilteringConfig {
): InputFilteringConfig | OutputFilteringConfig {
if (filter && !Object.keys(filter).length) {
throw new Error('Filter property cannot be an empty object');
}
Expand Down

0 comments on commit bf17e17

Please sign in to comment.