From 8663bec28236335daae86e46c376c8f38ea90b1c Mon Sep 17 00:00:00 2001 From: sameerajayasoma Date: Mon, 26 Jun 2023 16:33:17 +0530 Subject: [PATCH] Add README content for OpenAI connectors --- openapi/openai.audio/README.md | 57 +++++++++++++++++++++++++ openapi/openai.embeddings/README.md | 54 ++++++++++++++++++++++++ openapi/openai.finetunes/README.md | 62 ++++++++++++++++++++++++++++ openapi/openai.images/README.md | 55 ++++++++++++++++++++++++ openapi/openai.moderations/README.md | 53 ++++++++++++++++++++++++ openapi/openai.text/README.md | 2 +- 6 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 openapi/openai.audio/README.md create mode 100644 openapi/openai.embeddings/README.md create mode 100644 openapi/openai.finetunes/README.md create mode 100644 openapi/openai.images/README.md create mode 100644 openapi/openai.moderations/README.md diff --git a/openapi/openai.audio/README.md b/openapi/openai.audio/README.md new file mode 100644 index 000000000..5e6eade9f --- /dev/null +++ b/openapi/openai.audio/README.md @@ -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. diff --git a/openapi/openai.embeddings/README.md b/openapi/openai.embeddings/README.md new file mode 100644 index 000000000..b7b0b9798 --- /dev/null +++ b/openapi/openai.embeddings/README.md @@ -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. diff --git a/openapi/openai.finetunes/README.md b/openapi/openai.finetunes/README.md new file mode 100644 index 000000000..10256c1ba --- /dev/null +++ b/openapi/openai.finetunes/README.md @@ -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. diff --git a/openapi/openai.images/README.md b/openapi/openai.images/README.md new file mode 100644 index 000000000..f8ca1aa9f --- /dev/null +++ b/openapi/openai.images/README.md @@ -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. diff --git a/openapi/openai.moderations/README.md b/openapi/openai.moderations/README.md new file mode 100644 index 000000000..a25c0da90 --- /dev/null +++ b/openapi/openai.moderations/README.md @@ -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. diff --git a/openapi/openai.text/README.md b/openapi/openai.text/README.md index f015372e8..e1f3752b9 100644 --- a/openapi/openai.text/README.md +++ b/openapi/openai.text/README.md @@ -1,5 +1,5 @@ ## Overview -This is a community-maintained [Ballerina](https://ballerina.io) connector for the [OpenAI Completions API](https://platform.openai.com/docs/api-reference/completions). The OpenAI Completions API provides a way to access new Text AI models developed by OpenAI for a variety of tasks. +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)