Skip to content

Commit

Permalink
Merge branch 'refs/heads/refactor-content-filters' into feat/descript…
Browse files Browse the repository at this point in the history
…ive-const-content-filter

# Conflicts:
#	packages/orchestration/README.md
#	packages/orchestration/src/orchestration-client.test.ts
#	packages/orchestration/src/orchestration-completion-post-request.test.ts
#	packages/orchestration/src/util/filtering.test.ts
#	packages/orchestration/src/util/filtering.ts
#	packages/orchestration/src/util/request-config.test.ts
#	sample-code/src/orchestration.ts
  • Loading branch information
KavithaSiva committed Jan 31, 2025
2 parents fc3bca5 + ce1ac5a commit 5d29563
Show file tree
Hide file tree
Showing 43 changed files with 520 additions and 466 deletions.
4 changes: 2 additions & 2 deletions .changeset/afraid-cooks-shave.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
'@sap-ai-sdk/orchestration': minor
---

[Compatibility Note] Deprecate `buildAzureContentFilter()` function since it restricts filtering to have only one filter.
Use `ContentFilters.buildAzureContentSafety()` function instead.
[Compatibility Note] Deprecate `buildAzureContentFilter()` function since it restricts filtering to have only one filter.
Use `buildAzureContentSafetyFilter()` function instead.
6 changes: 0 additions & 6 deletions .changeset/big-mayflies-begin.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/help-sap-com.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/sour-camels-fry.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/tender-numbers-sin.md

This file was deleted.

9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ jobs:
- uses: sap/ai-sdk-js/.github/actions/setup@main
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v5
- run: pnpm generate
- name: Enforce generated code is up to date
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "Generated code is out of date. The following changes were found after generating:"
git status
echo "Please run 'pnpm generate' and commit the changes."
exit 1
fi
- run: pnpm lint
- name: Check CommonJS compatibility
run: pnpm compile:cjs
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sap-ai-sdk",
"version": "1.6.0",
"version": "1.7.0",
"description": "",
"keywords": [],
"license": "Apache-2.0",
Expand Down Expand Up @@ -41,12 +41,12 @@
"@sap-ai-sdk/foundation-models": "workspace:^",
"@sap-ai-sdk/orchestration": "workspace:^",
"tsx": "^4.19.2",
"@sap-cloud-sdk/connectivity": "^3.25.0",
"@sap-cloud-sdk/eslint-config": "^3.25.0",
"@sap-cloud-sdk/generator-common": "^3.25.0",
"@sap-cloud-sdk/http-client": "^3.25.0",
"@sap-cloud-sdk/openapi-generator": "^3.25.0",
"@sap-cloud-sdk/util": "^3.25.0",
"@sap-cloud-sdk/connectivity": "^3.26.0",
"@sap-cloud-sdk/eslint-config": "^3.26.0",
"@sap-cloud-sdk/generator-common": "^3.26.0",
"@sap-cloud-sdk/http-client": "^3.26.0",
"@sap-cloud-sdk/openapi-generator": "^3.26.0",
"@sap-cloud-sdk/util": "^3.26.0",
"@types/jest": "^29.5.14",
"@types/jsonwebtoken": "^9.0.8",
"@types/mock-fs": "^4.13.4",
Expand All @@ -61,7 +61,6 @@
"prettier": "^3.4.2",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.7.3",
"node-jq": "^6.0.1"
"typescript": "^5.7.3"
}
}
6 changes: 6 additions & 0 deletions packages/ai-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sap-ai-sdk/ai-api

## 1.7.0

### Patch Changes

- @sap-ai-sdk/core@1.7.0

## 1.6.0

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/ai-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sap-ai-sdk/ai-api",
"version": "1.6.0",
"version": "1.7.0",
"description": "",
"license": "Apache-2.0",
"keywords": [
Expand Down Expand Up @@ -29,6 +29,6 @@
},
"dependencies": {
"@sap-ai-sdk/core": "workspace:^",
"@sap-cloud-sdk/connectivity": "^3.25.0"
"@sap-cloud-sdk/connectivity": "^3.26.0"
}
}
2 changes: 2 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @sap-ai-sdk/core

## 1.7.0

## 1.6.0

