Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Follow-up Documentation cleanup #159

Merged
merged 66 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
7239bbb
chore: add local testing instructions
KavithaSiva Sep 20, 2024
f89fc29
fix: Changes from lint
Sep 20, 2024
971883e
chore: minor sentence fix
KavithaSiva Sep 20, 2024
8072128
chore: fix sentence
KavithaSiva Sep 20, 2024
f39f044
chore: add missing sections
KavithaSiva Sep 20, 2024
9028c12
Update packages/orchestration/README.md
KavithaSiva Sep 23, 2024
e0f2033
Update packages/orchestration/README.md
KavithaSiva Sep 23, 2024
df50cd1
Update packages/orchestration/README.md
KavithaSiva Sep 23, 2024
7390dbe
Update packages/orchestration/README.md
KavithaSiva Sep 23, 2024
8506bd6
Update packages/langchain/README.md
KavithaSiva Sep 23, 2024
361940b
Update packages/ai-api/README.md
KavithaSiva Sep 23, 2024
ef23a7c
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Sep 23, 2024
d62d62d
chore: link client readmes in root
KavithaSiva Sep 23, 2024
98fa3b4
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Sep 23, 2024
f1991b1
Update packages/orchestration/README.md
KavithaSiva Sep 23, 2024
864f041
chore: Address review comments
KavithaSiva Sep 23, 2024
7b94a23
chore: address review comments
KavithaSiva Sep 24, 2024
9333645
fix: Changes from lint
Sep 24, 2024
63fd72c
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Sep 24, 2024
94c3d8a
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Sep 25, 2024
4c8ce4f
Merge branch 'documentation/minor-cleanup' of github.com:SAP/ai-sdk-j…
KavithaSiva Sep 25, 2024
87a2ac0
chore: address review comments
KavithaSiva Sep 25, 2024
124a0d8
chore: add deploymentID relationship
KavithaSiva Sep 25, 2024
54f7815
chore: address review comment
KavithaSiva Sep 25, 2024
0f34a2d
chore: address review comments
KavithaSiva Sep 25, 2024
d5856df
chore: remove usage of you
KavithaSiva Sep 25, 2024
45b547e
chore: remove usages of you.
KavithaSiva Sep 25, 2024
2e29d74
fix: Changes from lint
Sep 25, 2024
8fd9186
chore: remove more usages of you
KavithaSiva Sep 25, 2024
76f5dd3
Merge branch 'documentation/minor-cleanup' of github.com:SAP/ai-sdk-j…
KavithaSiva Sep 25, 2024
408b0a1
chore: address review comment
KavithaSiva Sep 25, 2024
0016f88
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Sep 25, 2024
756b5df
chore: minor cleanup
KavithaSiva Sep 25, 2024
41c0b84
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Sep 26, 2024
129bdeb
Update packages/orchestration/README.md
KavithaSiva Sep 26, 2024
0a2a768
Update packages/orchestration/README.md
KavithaSiva Sep 27, 2024
728abe2
Update packages/orchestration/README.md
KavithaSiva Sep 27, 2024
afb3a95
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Sep 27, 2024
267a6f7
chore: cleanup links
KavithaSiva Sep 27, 2024
53b14e2
chore: cleanup links
KavithaSiva Sep 27, 2024
cd54014
chore: explain deployment id
KavithaSiva Sep 27, 2024
b379d9e
chore: explain deployment ID
KavithaSiva Sep 27, 2024
40e7409
chore: fix toc
KavithaSiva Sep 27, 2024
688af41
Update packages/orchestration/README.md
KavithaSiva Sep 27, 2024
9e26d5a
Update packages/orchestration/README.md
KavithaSiva Sep 27, 2024
d7f9522
chore: address review comments
KavithaSiva Sep 27, 2024
69afd57
chore: final review comment
KavithaSiva Sep 27, 2024
e24d8ad
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Oct 1, 2024
7af7b3b
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Oct 2, 2024
508fee5
chore: address review comments
KavithaSiva Oct 2, 2024
697e2c9
fix: Changes from lint
Oct 2, 2024
1425977
chore: remove requestConfig section
KavithaSiva Oct 2, 2024
5d40c54
Merge branch 'documentation/minor-cleanup' of github.com:SAP/ai-sdk-j…
KavithaSiva Oct 2, 2024
ecf5c01
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Oct 2, 2024
831b355
chore: cleanup convenience functions usage
KavithaSiva Oct 2, 2024
5358ad1
chore: fix toc
KavithaSiva Oct 2, 2024
bce751d
chore: fix toc
KavithaSiva Oct 2, 2024
57c02a0
Update README.md
deekshas8 Oct 2, 2024
37f23a7
Apply suggestions from code review
deekshas8 Oct 2, 2024
8188acc
Apply suggestions from code review
deekshas8 Oct 2, 2024
05d15b8
Update packages/orchestration/README.md
deekshas8 Oct 2, 2024
59cb45a
Update packages/orchestration/README.md
deekshas8 Oct 2, 2024
1838278
Update packages/orchestration/README.md
deekshas8 Oct 2, 2024
9eff8b0
Apply suggestions from code review
deekshas8 Oct 2, 2024
9926785
Merge branch 'main' into documentation/minor-cleanup
KavithaSiva Oct 4, 2024
3a70dc7
fix: Changes from lint
Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Integrate chat completion into your business applications with SAP Cloud SDK for
- [@sap-ai-sdk/orchestration](#sap-ai-sdkorchestration)
- [@sap-ai-sdk/langchain](#sap-ai-sdklangchain)
- [SAP Cloud SDK for AI Sample Project](#sap-cloud-sdk-for-ai-sample-project)
- [Local Testing](#local-testing)
- [Support, Feedback, Contribution](#support-feedback-contribution)
- [Security / Disclosure](#security--disclosure)
- [Code of Conduct](#code-of-conduct)
Expand All @@ -32,6 +33,8 @@ This package incorporates generative AI [orchestration](https://help.sap.com/doc
$ npm install @sap-ai-sdk/orchestration
```

For details on orchestration client, refer to this [document](https://github.com/SAP/ai-sdk-js/blob/main/packages/orchestration/README.md).

### @sap-ai-sdk/ai-api

This package provides tools to manage your scenarios and workflows in SAP AI Core.
Expand All @@ -47,6 +50,8 @@ This package provides tools to manage your scenarios and workflows in SAP AI Cor
$ npm install @sap-ai-sdk/ai-api
```

For details on the client, refer to this [document](https://github.com/SAP/ai-sdk-js/blob/main/packages/ai-api/README.md).

### @sap-ai-sdk/foundation-models

This package incorporates generative AI foundation models into your AI activities in SAP AI Core and SAP AI Launchpad.
Expand All @@ -57,6 +62,8 @@ This package incorporates generative AI foundation models into your AI activitie
$ npm install @sap-ai-sdk/foundation-models
```

For details on foundation model clients, refer to this [document](https://github.com/SAP/ai-sdk-js/blob/main/packages/foundation-models/README.md).

### @sap-ai-sdk/langchain

This package provides LangChain model clients, built on top of the foundation model clients of the SAP Cloud SDK for AI.
Expand All @@ -67,15 +74,27 @@ This package provides LangChain model clients, built on top of the foundation mo
$ npm install @sap-ai-sdk/langchain
```

For details on LangChain model client, refer to this [document](https://github.com/SAP/ai-sdk-js/blob/main/packages/langchain/README.md).

## SAP Cloud SDK for AI Sample Project

We have created a sample project demonstrating the different clients' usage of the SAP Cloud SDK for AI for TypeScript/JavaScript. The [project README](./sample-code/README.md) outlines the set-up needed to build and run it locally.
We have created a sample project demonstrating the different clients' usage of the SAP Cloud SDK for AI for TypeScript/JavaScript. The [project README](https://github.com/SAP/ai-sdk-js/blob/main/sample-code/README.md) outlines the set-up needed to build and run it locally.

## Local Testing

To test SAP Cloud SDK for AI features locally during application development, follow these steps:

- Download a service key for the AI Core service instance.
- Set the downloaded service key as the `AICORE_SERVICE_KEY` environment variable in the local environment.

The SDK parses the service key from the environment variable to interact with the AI Core service.
This setup enables local testing of clients such as orchestration and OpenAI, provided that deployments for orchestration and OpenAI exist in SAP BTP.

## Support, Feedback, Contribution

This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/ai-sdk-js/issues).

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](CONTRIBUTING.md).
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).

## Security / Disclosure

Expand Down
24 changes: 15 additions & 9 deletions packages/ai-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ We maintain a list of [currently available and tested AI Core APIs](https://gith

## Table of Contents

1. [Installation](#installation)
2. [Prerequisites](#prerequisites)
3. [Usage](#usage)
- [Create an Artifact](#create-an-artifact)
- [Create a Configuration](#create-a-configuration)
- [Create a Deployment](#create-a-deployment)
- [Delete a Deployment](#delete-a-deployment)
4. [Support, Feedback, Contribution](#support-feedback-contribution)
5. [License](#license)
- [Installation](#installation)
- [Version Management](#version-management)
- [Prerequisites](#prerequisites)
- [Usage](#usage)
- [Create an Artifact](#create-an-artifact)
- [Create a Configuration](#create-a-configuration)
- [Create a Deployment](#create-a-deployment)
- [Delete a Deployment](#delete-a-deployment)
- [Local Testing](#local-testing)
- [Support, Feedback, Contribution](#support-feedback-contribution)
- [License](#license)

## Installation

Expand Down Expand Up @@ -169,6 +171,10 @@ async function modifyDeployment() {
}
```

## Local Testing

For local testing instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#local-testing).

## Support, Feedback, Contribution

This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/ai-sdk-js/issues).
Expand Down
25 changes: 20 additions & 5 deletions packages/foundation-models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ This package incorporates generative AI foundation models into your AI activitie

## Table of Contents

- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Relationship between Models and Deployment ID](#relationship-between-models-and-deployment-id)
- [Usage](#usage)
- [Client Initialization](#client-initialization)
- [Chat Client](#chat-client)
- [Embedding Client](#embedding-client)
- [Local Testing](#local-testing)
- [Support, Feedback, Contribution](#support-feedback-contribution)
- [License](#license)

Expand All @@ -25,9 +26,21 @@ $ npm install @sap-ai-sdk/foundation-models
- [Enable the AI Core service in BTP](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/initial-setup).
- Project configured with Node.js v20 or higher and native ESM support enabled.
- A deployed OpenAI model in SAP Generative AI hub.
- Use the [`DeploymentApi`](../ai-api/README.md#deploymentapi) from `@sap-ai-sdk/ai-api` to deploy a model to SAP generative AI hub. For more information, see [here](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-generative-ai-model-in-sap-ai-core).
- 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 deploy a model to SAP generative AI hub.
For more information, see [here](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-generative-ai-model-in-sap-ai-core).
Deployment can be set up for each model and model version, as well as a resource group intended for use with the generative AI hub.
- Once a deployment is complete, the model can be accessed via the `deploymentUrl`
- Once a deployment is complete, the model can be accessed via the `deploymentUrl`.

## Relationship between Models and Deployment ID

SAP AI Core manages access to generative AI models through the global AI scenario `foundation-models`.
Creating a deployment for a model requires access to this scenario.

Each model, model version, and resource group allows for a one-time deployment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Each model, model version, and resource group allows for a one-time deployment.
Deployment requires model name, model version and resource group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subtle differences between the two, so I will use the original sentence, as it talks about relationship rather than what is required by the API.

After deployment completion, the response includes a `deploymentUrl` and an `id`, which is the deployment ID. For more information, see [here](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-generative-ai-model-in-sap-ai-core).
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
[Resource groups](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/resource-groups?q=resource+group) represent a virtual collection of related resources within the scope of one SAP AI Core tenant.

Consequently, each deployment ID and resource group uniquely map to a combination of model and model version within the `foundation-models` scenario.
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

## Usage

Expand All @@ -49,8 +62,6 @@ const chatClient = new AzureOpenAiChatClient({ modelName: 'gpt-4o' });
const embeddingClient = new AzureOpenAiEmbeddingClient({ modelName: 'gpt-4o' });
```

[Resource groups](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/resource-groups?q=resource+group) represent a virtual collection of related resources within the scope of one SAP AI Core tenant.

The deployment ID and resource group can be used as an alternative to the model name for obtaining a model.

```ts
Expand Down Expand Up @@ -154,6 +165,10 @@ const embedding = response.getEmbedding();

Define optional request configuration when running the client, similar to the chat client.

## Local Testing

For local testing instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#local-testing).

## Support, Feedback, Contribution

This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/ai-sdk-js/issues).
Expand Down
45 changes: 33 additions & 12 deletions packages/langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ This package provides LangChain model clients built on top of the foundation mod

## Table of Contents

1. [Installation](#installation)
2. [Prerequisites](#prerequisites)
3. [Usage](#usage)
- [Client Initialization](#client-initialization)
- [Chat Client](#chat-client)
- [Embedding Client](#embedding-client)
4. [Support, Feedback, Contribution](#support-feedback-contribution)
5. [License](#license)
- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Relationship between Models and Deployment ID](#relationship-between-models-and-deployment-id)
- [Usage](#usage)
- [Client Initialization](#client-initialization)
- [Chat Client](#chat-client)
- [Embedding Client](#embedding-client)
- [Local Testing](#local-testing)
- [Support, Feedback, Contribution](#support-feedback-contribution)
- [License](#license)

## Installation

Expand All @@ -24,10 +26,22 @@ $ npm install @sap-ai-sdk/langchain
- [Enable the AI Core service in SAP BTP](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/initial-setup).
- Bind the service to your application.
- Ensure the project is configured with Node.js v20 or higher, along with native ESM support.
- For testing your application locally:
- Download a service key for your AI Core service instance.
- Create a `.env` file in the root of your directory.
- Add an entry `AICORE_SERVICE_KEY='<content-of-service-key>'`.
- A deployed model is available in SAP Generative AI hub.
- 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 deploy a model to SAP generative AI hub.
For more information, see [here](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-generative-ai-model-in-sap-ai-core).
- Once a deployment is complete, the model can be accessed via the `deploymentUrl`.

## Relationship between Models and Deployment ID

SAP AI Core manages access to generative AI models through the global AI scenario `foundation-models`.
Creating a deployment for a model requires access to this scenario.

Each model, model version, and resource group allows for a one-time deployment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, a bit confusing to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

After deployment completion, the response includes a `deploymentUrl` and an `id`, which is the deployment ID. For more information, see [here](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-generative-ai-model-in-sap-ai-core).

[Resource groups](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/resource-groups?q=resource+group) represent a virtual collection of related resources within the scope of one SAP AI Core tenant.

Consequently, each deployment ID and resource group uniquely map to a combination of model and model version within the `foundation-models` scenario.

## Usage

Expand Down Expand Up @@ -60,6 +74,9 @@ const chatClient = new AzureOpenAiChatClient({
});
```

**Do not pass a `deployment ID` to initialize the client.**
For the LangChain model clients, initialization is done using the model name, model version and resource group.

An important note is that LangChain clients by default attempt 6 retries with exponential backoff in case of a failure.
Especially in testing environments you might want to reduce this number to speed up the process:

Expand Down Expand Up @@ -155,6 +172,10 @@ const vectorStore = await MemoryVectorStore.fromDocuments(
const retriever = vectorStore.asRetriever();
```

## Local Testing

For local testing instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#local-testing).

## Support, Feedback, Contribution

This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/ai-sdk-js/issues).
Expand Down
100 changes: 77 additions & 23 deletions packages/orchestration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

This package incorporates generative AI orchestration capabilities into your AI activities in SAP AI Core and SAP AI Launchpad.

### Table of Contents
## Table of Contents

- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Prerequisites](#prerequisites)
- [Orchestration Service](#orchestration-service)
- [Relationship between Orchestration and Resource Groups](#relationship-between-orchestration-and-resource-groups)
- [Usage](#usage)
- [Templating](#templating)
- [Token Usage](#token-usage)
- [Content Filtering](#content-filtering)
- [Data Masking](#data-masking)
- [Data Masking](#data-masking)
- [Using Resource Groups](#using-resource-groups)
- [Local Testing](#local-testing)
- [Support, Feedback, Contribution](#support-feedback-contribution)
- [License](#license)

Expand All @@ -21,12 +23,13 @@ This package incorporates generative AI orchestration capabilities into your AI
$ npm install @sap-ai-sdk/orchestration
```

### Prerequisites
## Prerequisites

- [Enable the AI Core service in SAP BTP](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/initial-setup).
- Project configured with Node.js v20 or higher and native ESM support enabled.
- An orchestration deployment is running.
- Use the [`DeploymentApi`](../ai-api/README.md#deploymentapi) from `@sap-ai-sdk/ai-api` to create a deployment for orchestration to the SAP generative AI hub. For more information, see [here](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 for orchestration to the SAP generative AI hub.
For more information, see [here](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-orchestration).
- Once a deployment is complete, the orchestration service can be accessed via the `deploymentUrl`.

## Orchestration Service
Expand All @@ -38,6 +41,16 @@ The orchestration service provides essential features like templating and conten

Find more details about orchestration workflow [here](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/orchestration-workflow).

## Relationship between Orchestration and Resource Groups

SAP AI Core manages access to orchestration of generative AI models through the global AI scenario `orchestration`.
Creating a deployment for enabling orchestration capabilities requires access to this scenario.

[Resource groups](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/resource-groups?q=resource+group) represent a virtual collection of related resources within the scope of one SAP AI Core tenant.
Each resource group allows for a one-time orchestration deployment.

Consequently, each orchestration deployment uniquely maps to a resource group within the `orchestration` scenario.
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +45 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pp] I would suggest we extract this section into a separate file as it has been repeated many times. It will be very hard to maintain so many packages. At least we should do this definitely in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As, the deployment requirements change between orchestration and foundation-models. I would prefer to write about it in the dedicated client document instead of a separate file, as this would be more confusing.


## Usage

Leverage the orchestration service capabilities by using the orchestration client.
Expand Down Expand Up @@ -99,6 +112,28 @@ const response = await orchestrationClient.chatCompletion(
const responseContent = response.getContent();
```

`getContent()` is a convenience method that parses the response and returns the model's output as a string.

```ts
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
const finishReason = response.getFinishReason();
```

`getFinishReason()` is a convenience method that specifies the reason for stopping the chat completion request.
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved

deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
```ts
const tokenUsage = response.getTokenUsage();

console.log(
`Total tokens consumed by the request: ${tokenUsage.total_tokens}\n` +
`Input prompt tokens consumed: ${tokenUsage.prompt_tokens}\n` +
`Output text completion tokens consumed: ${tokenUsage.completion_tokens}\n`
);
```

deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
`getTokenUsage()` is a convenience method that retrieves the token usage details of the chat completion request.
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved

#### Passing a Message History

It is possible to provide a history of a conversation to the model.
Use the following snippet to send a chat completion request with history and a system message:

Expand Down Expand Up @@ -136,22 +171,6 @@ const response = await orchestrationClient.chatCompletion({
const responseContent = response.getContent();
```

#### Token Usage

To retrieve the token usage details of the orchestration request, use the following snippet:

```ts
const tokenUsage = response.getTokenUsage();

logger.info(
`Total tokens consumed by the request: ${tokenUsage.total_tokens}\n` +
`Input prompt tokens consumed: ${tokenUsage.prompt_tokens}\n` +
`Output text completion tokens consumed: ${tokenUsage.completion_tokens}\n`
);
```

Remember to initialize a logger before using it.

### Content Filtering

Use the orchestration client with filtering to restrict content that is passed to and received from a generative AI model.
Expand Down Expand Up @@ -189,11 +208,21 @@ try {
}
```

In the above code snippet, both `chatCompletion()` and `getContent()` methods can throw errors.
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved

- **Axios Errors**:
When the chat completion request fails with a `400` status code, the caught error will be an `Axios` error. The property `error.response.data.message` may provide additional details about the failure's cause.
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved

- **Output Content Filtered**:
The method `getContent()` can throw an error if the output filter filters the model output. This situation can occur even if the chat completion request succeeds with a `200` status code. The `error.message` property indicates whether the output was filtered.
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved

Therefore, handle errors appropriately to ensure meaningful feedback for both types of errors.

`buildAzureContentFilter()` is a convenience function that creates an Azure content filter configuration based on the provided inputs.
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
### Data Masking

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

Expand Down Expand Up @@ -229,6 +258,31 @@ const response = await orchestrationClient.chatCompletion({
return response.getContent();
```

### Using Resource Groups

The resource group can be used as an additional parameter to pick the right orchestration deployment.

```ts
const orchestrationClient = new OrchestrationClient(
{
llm: {
model_name: 'gpt-4-32k',
model_params: { max_tokens: 50, temperature: 0.1 }
},
templating: {
template: [{ role: 'user', content: 'What is my name?' }]
}
},
{ resourceGroup: 'rg1234' }
);
```

The relationship between orchestration and resource groups is explained in this [section](#relationship-between-orchestration-and-resource-groups).

## Local Testing

For local testing instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#local-testing).

## 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