diff --git a/README.md b/README.md index f5eefcd..7091953 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,101 @@ ## Overview -[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.) +OpenAI is an American artificial intelligence research organization that comprises both a non-profit and a for-profit entity. The organization focuses on conducting cutting-edge AI research with the goal of developing friendly AI that benefits humanity. By advancing the state of AI, OpenAI aims to ensure that powerful AI technologies are used responsibly and ethically, promoting innovation while addressing potential risks. + +The `ballarinax/openai.Assistants` connector allows developers to seamlessly integrate OpenAI's advanced language models into their applications by interacting with [OpenAI REST API v1](https://platform.openai.com/docs/api-reference/assistants). This connector provides tools to build powerful [OpenAI Assistants](https://platform.openai.com/docs/assistants/overview) capable of performing a wide range of tasks, such as generating human-like text, managing conversations with persistent threads, and utilizing multiple tools in parallel. OpenAI has recently announced a variety of new features and improvements to the Assistants API, moving their Beta to a [new API version](https://platform.openai.com/docs/assistants/whats-new), `OpenAI-Beta: assistants=v2`. The users can interact with both the API v1 and v2 by [passing the respective API version header in the request](https://platform.openai.com/docs/assistants/migration/changing-beta-versions) + ## 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). + + +1. Open the [OpenAI Platform Dashboard](https://platform.openai.com). + + +2. Navigate to Dashboard -> API keys +OpenAI Platform + + +3. Click on the "Create new secret key" button +OpenAI Platform + + +4. Fill the details and click on Create secret key +OpenAI Platform + + +5. Store the API key securely to use in your application +OpenAI Platform + ## Quickstart -[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.) +To use the `OpenAI Assistants` connector in your Ballerina application, update the `.bal` file as follows: +### Step 1: Import the module + +Import the `openai.assistants` module. + +```ballerina +import ballerinax/openai.assistants; +``` + +### Step 2: Instantiate a new connector + +Create a `assistants:ConnectionConfig` with the obtained access token and initialize the connector with it. + +```ballerina +configurable string token = ?; + +final assistants:Client openAIAssistant = check new ({ + auth: { + token + } +}); +``` + +#### Setting HTTP Headers in Ballerina + +Calls to the Assistants API require that you pass a beta HTTP header. In Ballerina, you can define the header as follows: + +```ballerina +final map headers = { + "OpenAI-Beta": ["assistants=v2"] +}; +``` + +### Step 3: Invoke the connector operations + +Now, utilize the available connector operations. + +```ballerina +public function main() returns error? { + + // define the required tool + assistants:AssistantToolsCode tool = { + type: "code_interpreter" + }; + + // define the assistant request object + assistants:CreateAssistantRequest request = { + model: "gpt-3.5-turbo", + name: "Math Tutor", + description: "An Assistant for personal math tutoring", + instructions: "You are a personal math tutor. Help the user with their math questions.", + tools: [tool] + }; + + // call the `post assistants` resource to create an Assistant + assistants:AssistantObject assistantResponse = check openAIAssistant->/assistants.post(request, headers); +} +``` + +### Step 4: Run the Ballerina application + +```bash +bal run +``` ## Examples diff --git a/ballerina/Module.md b/ballerina/Module.md index e62514e..c71541a 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -1,17 +1,104 @@ ## Overview -[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.) +OpenAI is an American artificial intelligence research organization that comprises both a non-profit and a for-profit entity. The organization focuses on conducting cutting-edge AI research with the goal of developing friendly AI that benefits humanity. By advancing the state of AI, OpenAI aims to ensure that powerful AI technologies are used responsibly and ethically, promoting innovation while addressing potential risks. + +The `ballarinax/openai.Assistants` connector allows developers to seamlessly integrate OpenAI's advanced language models into their applications by interacting with [OpenAI REST API v1](https://platform.openai.com/docs/api-reference/assistants). This connector provides tools to build powerful [OpenAI Assistants](https://platform.openai.com/docs/assistants/overview) capable of performing a wide range of tasks, such as generating human-like text, managing conversations with persistent threads, and utilizing multiple tools in parallel. OpenAI has recently announced a variety of new features and improvements to the Assistants API, moving their Beta to a [new API version](https://platform.openai.com/docs/assistants/whats-new), `OpenAI-Beta: assistants=v2`. The users can interact with both the API v1 and v2 by [passing the respective API version header in the request](https://platform.openai.com/docs/assistants/migration/changing-beta-versions) + ## 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 +OpenAI Platform + + +3. Click on the "Create new secret key" button +OpenAI Platform + + +4. Fill the details and click on Create secret key +OpenAI Platform + + +5. Store the API key securely to use in your application +OpenAI Platform ## Quickstart -[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.) +To use the `OpenAI Assistants` connector in your Ballerina application, update the `.bal` file as follows: +### Step 1: Import the module + +Import the `openai.assistants` module. + +```ballerina +import ballerinax/openai.assistants; +``` + +### Step 2: Instantiate a new connector + +Create a `assistants:ConnectionConfig` with the obtained access token and initialize the connector with it. + +```ballerina +configurable string token = ?; + +final assistants:Client openAIAssistant = check new ({ + auth: { + token + } +}); +``` + +#### Setting HTTP Headers in Ballerina + +Calls to the Assistants API require that you pass a beta HTTP header. In Ballerina, you can define the header as follows: + +```ballerina +final map headers = { + "OpenAI-Beta": ["assistants=v2"] +}; +``` + +### Step 3: Invoke the connector operations + +Now, utilize the available connector operations. + + +```ballerina +public function main() returns error? { + + // define the required tool + assistants:AssistantToolsCode tool = { + type: "code_interpreter" + }; + + // define the assistant request object + assistants:CreateAssistantRequest request = { + model: "gpt-3.5-turbo", + name: "Math Tutor", + description: "An Assistant for personal math tutoring", + instructions: "You are a personal math tutor. Help the user with their math questions.", + tools: [tool] + }; + + // call the `post assistants` resource to create an Assistant + assistants:AssistantObject assistantResponse = check openAIAssistant->/assistants.post(request, headers); +} +``` + +### Step 4: Run the Ballerina application + +```bash +bal run +``` ## Examples -The `OpenAI Assistants` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-openai.assistants/tree/main/examples/), covering the following use cases: +The `OpenAI Assistants` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-openai-assistants/tree/main/examples/), covering the following use cases: [//]: # (TODO: Add examples) \ No newline at end of file diff --git a/ballerina/Package.md b/ballerina/Package.md index e62514e..f1e2f21 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -1,17 +1,102 @@ ## Overview -[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.) +OpenAI is an American artificial intelligence research organization that comprises both a non-profit and a for-profit entity. The organization focuses on conducting cutting-edge AI research with the goal of developing friendly AI that benefits humanity. By advancing the state of AI, OpenAI aims to ensure that powerful AI technologies are used responsibly and ethically, promoting innovation while addressing potential risks. + +The `ballarinax/openai.Assistants` connector allows developers to seamlessly integrate OpenAI's advanced language models into their applications by interacting with [OpenAI REST API v1](https://platform.openai.com/docs/api-reference/assistants). This connector provides tools to build powerful [OpenAI Assistants](https://platform.openai.com/docs/assistants/overview) capable of performing a wide range of tasks, such as generating human-like text, managing conversations with persistent threads, and utilizing multiple tools in parallel. OpenAI has recently announced a variety of new features and improvements to the Assistants API, moving their Beta to a [new API version](https://platform.openai.com/docs/assistants/whats-new), `OpenAI-Beta: assistants=v2`. The users can interact with both the API v1 and v2 by [passing the respective API version header in the request](https://platform.openai.com/docs/assistants/migration/changing-beta-versions) ## 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 +OpenAI Platform + + +3. Click on the "Create new secret key" button +OpenAI Platform + + +4. Fill the details and click on Create secret key +OpenAI Platform + + +5. Store the API key securely to use in your application +OpenAI Platform ## Quickstart -[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.) +To use the `OpenAI Assistants` connector in your Ballerina application, update the `.bal` file as follows: +### Step 1: Import the module + +Import the `openai.assistants` module. + +```ballerina +import ballerinax/openai.assistants; +``` + +### Step 2: Instantiate a new connector + +Create a `assistants:ConnectionConfig` with the obtained access token and initialize the connector with it. + +```ballerina +configurable string token = ?; + +final assistants:Client openAIAssistant = check new ({ + auth: { + token + } +}); +``` + +#### Setting HTTP Headers in Ballerina + +Calls to the Assistants API require that you pass a beta HTTP header. In Ballerina, you can define the header as follows: + +```ballerina +final map headers = { + "OpenAI-Beta": ["assistants=v2"] +}; +``` + +### Step 3: Invoke the connector operations + +Now, utilize the available connector operations. + + +```ballerina +public function main() returns error? { + + // define the required tool + assistants:AssistantToolsCode tool = { + type: "code_interpreter" + }; + + // define the assistant request object + assistants:CreateAssistantRequest request = { + model: "gpt-3.5-turbo", + name: "Math Tutor", + description: "An Assistant for personal math tutoring", + instructions: "You are a personal math tutor. Help the user with their math questions.", + tools: [tool] + }; + + // call the `post assistants` resource to create an Assistant + assistants:AssistantObject assistantResponse = check openAIAssistant->/assistants.post(request, headers); +} +``` + +### Step 4: Run the Ballerina application + +```bash +bal run +``` ## Examples -The `OpenAI Assistants` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-openai.assistants/tree/main/examples/), covering the following use cases: +The `OpenAI Assistants` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-openai-assistants/tree/main/examples/), covering the following use cases: [//]: # (TODO: Add examples) \ No newline at end of file