Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation #4

Merged
merged 18 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Compiled class file
*.class

*.balx
# Log file
*.log

Expand All @@ -10,15 +10,49 @@
# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
# .DS_Store files
*.DS_Store

# Package Files
*.jar
!gradle/wrapper/gradle-wrapper.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
*.deb

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

# Ignore everything in this directory
target
.classpath
.settings
.project
*.iml
*.iws
*.ipr
.idea
.m2
.vscode/

# Ignore ballerina files
accessToken.bal
temp.bal.ballerina/
target/
generated/
.DS_Store
*Ballerina.lock
.ballerina
**/Config.toml

# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

# Ignore Docker env file
docker.env
92 changes: 89 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<img src=https://github.com/user-attachments/assets/b2e09c6d-c15f-4cfa-a596-6328b1383162 alt="OpenAI Platform" style="width: 70%;">


3. Click on the "Create new secret key" button
<img src=https://github.com/user-attachments/assets/bf1adab4-5e3f-4094-9a56-5b4c3cc3c19e alt="OpenAI Platform" style="width: 70%;">


4. Fill the details and click on Create secret key
<img src=https://github.com/user-attachments/assets/1c565923-e968-4d5f-9864-7ed2022b8079 alt="OpenAI Platform" style="width: 70%;">


5. Store the API key securely to use in your application
<img src=https://github.com/user-attachments/assets/bbbf8f38-d551-40ee-9664-f4cf2bd98997 alt="OpenAI Platform" style="width: 70%;">


## 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<string|string[]> 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

Expand Down
95 changes: 91 additions & 4 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
@@ -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
<img src=https://github.com/user-attachments/assets/b2e09c6d-c15f-4cfa-a596-6328b1383162 alt="OpenAI Platform" style="width: 70%;">


3. Click on the "Create new secret key" button
<img src=https://github.com/user-attachments/assets/bf1adab4-5e3f-4094-9a56-5b4c3cc3c19e alt="OpenAI Platform" style="width: 70%;">


4. Fill the details and click on Create secret key
<img src=https://github.com/user-attachments/assets/1c565923-e968-4d5f-9864-7ed2022b8079 alt="OpenAI Platform" style="width: 70%;">


5. Store the API key securely to use in your application
<img src=https://github.com/user-attachments/assets/bbbf8f38-d551-40ee-9664-f4cf2bd98997 alt="OpenAI Platform" style="width: 70%;">

## 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<string|string[]> 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)
93 changes: 89 additions & 4 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
@@ -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
<img src=https://github.com/user-attachments/assets/b2e09c6d-c15f-4cfa-a596-6328b1383162 alt="OpenAI Platform" style="width: 70%;">


3. Click on the "Create new secret key" button
<img src=https://github.com/user-attachments/assets/bf1adab4-5e3f-4094-9a56-5b4c3cc3c19e alt="OpenAI Platform" style="width: 70%;">


4. Fill the details and click on Create secret key
<img src=https://github.com/user-attachments/assets/1c565923-e968-4d5f-9864-7ed2022b8079 alt="OpenAI Platform" style="width: 70%;">


5. Store the API key securely to use in your application
<img src=https://github.com/user-attachments/assets/bbbf8f38-d551-40ee-9664-f4cf2bd98997 alt="OpenAI Platform" style="width: 70%;">

## 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<string|string[]> 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)
Loading