Skip to content

Commit

Permalink
Merge pull request #802 from sameerajayasoma/main
Browse files Browse the repository at this point in the history
Add `README.md` files to all `openai.*` connectors
  • Loading branch information
NipunaRanasinghe authored Jun 26, 2023
2 parents f807dd3 + 8663bec commit 93a4c43
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 0 deletions.
57 changes: 57 additions & 0 deletions openapi/openai.audio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Overview
This [Ballerina](https://ballerina.io) connector, which is actively maintained by a dedicated community, provides streamlined access to the [OpenAI Audio API](https://platform.openai.com/docs/api-reference/audio). Its main function is to act as an interface between your Ballerina application and OpenAI's sophisticated speech-to-text AI models. By utilizing this connector, developers can easily leverage the power of OpenAI's latest advancements in artificial intelligence for speech recognition and transcription tasks.

[API Documentation](https://lib.ballerina.io/ballerinax/openai.audio/latest)

## Prerequisites
* Create an [OpenAI account](https://platform.openai.com/signup).
* Obtain an API key by following [these instructions](https://platform.openai.com/docs/api-reference/authentication).

## Quick start
### Step 1: Create a Ballerina package
Use `bal new` to create a new package.

```sh
bal new openai_audio
cd openai_audio
```

### Step 2: Invoke the audio API
Copy the following code to the `main.bal` file.

```ballerina
import ballerinax/openai.audio;
import ballerina/io;
// Read the OpenAI key
configurable string openAIKey = ?;
public function main(string fileName) returns error? {
// Create an OpenAI audio client.
audio:Client OpenAIAudio = check new ({
auth: {token: openAIKey}
});
// Create a speech-to-text request.
byte[] fileContent = check io:fileReadBytes(fileName);
audio:CreateTranscriptionRequest request = {
model: "whisper-1",
file: {fileContent, fileName}
};
// Call the API.
audio:CreateTranscriptionResponse response =
check OpenAIAudio->/audio/transcriptions.post(request);
io:println(response);
}
```

### Step 3: Set up your OpenAI API Key
Create a file called `Config.toml` at the root of the package directory and copy for the following content.
```toml
# OpenAI API Key
openAIKey="..."
```

### Step 4: Run the program
Use the `bal run -- audio.mp3` command to compile and run the Ballerina program.
56 changes: 56 additions & 0 deletions openapi/openai.chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Overview
This is a community-maintained [Ballerina](https://ballerina.io) connector for the [OpenAI Chat API](https://platform.openai.com/docs/api-reference/chat). It provides a way to access the state-of-the-art ChatGPT models developed by OpenAI. This connector is an indispensable tool for developers aiming to harness the advanced conversational AI capabilities of ChatGPT models in their Ballerina applications.

[API Documentation](https://lib.ballerina.io/ballerinax/openai.chat/latest)

## Prerequisites
* Create an [OpenAI account](https://platform.openai.com/signup).
* Obtain an API key by following [these instructions](https://platform.openai.com/docs/api-reference/authentication).

## Quick start
### Step 1: Create a Ballerina package
Use `bal new` to create a new package.

```sh
bal new openai_chat
cd openai_chat
```

### Step 2: Invoke the chat API
Copy the following code to the `main.bal` file.

```ballerina
import ballerinax/openai.chat;
import ballerina/io;
// Read the OpenAI key
configurable string openAIKey = ?;
public function main() returns error? {
// Create an OpenAI chat client.
chat:Client openAIChat = check new ({
auth: {token: openAIKey}
});
// Create a chat completion request.
chat:CreateChatCompletionRequest request = {
model: "gpt-3.5-turbo",
messages: [{"role": "user", "content": "What is Ballerina?"}]
};
// Call the API.
chat:CreateChatCompletionResponse response =
check openAIChat->/chat/completions.post(request);
io:println(response);
}
```

### Step 3: Set up your OpenAI API Key
Create a file called `Config.toml` at the root of the package directory and copy for the following content.
```toml
# OpenAI API Key
openAIKey="..."
```

### Step 4: Run the program
Use the `bal run` command to compile and run the Ballerina program.
54 changes: 54 additions & 0 deletions openapi/openai.embeddings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Overview
This [Ballerina](https://ballerina.io) connector, which is actively maintained by a dedicated community, provides streamlined access to the [OpenAI Embeddings API](https://platform.openai.com/docs/api-reference/embeddings). It offers an interface to extract embeddings from a diverse range of AI models recently devised by OpenAI. This connector is a crucial tool for developers intending to utilize the cutting-edge artificial intelligence capabilities of these models in various computational tasks.

[API Documentation](https://lib.ballerina.io/ballerinax/openai.embeddings/latest)

## Prerequisites
* Create an [OpenAI account](https://platform.openai.com/signup).
* Obtain an API key by following [these instructions](https://platform.openai.com/docs/api-reference/authentication).

## Quick start
### Step 1: Create a Ballerina package
Use `bal new` to create a new package.

```sh
bal new openai_embeddings
cd openai_embeddings
```

### Step 2: Invoke the embeddings API
Copy the following code to the `main.bal` file.

```ballerina
import ballerinax/openai.embeddings;
import ballerina/io;
// Read the OpenAI key
configurable string openAIKey = ?;
public function main() returns error? {
// Create an OpenAI embeddings client.
embeddings:Client embeddingsClient = check new ({
auth: {token: openAIKey}
});
embeddings:CreateEmbeddingRequest request = {
model: "text-embedding-ada-002",
input: "The food was delicious and the waiter..."
};
embeddings:CreateEmbeddingResponse response =
check embeddingsClient->/embeddings.post(request);
io:println(response);
}
```

### Step 3: Set up your OpenAI API Key
Create a file called `Config.toml` at the root of the package directory and copy for the following content.
```toml
# OpenAI API Key
openAIKey="..."
```

### Step 4: Run the program
Use the `bal run` command to compile and run the Ballerina program.
62 changes: 62 additions & 0 deletions openapi/openai.finetunes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## Overview
This [Ballerina](https://ballerina.io) connector, which is actively maintained by a dedicated community, provides streamlined access to the [OpenAI Fine-tunes API](https://platform.openai.com/docs/api-reference/fine-tunes). The OpenAI Fine-tunes API allows developers to tailor the latest AI models developed by OpenAI according to their specific requirements.

[API Documentation](https://lib.ballerina.io/ballerinax/openai.finetunes/latest)

## Prerequisites
* Create an [OpenAI account](https://platform.openai.com/signup).
* Obtain an API key by following [these instructions](https://platform.openai.com/docs/api-reference/authentication).

## Quick start
### Step 1: Create a Ballerina package
Use `bal new` to create a new package.

```sh
bal new openai_finetunes
cd openai_finetunes
```

### Step 2: Invoke the fine-tunes API
Copy the following code to the `main.bal` file.

```ballerina
import ballerinax/openai.finetunes;
import ballerina/io;
// Read the OpenAI key
configurable string openAIKey = ?;
public function main(string fileName) returns error? {
// Create an OpenAI fine-tunes client.
finetunes:Client finetunesClient = check new ({
auth: {token: openAIKey}
});
byte[] fileContent = check io:fileReadBytes(fileName);
finetunes:CreateFileRequest fileRequest = {
file: {fileContent, fileName},
purpose: "fine-tune"
};
finetunes:OpenAIFile fileResponse =
check finetunesClient->/files.post(fileRequest);
string fileId = fileResponse.id;
finetunes:CreateFineTuneRequest fineTuneRequest = {
model: "ada",
training_file: fileId
};
finetunes:FineTune fineTuneResponse =
check finetunesClient->/fine\-tunes.post(fineTuneRequest);
io:println(fineTuneResponse.id);
}
```

### Step 3: Set up your OpenAI API Key
Create a file called `Config.toml` at the root of the package directory and copy for the following content.
```toml
# OpenAI API Key
openAIKey="..."
```

### Step 4: Run the program
Use the `bal run -- sample.jsonl` command to compile and run the Ballerina program.
55 changes: 55 additions & 0 deletions openapi/openai.images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Overview
This [Ballerina](https://ballerina.io) connector, which is actively maintained by a dedicated community, provides streamlined access to the [OpenAI Images API](https://platform.openai.com/docs/api-reference/images). The OpenAI Images API facilitates access to the innovative DALL.E models developed by OpenAI, designed for a range of image-based tasks. This connector is an essential tool for developers aiming to employ the power of OpenAI's advanced image processing AI capabilities in their applications.

[API Documentation](https://lib.ballerina.io/ballerinax/openai.images/latest)

## Prerequisites
* Create an [OpenAI account](https://platform.openai.com/signup).
* Obtain an API key by following [these instructions](https://platform.openai.com/docs/api-reference/authentication).

## Quick start
### Step 1: Create a Ballerina package
Use `bal new` to create a new package.

```sh
bal new openai_images
cd openai_images
```

### Step 2: Invoke the images API
Copy the following code to the `main.bal` file.

```ballerina
import ballerinax/openai.images;
import ballerina/io;
// Read the OpenAI key
configurable string openAIKey = ?;
public function main() returns error? {
images:Client openAIImages = check new ({
auth: {token: openAIKey}
});
images:CreateImageRequest request = {
prompt: "A cute baby sea otter",
n: 1,
size: "256x256",
response_format: "url",
user: "user-1234"
};
images:ImagesResponse response =
check openAIImages->/images/generations.post(request);
io:println(response);
}
```

### Step 3: Set up your OpenAI API Key
Create a file called `Config.toml` at the root of the package directory and copy for the following content.
```toml
# OpenAI API Key
openAIKey="..."
```

### Step 4: Run the program
Use the `bal run` command to compile and run the Ballerina program.
53 changes: 53 additions & 0 deletions openapi/openai.moderations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Overview
This [Ballerina](https://ballerina.io) connector, which is actively maintained by a dedicated community, provides streamlined access to the [OpenAI Moderations API](https://platform.openai.com/docs/api-reference/moderations). The OpenAI Moderations API provides a way to access new moderation models developed by OpenAI for content moderation tasks.

[API Documentation](https://lib.ballerina.io/ballerinax/openai.moderations/latest)

## Prerequisites
* Create an [OpenAI account](https://platform.openai.com/signup).
* Obtain an API key by following [these instructions](https://platform.openai.com/docs/api-reference/authentication).

## Quick start
### Step 1: Create a Ballerina package
Use `bal new` to create a new package.

```sh
bal new openai_moderations
cd openai_moderations
```

### Step 2: Invoke the moderations API
Copy the following code to the `main.bal` file.

```ballerina
import ballerinax/openai.moderations;
import ballerina/io;
// Read the OpenAI key
configurable string openAIKey = ?;
public function main() returns error? {
moderations:Client moderationsClient = check new ({
auth: {token: openAIKey}
});
moderations:CreateModerationRequest request = {
input: "I want to kill them.",
model: "text-moderation-stable"
};
moderations:CreateModerationResponse response =
check moderationsClient->/moderations.post(request);
io:println(response);
}
```

### Step 3: Set up your OpenAI API Key
Create a file called `Config.toml` at the root of the package directory and copy for the following content.
```toml
# OpenAI API Key
openAIKey="..."
```

### Step 4: Run the program
Use the `bal run` command to compile and run the Ballerina program.
56 changes: 56 additions & 0 deletions openapi/openai.text/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Overview
This is a community-maintained [Ballerina](https://ballerina.io) connector for the [OpenAI Completions API](https://platform.openai.com/docs/api-reference/completions). It serves as a powerful bridge, connecting your Ballerina applications to the cutting-edge Text AI models developed by OpenAI. This makes it an invaluable tool for those seeking to incorporate advanced AI functionalities into their projects.

[API Documentation](https://lib.ballerina.io/ballerinax/openai.text/latest)

## Prerequisites
* Create an [OpenAI account](https://platform.openai.com/signup).
* Obtain an API key by following [these instructions](https://platform.openai.com/docs/api-reference/authentication).

## Quick start
### Step 1: Create a Ballerina package
Use `bal new` to create a new package.

```sh
bal new openai_text
cd openai_text
```

### Step 2: Invoke the completions API
Copy the following code to the `main.bal` file.

```ballerina
import ballerinax/openai.text;
import ballerina/io;
// Read the OpenAI key
configurable string openAIKey = ?;
public function main() returns error? {
// Create an OpenAI text client.
text:Client openAIText = check new ({
auth: {token: openAIKey}
});
// Create a completion request.
text:CreateCompletionRequest request = {
model: "text-davinci-003",
prompt: "Say this is a test"
};
// Call the API.
text:CreateCompletionResponse response =
check openAIText->/completions.post(request);
io:println(response);
}
```

### Step 3: Set up your OpenAI API Key
Create a file called `Config.toml` at the root of the package directory and copy for the following content.
```toml
# OpenAI API Key
openAIKey="..."
```

### Step 4: Run the program
Use the `bal run` command to compile and run the Ballerina program.

0 comments on commit 93a4c43

Please sign in to comment.