-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README content for OpenAI connectors
- Loading branch information
1 parent
f9e33ea
commit 8663bec
Showing
6 changed files
with
282 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters