Skip to content

Commit

Permalink
Merge pull request #2 from manodyaSenevirathne/client_gen
Browse files Browse the repository at this point in the history
Add OpenAPI Spec, Generate Client Code and Sanitations
  • Loading branch information
NipunaRanasinghe authored Aug 8, 2024
2 parents c480fa5 + 56f6903 commit d7979a9
Show file tree
Hide file tree
Showing 8 changed files with 15,124 additions and 12 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@

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

# Ignore ballerina files
accessToken.bal
temp.bal.ballerina/
target/
generated/
.DS_Store
*Ballerina.lock
.ballerina
**/Config.toml
302 changes: 302 additions & 0 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
# AUTO-GENERATED FILE. DO NOT MODIFY.

# This file is auto-generated by Ballerina for managing dependency versions.
# It should not be modified by hand.

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.2"

[[package]]
org = "ballerina"
name = "auth"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"}
]

[[package]]
org = "ballerina"
name = "cache"
version = "3.8.0"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "task"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "constraint"
version = "1.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "constraint", moduleName = "constraint"}
]

[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "file"
version = "1.9.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "os"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "http"
version = "2.11.3"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "jwt"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.decimal"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "lang.regexp"},
{org = "ballerina", name = "lang.runtime"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "oauth2"},
{org = "ballerina", name = "observe"},
{org = "ballerina", name = "time"},
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
org = "ballerina"
name = "io"
version = "1.6.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]

[[package]]
org = "ballerina"
name = "jballerina.java"
version = "0.0.0"

[[package]]
org = "ballerina"
name = "jwt"
version = "2.12.1"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.decimal"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.int"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"

[[package]]
org = "ballerina"
name = "lang.regexp"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.runtime"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.string"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.regexp"}
]

[[package]]
org = "ballerina"
name = "lang.value"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "log"
version = "2.9.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "observe"}
]

[[package]]
org = "ballerina"
name = "mime"
version = "2.9.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.int"}
]

[[package]]
org = "ballerina"
name = "oauth2"
version = "2.11.0"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "time"},
{org = "ballerina", name = "url"}
]

[[package]]
org = "ballerina"
name = "observe"
version = "1.2.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "os"
version = "1.8.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "task"
version = "2.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "time"
version = "2.4.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "url"
version = "2.4.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "url", moduleName = "url"}
]

[[package]]
org = "ballerinai"
name = "observe"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "observe"}
]
modules = [
{org = "ballerinai", packageName = "observe", moduleName = "observe"}
]

[[package]]
org = "ballerinax"
name = "openai.chat"
version = "2.0.1"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
{org = "ballerina", name = "url"},
{org = "ballerinai", name = "observe"}
]
modules = [
{org = "ballerinax", packageName = "openai.chat", moduleName = "openai.chat"}
]

56 changes: 55 additions & 1 deletion ballerina/client.bal
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// AUTO-GENERATED FILE. DO NOT MODIFY.
// This file is auto-generated by the Ballerina OpenAPI tool.

// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
Expand All @@ -12,4 +15,55 @@
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// under the License.

import ballerina/http;

# The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
public isolated client class Client {
final http:Client clientEp;
# Gets invoked to initialize the `connector`.
#
# + config - The configurations to be used when initializing the `connector`
# + serviceUrl - URL of the target service
# + return - An error if connector initialization failed
public isolated function init(ConnectionConfig config, string serviceUrl = "https://api.openai.com/v1") returns error? {
http:ClientConfiguration httpClientConfig = {auth: config.auth, httpVersion: config.httpVersion, timeout: config.timeout, forwarded: config.forwarded, poolConfig: config.poolConfig, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, validation: config.validation};
do {
if config.http1Settings is ClientHttp1Settings {
ClientHttp1Settings settings = check config.http1Settings.ensureType(ClientHttp1Settings);
httpClientConfig.http1Settings = {...settings};
}
if config.http2Settings is http:ClientHttp2Settings {
httpClientConfig.http2Settings = check config.http2Settings.ensureType(http:ClientHttp2Settings);
}
if config.cache is http:CacheConfig {
httpClientConfig.cache = check config.cache.ensureType(http:CacheConfig);
}
if config.responseLimits is http:ResponseLimitConfigs {
httpClientConfig.responseLimits = check config.responseLimits.ensureType(http:ResponseLimitConfigs);
}
if config.secureSocket is http:ClientSecureSocket {
httpClientConfig.secureSocket = check config.secureSocket.ensureType(http:ClientSecureSocket);
}
if config.proxy is http:ProxyConfig {
httpClientConfig.proxy = check config.proxy.ensureType(http:ProxyConfig);
}
}
http:Client httpEp = check new (serviceUrl, httpClientConfig);
self.clientEp = httpEp;
return;
}

# Creates a model response for the given chat conversation.
#
# + headers - Headers to be sent with the request
# + return - OK
resource isolated function post chat/completions(CreateChatCompletionRequest payload, map<string|string[]> headers = {}) returns CreateChatCompletionResponse|error {
string resourcePath = string `/chat/completions`;
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
return self.clientEp->post(resourcePath, request, headers);
}
}
Binary file added ballerina/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d7979a9

Please sign in to comment.