From b1b5e961b72c7c51290c776c0aa3e8216543e0cd Mon Sep 17 00:00:00 2001 From: sameerajayasoma Date: Mon, 26 Jun 2023 13:39:12 +0530 Subject: [PATCH 1/4] Add README content to the completions library --- openapi/openai.text/README.md | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 openapi/openai.text/README.md diff --git a/openapi/openai.text/README.md b/openapi/openai.text/README.md new file mode 100644 index 000000000..f015372e8 --- /dev/null +++ b/openapi/openai.text/README.md @@ -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). The OpenAI Completions API provides a way to access new Text AI models developed by OpenAI for a variety of tasks. + +[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. From 61c31d1e8830b205ba220da50ffcc0b397bdf430 Mon Sep 17 00:00:00 2001 From: sameerajayasoma Date: Mon, 26 Jun 2023 13:53:45 +0530 Subject: [PATCH 2/4] Add README content to the OpenAPI chat library --- openapi/openai.chat/README.md | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 openapi/openai.chat/README.md diff --git a/openapi/openai.chat/README.md b/openapi/openai.chat/README.md new file mode 100644 index 000000000..20896764d --- /dev/null +++ b/openapi/openai.chat/README.md @@ -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). The OpenAI Chat API provides a way to access the state-of-the-art ChatGPT models developed by OpenAI for a variety of tasks. + +[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. From f9e33eacd9cb6b27aabc15471a855b35ffad7107 Mon Sep 17 00:00:00 2001 From: sameerajayasoma Date: Mon, 26 Jun 2023 16:32:22 +0530 Subject: [PATCH 3/4] Update README content --- openapi/openai.chat/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi/openai.chat/README.md b/openapi/openai.chat/README.md index 20896764d..cb569327c 100644 --- a/openapi/openai.chat/README.md +++ b/openapi/openai.chat/README.md @@ -1,5 +1,5 @@ ## Overview -This is a community-maintained [Ballerina](https://ballerina.io) connector for the [OpenAI Chat API](https://platform.openai.com/docs/api-reference/chat). The OpenAI Chat API provides a way to access the state-of-the-art ChatGPT models developed by OpenAI for a variety of tasks. +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) From 8663bec28236335daae86e46c376c8f38ea90b1c Mon Sep 17 00:00:00 2001 From: sameerajayasoma Date: Mon, 26 Jun 2023 16:33:17 +0530 Subject: [PATCH 4/4] 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)