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

Update Docs #3

Merged
merged 8 commits into from
Aug 14, 2024
Merged
75 changes: 72 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,84 @@

## Overview

[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.)
[OpenAI](https://openai.com/), an AI research organization dedicated to developing beneficial AI for humanity, provides the [OpenAI API](https://platform.openai.com/docs/api-reference/introduction) for accessing its powerful AI models, enabling tasks such as natural language processing and image generation.

The `ballarinax/openai.chat` package offers functionality to connect and interact with [Chat Completion related endpoints of OpenAI API](https://platform.openai.com/docs/api-reference/chat) Enabling seamless interaction with the advanced GPT-4 models developed by OpenAI for diverse conversational and text generation tasks.
NipunaRanasinghe marked this conversation as resolved.
Show resolved Hide resolved

## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
To use the OpenAI Connector, you must have access to the OpenAI API through a [OpenAI Platform account](https://platform.openai.com) and a project under it. If you do not have a OpenAI Platform account, you can sign up for one [here](https://platform.openai.com/signup).

#### Create a OpenAI API Key

1. Open the [OpenAI Platform Dashboard](https://platform.openai.com).

2. Navigate to **Dashboard** -> **API keys**.
<img src=/docs/setup/resources/navigate-api-key-dashboard.png alt="Navigate to API key section" style="width: 70%;">

3. Click on the **Create new secret key** button.
<img src=/docs/setup/resources/api-key-dashboard.png alt="OpenAI Dashbaord | API keys" style="width: 70%;">

4. Fill the details and click on Create secret key.
<img src=/docs/setup/resources/create-new-secrete-key.png alt="Create New API key" style="width: 70%;">

5. Store the API key securely to use in your application.
<img src=/docs/setup/resources/saved-key.png alt="Generated New API key" style="width: 70%;">

## Quickstart

[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.)
To use the `OpenAI Chat` connector in your Ballerina application, update the `.bal` file as follows:

### Step 1: Import the module

Import the `ballerinax/openai.chat` module.

```ballerina
import ballerinax/openai.chat;
```

### Step 2: Create a new connector instance

Create a `chat:Client` with the obtained API Key and initialize the connector.

```ballerina
chat:Client openAIChat = check new({
auth: {
token
}
});
NipunaRanasinghe marked this conversation as resolved.
Show resolved Hide resolved
```

### Step 3: Invoke the connector operation

Now, you can utilize available connector operations.

#### Generate a response for given message

```ballerina

public function main() returns error? {

// Create a chat completion request.
CreateChatCompletionRequest request = {

model: "gpt-4o-mini",
NipunaRanasinghe marked this conversation as resolved.
Show resolved Hide resolved
messages: [{
"role": "user",
"content": "What is Ballerina programming language?"
}]

};
NipunaRanasinghe marked this conversation as resolved.
Show resolved Hide resolved

CreateChatCompletionResponse response = check openAIChat->/chat/completions.post(request);
}
```

### Step 4: Run the Ballerina application

```bash
bal run
```

## Examples

Expand Down
74 changes: 71 additions & 3 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,82 @@
## Overview

[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.)
[OpenAI](https://openai.com/), an AI research organization dedicated to developing beneficial AI for humanity, provides the [OpenAI API](https://platform.openai.com/docs/api-reference/introduction) for accessing its powerful AI models, enabling tasks such as natural language processing and image generation.

The `ballarinax/openai.chat` package offers functionality to connect and interact with [Chat Completion related endpoints of OpenAI API](https://platform.openai.com/docs/api-reference/chat) Enabling seamless interaction with the advanced GPT-4 models developed by OpenAI for diverse conversational and text generation tasks.

## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
To use the OpenAI Connector, you must have access to the OpenAI API through a [OpenAI Platform account](https://platform.openai.com) and a project under it. If you do not have a OpenAI Platform account, you can sign up for one [here](https://platform.openai.com/signup).

#### Create a OpenAI API Key

1. Open the [OpenAI Platform Dashboard](https://platform.openai.com).

2. Navigate to **Dashboard** -> **API keys**.
<img src=/docs/setup/resources/navigate-api-key-dashboard.png alt="Navigate to API key section" style="width: 70%;">

3. Click on the **Create new secret key** button.
<img src=/docs/setup/resources/api-key-dashboard.png alt="OpenAI Dashbaord | API keys" style="width: 70%;">

4. Fill the details and click on Create secret key.
<img src=/docs/setup/resources/create-new-secrete-key.png alt="Create New API key" style="width: 70%;">

5. Store the API key securely to use in your application.
<img src=/docs/setup/resources/saved-key.png alt="Generated New API key" style="width: 70%;">

## Quickstart

[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.)
To use the `OpenAI Chat` connector in your Ballerina application, update the `.bal` file as follows:

### Step 1: Import the module

Import the `ballerinax/openai.chat` module.

```ballerina
import ballerinax/openai.chat;
```

### Step 2: Create a new connector instance

Create a `chat:Client` with the obtained API Key and initialize the connector.

```ballerina
chat:Client openAIChat = check new({
auth: {
token
}
});
```

### Step 3: Invoke the connector operation

Now, you can utilize available connector operations.

#### Generate a response for given message

```ballerina
public function main() returns error? {

// Create a chat completion request.
CreateChatCompletionRequest request = {

model: "gpt-4o-mini",
messages: [{
"role": "user",
"content": "What is Ballerina programming language?"
}]

};

CreateChatCompletionResponse response = check openAIChat->/chat/completions.post(request);
}
```

### Step 4: Run the Ballerina application

```bash
bal run
```

## Examples

Expand Down
74 changes: 71 additions & 3 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,82 @@
## Overview

[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.)
[OpenAI](https://openai.com/), an AI research organization dedicated to developing beneficial AI for humanity, provides the [OpenAI API](https://platform.openai.com/docs/api-reference/introduction) for accessing its powerful AI models, enabling tasks such as natural language processing and image generation.

The `ballarinax/openai.chat` package offers functionality to connect and interact with [Chat Completion related endpoints of OpenAI API](https://platform.openai.com/docs/api-reference/chat) Enabling seamless interaction with the advanced GPT-4 models developed by OpenAI for diverse conversational and text generation tasks.

## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
To use the OpenAI Connector, you must have access to the OpenAI API through a [OpenAI Platform account](https://platform.openai.com) and a project under it. If you do not have a OpenAI Platform account, you can sign up for one [here](https://platform.openai.com/signup).

#### Create a OpenAI API Key

1. Open the [OpenAI Platform Dashboard](https://platform.openai.com).

2. Navigate to **Dashboard** -> **API keys**.
<img src=/docs/setup/resources/navigate-api-key-dashboard.png alt="Navigate to API key section" style="width: 70%;">

3. Click on the **Create new secret key** button.
<img src=/docs/setup/resources/api-key-dashboard.png alt="OpenAI Dashbaord | API keys" style="width: 70%;">

4. Fill the details and click on Create secret key.
<img src=/docs/setup/resources/create-new-secrete-key.png alt="Create New API key" style="width: 70%;">

5. Store the API key securely to use in your application.
<img src=/docs/setup/resources/saved-key.png alt="Generated New API key" style="width: 70%;">

## Quickstart

[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.)
To use the `OpenAI Chat` connector in your Ballerina application, update the `.bal` file as follows:

### Step 1: Import the module

Import the `ballerinax/openai.chat` module.

```ballerina
import ballerinax/openai.chat;
```

### Step 2: Create a new connector instance

Create a `chat:Client` with the obtained API Key and initialize the connector.

```ballerina
chat:Client openAIChat = check new({
auth: {
token
}
});
```

### Step 3: Invoke the connector operation

Now, you can utilize available connector operations.

#### Generate a response for given message

```ballerina
public function main() returns error? {

// Create a chat completion request.
CreateChatCompletionRequest request = {

model: "gpt-4o-mini",
messages: [{
"role": "user",
"content": "What is Ballerina programming language?"
}]

};

CreateChatCompletionResponse response = check openAIChat->/chat/completions.post(request);
}
```

### Step 4: Run the Ballerina application

```bash
bal run
```

## Examples

Expand Down
Binary file added docs/setup/resources/api-key-dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/setup/resources/saved-key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading