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 6 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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ $ 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:
To install the Gen AI Hub package in your project, run:
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

```
$ npm install @sap-ai-sdk/foundation-models
```
Expand All @@ -55,7 +56,8 @@ $ npm install @sap-ai-sdk/foundation-models

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:
To install the Gen AI Hub package in your project, run:

```
$ npm install @sap-ai-sdk/orchestration
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
```
Expand All @@ -64,10 +66,9 @@ $ npm install @sap-ai-sdk/orchestration

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
49 changes: 47 additions & 2 deletions packages/foundation-models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,54 @@ $ 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
## OpenAI client
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

<!-- Details to be added -->
The OpenAI client can be used to send chat completion or embedding requests to the OpenAI model deployed in SAP Generative AI Hub.
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

### 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.
- `sap-ai-sdk/foundation-models` package installed in your project.

### Chat completion Client Usage
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

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

const client = new OpenAiChatClient('gpt-35-turbo');
const response = await client.run({
messages: [
{
role: 'user',
content: 'Where is the deepest place on earth located'
}
]
})
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
const responseContent = response.getContent();
```

It is also possible to create a chat client by passing a `deploymentId` instead of a `modelName`.
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

[req] Please try to avoid passive voice as much as possible.
[req] Please also recheck our docs style guide => instead of passing a deploymentId either use "passing the deploymentId parameter" or "passing a deployment ID"
[pp] I would explain it a little more in depth, why would you ever do that? Consider adding a subsection:

Suggested change
It is also possible to create a chat client by passing a `deploymentId` instead of a `modelName`.
#### Obtaining a deployment ID on your own
In case you want to obtain the ID of your deployment on your own you can pass it instead of a model name.
EXAMPLE

=> as this is true for all clients this could be in some shared documentation for all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have repeated this subsection for both clients as I don't have a shared documentation for all clients yet.
I will create a follow-up to create this shared documentation.
As a result, some information could be repeated for both clients for now.


On the response obtained from the client, you could also use convenience functions like `getContent()`, `getFinishReason()` and `getTokenUsage()` to get easy access to the certain parts of the response.
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
### Embedding Client Usage
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

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

const client = new OpenAiEmbeddingClient({ deploymentId: 'd123456abcdefg' });
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
const response = await client.run({
input: 'AI is fascinating'
});
ZhongpinWang marked this conversation as resolved.
Show resolved Hide resolved
const embedding = response.data[0]?.embedding;
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved
```

It is also possible to create an embedding client by passing a `modelName` instead of a `deploymentId`.
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

## Caching
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

The deployment information which includes deployment id and properties like model name and model version is also cached by default for 5 mins. So, if you create an OpenAI client with a `modelName`, the deployment information is fetched from the cache if it is available.
KavithaSiva marked this conversation as resolved.
Show resolved Hide resolved

## Support, Feedback, Contribution

Expand Down