diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 2962bfd..8ecab42 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -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: @@ -71,15 +71,15 @@ Alternatively, you can set your authentication credentials as environment variab For Linux or macOS: ```bash -export isLiveServer=true -export token="" +export IS_LIVE_SERVER=true +export OPENAI_TOKEN="" ``` For Windows: ```bash -setx isLiveServer true -setx token +setx IS_LIVE_SERVER true +setx OPENAI_TOKEN ``` Then, run the following command to execute the tests: diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index 0a5276a..f563898 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -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(); diff --git a/ballerina/types.bal b/ballerina/types.bal index 26deea8..fc40d30 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -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; @@ -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?; }; @@ -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; @@ -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; @@ -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?; diff --git a/docs/setup/resources/api-key-dashboard.png b/docs/setup/resources/api-key-dashboard.png index 0a66883..5239d1a 100644 Binary files a/docs/setup/resources/api-key-dashboard.png and b/docs/setup/resources/api-key-dashboard.png differ diff --git a/docs/setup/resources/create-new-secret-key.png b/docs/setup/resources/create-new-secret-key.png index 5492f4a..70daf70 100644 Binary files a/docs/setup/resources/create-new-secret-key.png and b/docs/setup/resources/create-new-secret-key.png differ diff --git a/docs/setup/resources/navigate-api-key-dashboard.png b/docs/setup/resources/navigate-api-key-dashboard.png index f42cb48..7b0d1bd 100644 Binary files a/docs/setup/resources/navigate-api-key-dashboard.png and b/docs/setup/resources/navigate-api-key-dashboard.png differ diff --git a/docs/setup/resources/saved-key.png b/docs/setup/resources/saved-key.png index 7ed28c7..87aaf88 100644 Binary files a/docs/setup/resources/saved-key.png and b/docs/setup/resources/saved-key.png differ diff --git a/docs/spec/openapi.yaml b/docs/spec/openapi.yaml index 5b3a8b2..1e0945a 100644 --- a/docs/spec/openapi.yaml +++ b/docs/spec/openapi.yaml @@ -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: @@ -7760,7 +7760,7 @@ components: ChatCompletionRequestFunctionMessage: type: object title: Function message - # deprecated: true + deprecated: true properties: role: type: string @@ -7785,7 +7785,7 @@ components: ChatCompletionFunctions: type: object - # deprecated: true + deprecated: true properties: description: type: string @@ -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: @@ -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: @@ -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`. @@ -8222,7 +8222,7 @@ components: - $ref: "#/components/schemas/ChatCompletionFunctionCallOption" x-oaiExpandable: true functions: - # deprecated: true + deprecated: true description: | Deprecated in favor of `tools`. @@ -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 @@ -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 diff --git a/docs/spec/sanitations.md b/docs/spec/sanitations.md index b52fc53..423e839 100644 --- a/docs/spec/sanitations.md +++ b/docs/spec/sanitations.md @@ -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 @@ -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` @@ -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 diff --git a/examples/cli-assistant/main.bal b/examples/cli-assistant/main.bal index 1b4182d..cd53cb7 100644 --- a/examples/cli-assistant/main.bal +++ b/examples/cli-assistant/main.bal @@ -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 { @@ -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: [ @@ -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 { @@ -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."); diff --git a/examples/image-to-markdown-converter/main.bal b/examples/image-to-markdown-converter/main.bal index 0d34f34..47a7f65 100644 --- a/examples/image-to-markdown-converter/main.bal +++ b/examples/image-to-markdown-converter/main.bal @@ -19,9 +19,9 @@ 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); @@ -29,7 +29,7 @@ public function main() returns error? { io:println(base64Image); return; } - string|error markdownDoc = generateDocumentation(base64Image); + string|error markdownDoc = generateDocumentation(base64Image, openAIChat); if markdownDoc is error { io:println(markdownDoc); @@ -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 = {