Skip to content

Commit

Permalink
Merge pull request #21 from SanduniU/final-fixes
Browse files Browse the repository at this point in the history
Move the client initialization to main function
  • Loading branch information
NipunaRanasinghe authored Aug 21, 2024
2 parents c3a9afe + 54e2bde commit d384c76
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 41 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@ The `ballarinax/openai.assistants` connector allows developers to seamlessly int

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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/navigate-api-key-dashboard.png 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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/api-key-dashboard.png 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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/create-new-secret-key.png 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%;">
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/saved-key.png alt="OpenAI Platform" style="width: 70%;">


## Quickstart
Expand Down
15 changes: 5 additions & 10 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,20 @@ The `ballarinax/openai.assistants` connector allows developers to seamlessly int

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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/navigate-api-key-dashboard.png 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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/api-key-dashboard.png 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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/create-new-secret-key.png 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%;">
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/saved-key.png alt="OpenAI Platform" style="width: 70%;">


## Quickstart

Expand Down
14 changes: 5 additions & 9 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ The `ballarinax/openai.assistants` connector allows developers to seamlessly int

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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/navigate-api-key-dashboard.png 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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/api-key-dashboard.png 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%;">

<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/create-new-secret-key.png 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%;">
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-openai.assistants/main/docs/setup/resources/saved-key.png alt="OpenAI Platform" style="width: 70%;">


## Quickstart

Expand Down
Binary file added docs/setup/resources/api-key-dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/setup/resources/create-new-secret-key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/setup/resources/saved-key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions examples/math-tutor-bot/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import ballerinax/openai.assistants;
// Define configuration and client setup
configurable string token = ?;

final assistants:Client openaiAssistant = check new ({
auth: {
token
}
});

final map<string|string[]> headers = {
"OpenAI-Beta": ["assistants=v2"]
};

public function main() returns error? {
// Define the client to interact with the OpenAI Assistants API
final assistants:Client openaiAssistant = check new ({
auth: {
token
}
});
// Step 1: Create a new Math Assistant
assistants:AssistantToolsCode codeTool = {
'type: "code_interpreter"
Expand Down
13 changes: 6 additions & 7 deletions examples/weather-assistant/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ import ballerinax/openai.assistants;

configurable string token = ?;

// Define the client to interact with the OpenAI Assistants API
final assistants:Client openaiAssistant = check new ({
auth: {
token
}
});

final map<string|string[]> headers = {
"OpenAI-Beta": ["assistants=v2"]
};

public function main() returns error? {
// Define the client to interact with the OpenAI Assistants API
final assistants:Client openaiAssistant = check new ({
auth: {
token
}
});
// Step 1: Create the weather assistant
assistants:FunctionObject getTemperature = {
name: "get_temperature",
Expand Down

0 comments on commit d384c76

Please sign in to comment.