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: Adding Documentation for OpenAI client #134

Merged
merged 36 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
47d030f
chore: add documentation for OpenAI client
KavithaSiva Sep 16, 2024
30d1478
chore:minor updates
KavithaSiva Sep 16, 2024
5ca2a7b
chore:Add documentation for embedding client
KavithaSiva Sep 16, 2024
9bccc16
chore: switch to the correct readme
KavithaSiva Sep 16, 2024
f66a3cc
Merge branch 'main' into documentation-open-ai-client
KavithaSiva Sep 16, 2024
43f90ed
Merge branch 'main' into documentation-open-ai-client
KavithaSiva Sep 17, 2024
988073b
Update packages/foundation-models/README.md
KavithaSiva Sep 17, 2024
86dcfbc
chore: cleanup root readme
KavithaSiva Sep 18, 2024
ecebfa4
chore: minor fix
KavithaSiva Sep 18, 2024
fc1dc2a
Update packages/foundation-models/README.md
KavithaSiva Sep 18, 2024
e11322e
Update packages/foundation-models/README.md
KavithaSiva Sep 18, 2024
676526b
chore: progress till now
KavithaSiva Sep 18, 2024
68df02b
Merge branch 'documentation-open-ai-client' of github.com:SAP/ai-sdk-…
KavithaSiva Sep 18, 2024
ebb4468
chore:progress till now
KavithaSiva Sep 18, 2024
4fd7c92
chore: address review comments
KavithaSiva Sep 18, 2024
eb17cf7
chore: minor cleanup
KavithaSiva Sep 18, 2024
73f59af
chore: address review comments
KavithaSiva Sep 18, 2024
10e0946
chore: address review comments
KavithaSiva Sep 18, 2024
09be33a
Merge branch 'main' into documentation-open-ai-client
KavithaSiva Sep 18, 2024
3ac3788
chore: minor fixes
KavithaSiva Sep 18, 2024
d9eed14
Merge branch 'documentation-open-ai-client' of github.com:SAP/ai-sdk-…
KavithaSiva Sep 18, 2024
9e840d9
Update README.md
KavithaSiva Sep 19, 2024
97a826b
chore: review comments
KavithaSiva Sep 19, 2024
7563401
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
ba86fba
chore: address review comments
KavithaSiva Sep 19, 2024
e8b9804
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
f038ed3
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
fce00b3
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
d0cc6bd
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
112f33a
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
2b3b0f3
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
271e306
fix: Changes from lint
Sep 19, 2024
1ece4aa
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
dc6a3d0
Update packages/foundation-models/README.md
KavithaSiva Sep 19, 2024
bf5214e
chore: address review comments
KavithaSiva Sep 19, 2024
889ace9
Merge branch 'main' into documentation-open-ai-client
KavithaSiva Sep 19, 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
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# SAP Cloud SDK for AI

Integrate chat completion into your business applications with SAP Cloud SDK for GenAI Hub. Leverage the Generative AI Hub of SAP AI Core to make use of templating, grounding, data masking, content filtering and more. Setup your SAP AI Core instance with SAP Cloud SDK for AI Core.
Integrate chat completion into your business applications with SAP Cloud SDK for AI. Leverage the generative AI hub of SAP AI Core to make use of templating, grounding, data masking, content filtering and more. Setup your SAP AI Core instance with SAP Cloud SDK for AI Core.

## Disclaimer ⚠️

Expand All @@ -27,6 +27,16 @@ This project is currently in an experimental state. All functionality and naming

