Skip to content

Commit

Permalink
merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
MatKuhr committed Sep 26, 2024
2 parents a548d1b + a1105d9 commit d9d912e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-trees-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ai-sdk/orchestration': minor
---

[New Functionality] Add support for the data masking capabilities of the orchestration service.
36 changes: 36 additions & 0 deletions packages/orchestration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ try {
The Azure content filter supports four categories: `Hate`, `Violence`, `Sexual`, and `SelfHarm`.
Each category can be configured with severity levels of 0, 2, 4, or 6.

#### Data Masking

You can anonymize or pseudonomize the prompt using the data masking capabilities of the orchestration service.

```ts
const orchestrationClient = new OrchestrationClient({
llm: {
model_name: 'gpt-4-32k',
model_params: {}
},
templating: {
template: [
{
role: 'user',
content:
'Please write an email to {{?user}} ({{?email}}), informing them about the amazing capabilities of generative AI! Be brief and concise, write at most 6 sentences.'
}
]
},
masking: {
masking_providers: [
{
type: 'sap_data_privacy_integration',
method: 'pseudonymization',
entities: [{ type: 'profile-email' }, { type: 'profile-person' }]
}
]
}
});

const response = await orchestrationClient.chatCompletion({
inputParams: { user: 'Alice Anderson', email: '[email protected]' }
});
return response.getContent();
```

## Support, Feedback, Contribution

Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](https://github.com/SAP/ai-sdk-js/blob/main/CONTRIBUTING.md).
Expand Down
3 changes: 3 additions & 0 deletions packages/orchestration/src/orchestration-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export function constructCompletionPostRequest(
llm_module_config: config.llm,
...(Object.keys(config?.filtering || {}).length && {
filtering_module_config: config.filtering
}),
...(Object.keys(config?.masking || {}).length && {
masking_module_config: config.masking
})
}
},
Expand Down
5 changes: 5 additions & 0 deletions packages/orchestration/src/orchestration-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChatModel } from './model-types.js';
import {
ChatMessages,
FilteringModuleConfig,
MaskingModuleConfig,
LlmModuleConfig as OriginalLlmModuleConfig,
TemplatingModuleConfig
} from './client/api/schema/index.js';
Expand Down Expand Up @@ -45,4 +46,8 @@ export interface OrchestrationModuleConfig {
* Filtering module configuration.
*/
filtering?: FilteringModuleConfig;
/**
* Masking module configuration.
*/
masking?: MaskingModuleConfig;
}
3 changes: 2 additions & 1 deletion sample-code/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export {
orchestrationTemplating,
orchestrationInputFiltering,
orchestrationOutputFiltering,
orchestrationRequestConfig
orchestrationRequestConfig,
orchestrationCompletionMasking
} from './orchestration.js';
export {
embedQuery,
Expand Down
38 changes: 38 additions & 0 deletions sample-code/src/orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,44 @@ export async function orchestrationOutputFiltering(): Promise<OrchestrationRespo
);
}

/**
* Ask to write an e-mail while masking personal information.
* @returns The message content from the orchestration service in the generative AI hub.
*/
export async function orchestrationCompletionMasking(): Promise<
string | undefined
> {
const orchestrationClient = new OrchestrationClient({
llm: {
model_name: 'gpt-4-32k',
model_params: {}
},
templating: {
template: [
{
role: 'user',
content:
'Please write an email to {{?user}} ({{?email}}), informing them about the amazing capabilities of generative AI! Be brief and concise, write at most 6 sentences.'
}
]
},
masking: {
masking_providers: [
{
type: 'sap_data_privacy_integration',
method: 'pseudonymization',
entities: [{ type: 'profile-email' }, { type: 'profile-person' }]
}
]
}
});

const response = await orchestrationClient.chatCompletion({
inputParams: { user: 'Alice Anderson', email: '[email protected]' }
});
return response.getContent();
}

/**
* Ask about the capital of France and send along custom request configuration.
* @returns The orchestration service response.
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e-tests/src/orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
orchestrationTemplating,
orchestrationInputFiltering,
orchestrationOutputFiltering,
orchestrationRequestConfig
orchestrationRequestConfig,
orchestrationCompletionMasking
} from '@sap-ai-sdk/sample-code';
import { OrchestrationResponse } from '@sap-ai-sdk/orchestration';
import { loadEnv } from './utils/load-env.js';
Expand Down Expand Up @@ -49,4 +50,9 @@ describe('orchestration', () => {

assertContent(response);
});

it('should complete a chat with masking', async () => {
const result = await orchestrationCompletionMasking();
expect(result).toEqual(expect.any(String));
});
});

0 comments on commit d9d912e

Please sign in to comment.