## 1.5.0
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sap-ai-sdk/core",
"version": "1.6.0",
"version": "1.7.0",
"description": "",
"license": "Apache-2.0",
"keywords": [
Expand All @@ -26,9 +26,9 @@
"lint:fix": "eslint \"**/*.ts\" --fix && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -w --log-level error"
},
"dependencies": {
"@sap-cloud-sdk/connectivity": "^3.25.0",
"@sap-cloud-sdk/http-client": "^3.25.0",
"@sap-cloud-sdk/openapi": "^3.25.0",
"@sap-cloud-sdk/util": "^3.25.0"
"@sap-cloud-sdk/connectivity": "^3.26.0",
"@sap-cloud-sdk/http-client": "^3.26.0",
"@sap-cloud-sdk/openapi": "^3.26.0",
"@sap-cloud-sdk/util": "^3.26.0"
}
}
6 changes: 6 additions & 0 deletions packages/document-grounding/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sap-ai-sdk/document-grounding

## 1.7.0

### Patch Changes

- @sap-ai-sdk/core@1.7.0

## 1.6.0

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/document-grounding/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sap-ai-sdk/document-grounding",
"version": "1.6.0",
"version": "1.7.0",
"description": "",
"license": "Apache-2.0",
"keywords": [
Expand Down
7 changes: 7 additions & 0 deletions packages/foundation-models/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @sap-ai-sdk/foundation-models

## 1.7.0

### Patch Changes

- @sap-ai-sdk/ai-api@1.7.0
- @sap-ai-sdk/core@1.7.0

## 1.6.0

### Patch Changes
Expand Down
11 changes: 5 additions & 6 deletions packages/foundation-models/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sap-ai-sdk/foundation-models",
"version": "1.6.0",
"version": "1.7.0",
"description": "",
"license": "Apache-2.0",
"keywords": [
Expand All @@ -26,15 +26,14 @@
"lint": "eslint \"**/*.ts\" && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -c",
"lint:fix": "eslint \"**/*.ts\" --fix && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -w --log-level error",
"generate": "pnpm generate:azure-openai",
"pregenerate:azure-openai": "cp ./src/azure-openai/spec/inference.json ./src/azure-openai/spec/inference.json.bak && pnpm node-jq \"walk(if type == \\\"object\\\" then (if has(\\\"x-ms-examples\\\") then del(.[\\\"x-ms-examples\\\"]) else . end) else . end)\" ./src/azure-openai/spec/inference.json.bak > ./src/azure-openai/spec/inference.json && rm -f ./src/azure-openai/spec/inference.json.bak",
"generate:azure-openai": "cd ./src/azure-openai/spec && openapi-generator --generateESM --clearOutputDir -i ./inference.json -o ../client --schemaPrefix AzureOpenAi && cd ..",
"generate:azure-openai": "cd ./src/azure-openai/spec && openapi-generator --resolveExternal false --generateESM --clearOutputDir -i ./inference.json -o ../client --schemaPrefix AzureOpenAi && cd ..",
"postgenerate:azure-openai": "rm ./src/azure-openai/client/inference/*.ts && pnpm lint:fix"
},
"dependencies": {
"@sap-ai-sdk/ai-api": "workspace:^",
"@sap-ai-sdk/core": "workspace:^",
"@sap-cloud-sdk/http-client": "^3.25.0",
"@sap-cloud-sdk/util": "^3.25.0",
"@sap-cloud-sdk/connectivity": "^3.25.0"
"@sap-cloud-sdk/http-client": "^3.26.0",
"@sap-cloud-sdk/util": "^3.26.0",
"@sap-cloud-sdk/connectivity": "^3.26.0"
}
}
45 changes: 45 additions & 0 deletions packages/foundation-models/src/azure-openai/spec/inference.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
}
}
}
},
"x-ms-examples": {
"Create a completion.": {
"$ref": "./examples/completions.json"
}
}
}
},
Expand Down Expand Up @@ -255,6 +260,11 @@
}
}
}
},
"x-ms-examples": {
"Create a embeddings.": {
"$ref": "./examples/embeddings.json"
}
}
}
},
Expand Down Expand Up @@ -337,6 +347,20 @@
}
}
}
},
"x-ms-examples": {
"Create a chat completion.": {
"$ref": "./examples/chat_completions.json"
},
"Creates a completion based on Azure Search data and system-assigned managed identity.": {
"$ref": "./examples/chat_completions_azure_search_minimum.json"
},
"Creates a completion based on Azure Search vector data, previous assistant message and user-assigned managed identity.": {
"$ref": "./examples/chat_completions_azure_search_advanced.json"
},
"Creates a completion for the provided Azure Cosmos DB.": {
"$ref": "./examples/chat_completions_cosmos_db.json"
}
}
}
},
Expand Down Expand Up @@ -400,6 +424,14 @@
}
}
}
},
"x-ms-examples": {
"Create an audio transcription with json response format.": {
"$ref": "./examples/audio_transcription_object.json"
},
"Create an audio transcription with text response format.": {
"$ref": "./examples/audio_transcription_text.json"
}
}
}
},
Expand Down Expand Up @@ -463,6 +495,14 @@
}
}
}
},
"x-ms-examples": {
"Create an audio translation with json response format.": {
"$ref": "./examples/audio_translation_object.json"
},
"Create an audio translation with text response format.": {
"$ref": "./examples/audio_translation_text.json"
}
}
}
},
Expand Down Expand Up @@ -523,6 +563,11 @@
}
}
}
},
"x-ms-examples": {
"Create an image.": {
"$ref": "./examples/image_generation.json"
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/langchain/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @sap-ai-sdk/langchain

## 1.7.0

### Minor Changes

- ccfa2eb: [Fixed Issue] Fixed the internal mapping of LangChain to Azure OpenAI and vice versa.

### Patch Changes

- @sap-ai-sdk/ai-api@1.7.0
- @sap-ai-sdk/core@1.7.0
- @sap-ai-sdk/foundation-models@1.7.0

## 1.6.0

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/langchain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sap-ai-sdk/langchain",
"version": "1.6.0",
"version": "1.7.0",
"description": "LangChain clients based on the @sap-ai-sdk",
"license": "Apache-2.0",
"keywords": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"@sap-ai-sdk/ai-api": "workspace:^",
"@sap-ai-sdk/core": "workspace:^",
"@sap-ai-sdk/foundation-models": "workspace:^",
"@sap-cloud-sdk/connectivity": "^3.25.0",
"@sap-cloud-sdk/connectivity": "^3.26.0",
"uuid": "^11.0.0",
"@langchain/core": "0.3.36",
"zod-to-json-schema": "^3.24.1"
Expand Down
15 changes: 15 additions & 0 deletions packages/orchestration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# @sap-ai-sdk/orchestration

## 1.7.0

### Minor Changes

- 0a62553: [Compatibility Note] Update AI API to the 2501a release.
As part of this change, the `modelsGet` method of `ScenarioAPI` has been renamed to `scenarioQueryModels`.
- f08ac2e: [New Functionality] Support using `help.sap.com` as data repository type in the grounding module.
- bdaae7e: [Fixed Issue] Fix logging bug when using streaming with JSON client.
[New Functionality] Add `streaming` option in the `OrchestrationModuleConfig` type to set global streaming options.

### Patch Changes

- @sap-ai-sdk/ai-api@1.7.0
- @sap-ai-sdk/core@1.7.0

## 1.6.0

### Minor Changes
Expand Down
8 changes: 4 additions & 4 deletions packages/orchestration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $ npm install @sap-ai-sdk/orchestration

- [Enable the AI Core service in SAP BTP](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/initial-setup).
- Configure the project with **Node.js v20 or higher** and **native ESM** support.
- Ensure an orchestration deployment is available in the SAP Generative AI Hub.
- Ensure an [orchestration deployment is available in the SAP Generative AI Hub](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-orchestration).
- Use the [`DeploymentApi`](https://github.com/SAP/ai-sdk-js/blob/main/packages/ai-api/README.md#create-a-deployment) from `@sap-ai-sdk/ai-api` [to create a deployment](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-orchestration).
Alternatively, you can also create deployments using the [SAP AI Launchpad](https://help.sap.com/docs/sap-ai-core/generative-ai-hub/activate-generative-ai-hub-for-sap-ai-launchpad?locale=en-US&q=launchpad).
- Once the deployment is complete, access the orchestration service via the `deploymentUrl`.
Expand Down Expand Up @@ -243,11 +243,11 @@ It will process each image and use the information from all of them to answer th

Use the orchestration client with filtering to restrict content that is passed to and received from a generative AI model.

This feature allows filtering both the [input](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/consume-orchestration#content-filtering-on-input) and [output](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/consume-orchestration#content-filtering-on-input) of a model based on content safety criteria.
This feature allows filtering both the [input](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/input-filtering) and [output](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/output-filtering) of a model based on content safety criteria.

#### Azure Content Filter

Use `ContentFilters.buildAzureContentSafety()` function to build an Azure content filter.
Use `buildAzureContentSafetyFilter()` function to build an Azure content filter.
The Azure content filter supports four categories: `Hate`, `Violence`, `Sexual`, and `SelfHarm`.
Each category can be set to a specific severity level, each of which corresponds to an azure threshold value.

Expand All @@ -270,7 +270,7 @@ const templating = {
template: [{ role: 'user', content: '{{?input}}' }]
};

const filter = ContentFilters.buildAzureContentSafety({
const filter = buildAzureContentSafetyFilter({
Hate: 'ALLOW_SAFE_LOW',
Violence: 'ALLOW_SAFE_LOW_MEDIUM'
});
Expand Down
Loading

0 comments on commit 5d29563

Please sign in to comment.