This project publishes multiple packages and is managed using [pnpm](https://pnpm.io/)

### @sap-ai-sdk/orchestration

This package incorporates generative AI [orchestration](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/orchestration) capabilities into your AI activities in SAP AI Core and SAP AI Launchpad.

#### Installation

```
$ npm install @sap-ai-sdk/orchestration
```

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

This package provides tools to manage your scenarios and workflows in SAP AI Core.
Expand All @@ -36,7 +46,7 @@ This package provides tools to manage your scenarios and workflows in SAP AI Cor
- Deploy inference endpoints for your trained models.
- Register custom Docker registries, sync AI content from your own git repositories, and register your own object storage for training data and model artifacts.

To install the AI Core package in your project, run:
#### Installation

```
$ npm install @sap-ai-sdk/ai-api
Expand All @@ -46,28 +56,19 @@ $ npm install @sap-ai-sdk/ai-api

This package incorporates generative AI foundation models into your AI activities in SAP AI Core and SAP AI Launchpad.

To install the Gen AI Hub package in your project, run:
```
$ npm install @sap-ai-sdk/foundation-models
```

### @sap-ai-sdk/orchestration
#### Installation

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

To install the Gen AI Hub package in your project, run:
```
$ npm install @sap-ai-sdk/orchestration
$ npm install @sap-ai-sdk/foundation-models
```

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


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

Expand Down
129 changes: 127 additions & 2 deletions packages/foundation-models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,134 @@ $ npm install @sap-ai-sdk/foundation-models
- Create a `.env` file in the sample-code directory.
- Add an entry `AICORE_SERVICE_KEY='<content-of-service-key>'`.

## Usage
## Azure OpenAI Client

<!-- Details to be added -->
To make a generative AI model available for use, you need to create a deployment.
You can create a deployment for each model and model version, as well as for each resource group that you want to use with generative AI hub.

After the deployment is complete, you have a `deploymentUrl`, which can be used to access the model.

The Azure OpenAI client allows you to send chat completion or embedding requests to OpenAI models deployed in SAP generative AI hub.

### Prerequisites

- A deployed OpenAI model in SAP generative AI hub.
- You can 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).
- `sap-ai-sdk/foundation-models` package installed in your project.

### Usage of Azure OpenAI Chat Client

Use the `AzureOpenAiChatClient` to send chat completion requests to an OpenAI model deployed in SAP generative AI hub.
You can pass the model name as a parameter to the client, the SDK will implicitly fetch the deployment ID for the model from the AI Core service and use it to send the request.

By default, the SDK caches the deployment information, which includes the deployment ID and properties such as the model name and model version, for 5 minutes to prevent performance impact from fetching the deployment information for every request.

```TS
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
import { AzureOpenAiChatClient } from '@sap-ai-sdk/foundation-models';

const client = new AzureOpenAiChatClient('gpt-35-turbo');
const response = await client.run({
messages: [
{
role: 'user',
content: 'Where is the deepest place on earth located'
}
]
});

const responseContent = response.getContent();

```

Use the following snippet to send a chat completion request with system messages:

```TS
import { AzureOpenAiChatClient } from '@sap-ai-sdk/foundation-models';

const client = new AzureOpenAiChatClient('gpt-35-turbo');
const response = await client.run({
messages: [
{
role: 'system',
content: 'You are a friendly chatbot.'
},
{
role: 'user',
content: 'Hi, my name is Isa'
},
{
role: 'assistant',
content: 'Hi Isa! It is nice to meet you. Is there anything I can help you with today?'
},
{
role: 'user',
content: 'Can you remind me, What is my name?'
}
],
max_tokens: 100,
temperature: 0.0
});

const responseContent = response.getContent();
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`
);

```

It is possible to send multiple messages in a single request.
This feature is useful for providing a history of the conversation to the model.

Pass parameters like `max_tokens` and `temperature` to the request to control the completion behavior.
Refer to `AzureOpenAiChatCompletionParameters` interface for knowing more parameters that can be passed to the chat completion request.

#### Obtaining a Client using Resource Groups

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.

You can use the deployment ID and resource group as an alternative to obtaining a model by using the model name.

```TS
import { AzureOpenAiChatClient } from '@sap-ai-sdk/foundation-models';

const response = await new AzureOpenAiChatClient({ deploymentId: 'd1234' , resourceGroup: 'rg1234' }).run({
messages: [
{
'role':'user',
'content': 'What is the capital of France?'
}
]
});

```

### Usage of Azure OpenAI Embedding Client

Use the `AzureOpenAiEmbeddingClient` to send embedding requests to an OpenAI model deployed in SAP generative AI hub.
You can pass the model name as a parameter to the client, the SDK will implicitly fetch the deployment ID for the model from the AI Core service and use it to send the request.

By default, the SDK caches the deployment information, which includes the deployment ID and properties such as the model name and model version, for 5 minutes to prevent performance impact from fetching the deployment information for every request.

```TS
import { AzureOpenAiEmbeddingClient } from '@sap-ai-sdk/foundation-models';

const client = new AzureOpenAiEmbeddingClient('text-embedding-ada-002');
const response = await client.run({
input: 'AI is fascinating'
});
const embedding = response.getEmbedding();

```

Like in [Azure OpenAI Chat client](#obtaining-a-client-using-resource-groups), you could also pass the [resource group](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/resource-groups?q=resource+group) name to the client along with the deployment ID instead of the model name.

```TS
const client = new AzureOpenAiEmbeddingClient({ deploymentId: 'd1234' , resourceGroup: 'rg1234' })
```

## Support, Feedback, Contribution

Expand Down