Skip to content

Commit

Permalink
Merge pull request #15 from manodyaSenevirathne/main
Browse files Browse the repository at this point in the history
Suggested Changes
  • Loading branch information
NipunaRanasinghe authored Aug 21, 2024
2 parents 7decfd4 + 35fae51 commit 31ca90c
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 42 deletions.
12 changes: 6 additions & 6 deletions ballerina/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ Alternatively, you can set the environment variable directly.
For Linux or macOS:

```bash
export isLiveServer=false
export IS_LIVE_SERVER=false
```

For Windows:

```bash
setx isLiveServer false
setx IS_LIVE_SERVER false
```

Then, run the following command to execute the tests:
Expand All @@ -71,15 +71,15 @@ Alternatively, you can set your authentication credentials as environment variab
For Linux or macOS:

```bash
export isLiveServer=true
export token="<your-openAI-api-token>"
export IS_LIVE_SERVER=true
export OPENAI_TOKEN="<your-openAI-api-token>"
```

For Windows:

```bash
setx isLiveServer true
setx token <your-openAI-api-token>
setx IS_LIVE_SERVER true
setx OPENAI_TOKEN <your-openAI-api-token>
```

Then, run the following command to execute the tests:
Expand Down
4 changes: 2 additions & 2 deletions ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import ballerina/os;
import ballerina/test;

configurable boolean isLiveServer = os:getEnv("isLiveServer") == "true";
configurable string token = isLiveServer ? os:getEnv("token") : "test";
configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true";
configurable string token = isLiveServer ? os:getEnv("OPENAI_TOKEN") : "test";
final string mockServiceUrl = "http://localhost:9090";
final Client openAIChat = check initClient();

Expand Down
14 changes: 14 additions & 0 deletions ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import ballerina/constraint;
import ballerina/http;

# Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.
#
# # Deprecated
@deprecated
public type ChatCompletionRequestAssistantMessage_function_call record {
# The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
string arguments;
Expand Down Expand Up @@ -151,11 +154,17 @@ public type CreateChatCompletionRequest record {
# Specifying a particular function via `{"name": "my_function"}` forces the model to call that function.
#
# `none` is the default when no functions are present. `auto` is the default if functions are present.
#
# # Deprecated
@deprecated
"none"|"auto"|ChatCompletionFunctionCallOption function_call?;
# Deprecated in favor of `tools`.
#
# A list of functions the model may generate JSON inputs for.
#
# # Deprecated
@constraint:Array {maxLength: 128, minLength: 1}
@deprecated
ChatCompletionFunctions[] functions?;
};

Expand Down Expand Up @@ -186,6 +195,9 @@ public type ChatCompletionRequestAssistantMessage record {
public type ChatCompletionToolChoiceOption "none"|"auto"|"required"|ChatCompletionNamedToolChoice;

# Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.
#
# # Deprecated
@deprecated
public type ChatCompletionResponseMessage_function_call record {
# The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
string arguments;
Expand Down Expand Up @@ -276,6 +288,7 @@ public type CreateChatCompletionResponse record {
CompletionUsage usage?;
};

@deprecated
public type ChatCompletionRequestFunctionMessage record {
# The role of the messages author, in this case `function`.
"function" role;
Expand All @@ -300,6 +313,7 @@ public type ChatCompletionRequestToolMessage record {
string tool_call_id;
};

@deprecated
public type ChatCompletionFunctions record {
# A description of what the function does, used by the model to choose when and how to call the function.
string description?;
Expand Down
Binary file modified 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 modified 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.
Binary file modified docs/setup/resources/navigate-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 modified 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.
20 changes: 10 additions & 10 deletions docs/spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7708,7 +7708,7 @@ components:
$ref: "#/components/schemas/ChatCompletionMessageToolCalls"
function_call:
type: object
# deprecated: true
deprecated: true
description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model."
nullable: true
properties:
Expand Down Expand Up @@ -7760,7 +7760,7 @@ components:
ChatCompletionRequestFunctionMessage:
type: object
title: Function message
# deprecated: true
deprecated: true
properties:
role:
type: string
Expand All @@ -7785,7 +7785,7 @@ components:

ChatCompletionFunctions:
type: object
# deprecated: true
deprecated: true
properties:
description:
type: string
Expand Down Expand Up @@ -7978,7 +7978,7 @@ components:
description: The role of the author of this message.
function_call:
type: object
# deprecated: true
deprecated: true
description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model."
properties:
arguments:
Expand All @@ -8003,7 +8003,7 @@ components:
description: The contents of the chunk message.
nullable: true
function_call:
# deprecated: true
deprecated: true
type: object
description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model."
properties:
Expand Down Expand Up @@ -8203,7 +8203,7 @@ components:
$ref: "#/components/schemas/ParallelToolCalls"
user: *end_user_param_configuration
function_call:
# deprecated: true
deprecated: true
description: |
Deprecated in favor of `tool_choice`.

Expand All @@ -8222,7 +8222,7 @@ components:
- $ref: "#/components/schemas/ChatCompletionFunctionCallOption"
x-oaiExpandable: true
functions:
# deprecated: true
deprecated: true
description: |
Deprecated in favor of `tools`.

Expand Down Expand Up @@ -9586,12 +9586,12 @@ components:
]
status:
type: string
# deprecated: true
deprecated: true
description: Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
enum: ["uploaded", "processed", "error"]
status_details:
type: string
# deprecated: true
deprecated: true
description: Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
required:
- id
Expand Down Expand Up @@ -10052,7 +10052,7 @@ components:
parallel_tool_calls:
$ref: "#/components/schemas/ParallelToolCalls"
functions:
# deprecated: true
deprecated: true
description:
A list of functions the model may generate JSON inputs for.
type: array
Expand Down
19 changes: 3 additions & 16 deletions docs/spec/sanitations.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_Authors_: @manodyaSenevirathne \
_Created_: 2024/08/05 \
_Updated_: 2024/08/05 \
_Updated_: 2024/08/21 \
_Edition_: Swan Lake

# Sanitation for OpenAPI specification
Expand All @@ -9,20 +9,7 @@ This document records the sanitation done on top of the official OpenAPI specifi
The OpenAPI specification is obtained from the [OpenAPI specification for the OpenAI API](https://github.com/openai/openai-openapi/blob/master/openapi.yaml).
These changes are done in order to improve the overall usability, and as workarounds for some known language limitations.

1. **Removed the `Deprecated: true` property from the below schemas**:

- **Changed Schemas**: `ChatCompletionRequestAssistantMessage`,`ChatCompletionRequestFunctionMessage`,`ChatCompletionFunctions`,`ChatCompletionResponseMessage`,`ChatCompletionStreamResponseDelta`,`CreateChatCompletionRequest`

- **Original**:
- `Deprecated: true`

- **Updated**:
- Removed the `deprecated` parameter

- **Reasons**: The original configuration was generated successfully, but it led to compile-time warnings. To ensure smoother compilation and avoid potential issues, the configuration has been revised.


2. **Removed the `default:null` property of from the below schemas**:
1. **Removed the `default:null` property of from the below schemas**:

- **Changed Schemas**: `CreateCompletionRequest`,`ChatCompletionStreamOptions`,`CreateChatCompletionRequest`

Expand All @@ -32,7 +19,7 @@ These changes are done in order to improve the overall usability, and as workaro
- **Updated**:
- Removed the `default` parameter

- **Reason**: This change is done as a workaround for ballerina openapi tool not allowing to generate the client.
- **Reason**: This change is done as a temporary workaround until the Ballerina OpenAPI tool supports OpenAPI Specification version v3.1.x (Currently supported upto version 3.0.0).

## OpenAPI cli command

Expand Down
10 changes: 5 additions & 5 deletions examples/cli-assistant/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import ballerina/os;
import ballerinax/openai.chat;

configurable string token = ?;
final chat:Client openAIChat = check new ({auth: {token}});

public function main() returns error? {
final chat:Client openAIChat = check new ({auth: {token}});
string osType = getOSType();
string taskDescription = getTaskDescription();
string|error command = generateCLICommand(osType, taskDescription);
string|error command = generateCLICommand(osType, taskDescription, openAIChat);

// if the command generation was unsuccessful, terminate the program
if command is error {
Expand Down Expand Up @@ -70,7 +70,7 @@ function getTaskDescription() returns string {
return taskDescription;
}

function generateCLICommand(string osType, string taskDescription) returns string|error {
function generateCLICommand(string osType, string taskDescription, chat:Client openAIChat) returns string|error {
chat:CreateChatCompletionRequest request = {
model: "gpt-4o-mini",
messages: [
Expand Down Expand Up @@ -102,7 +102,7 @@ function executeCommand(string command, string osType) returns error? {
io:println("Executing command...");

string[] cmdArray;
if (osType == "windows") {
if osType == "windows" {
// Use PowerShell to execute the command on Windows
cmdArray = ["powershell", "-Command", command];
} else {
Expand All @@ -113,7 +113,7 @@ function executeCommand(string command, string osType) returns error? {
os:Process exec = check os:exec({value: cmdArray[0], arguments: cmdArray.slice(1)});

int status = check exec.waitForExit();
if (status != 0) {
if status != 0 {
io:println(string `Process exited with status: ${status}. The command may have failed.`);
} else {
io:println("Process executed successfully.");
Expand Down
6 changes: 3 additions & 3 deletions examples/image-to-markdown-converter/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import ballerina/io;
import ballerinax/openai.chat;

configurable string token = ?;
final chat:Client openAIChat = check new ({auth: {token}});

public function main() returns error? {
final chat:Client openAIChat = check new ({auth: {token}});
string imagePath = getImageFilePath();
string|error base64Image = encodeImageToBase64(imagePath);

if base64Image is error {
io:println(base64Image);
return;
}
string|error markdownDoc = generateDocumentation(base64Image);
string|error markdownDoc = generateDocumentation(base64Image, openAIChat);

if markdownDoc is error {
io:println(markdownDoc);
Expand All @@ -49,7 +49,7 @@ function encodeImageToBase64(string imagePath) returns string|error {
return imageBytes.toBase64();
}

function generateDocumentation(string base64Image) returns string|error {
function generateDocumentation(string base64Image, chat:Client openAIChat) returns string|error {
string prompt = "Generate markdown documentation based on the content of the following image. Include detailed descriptions of any diagrams, notes, or code snippets present. Structure the documentation with appropriate headings, and provide a summary of the key concepts discussed. Additionally, include any relevant annotations or comments that might aid in understanding the content";

chat:CreateChatCompletionRequest request = {
Expand Down

0 comments on commit 31ca90c

Please sign in to comment.