Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aneeshafedo committed May 8, 2023
1 parent 202e755 commit ee17986
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public Object[][] fileProviderForFilesComparison() {
{"api2pdf.yaml", "api2pdf.bal"},
{"nillable_response.yaml", "nillable_response.bal"},
{"nillable_union_response.yaml", "nillable_union_response.bal"},
{"duplicated_response.yaml", "duplicated_response.bal"}
{"duplicated_response.yaml", "duplicated_response.bal"},
{"multiline_param_comment.yaml", "multiline_param_comment.bal"}
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import ballerina/http;

# APIs for fine-tuning and managing deployments of OpenAI models.
public isolated client class Client {
final http:Client clientEp;
final readonly & ApiKeysConfig apiKeyConfig;
# Gets invoked to initialize the `connector`.
#
# + apiKeyConfig - API keys for authorization
# + 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(ApiKeysConfig apiKeyConfig, string serviceUrl, ConnectionConfig config = {}) returns error? {
http:ClientConfiguration httpClientConfig = {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;
self.apiKeyConfig = apiKeyConfig.cloneReadOnly();
return;
}
# Gets the events for the fine-tune job specified by the given fine-tune-id.
# Events are created when the job status changes, e.g. running or complete, and when results are uploaded.
#
# + fineTuneId - The identifier of the fine-tune job.
# + 'stream - A flag indicating whether to stream events for the fine-tune job. If set to true,
# events will be sent as data-only server-sent events as they become available. The stream will terminate with
# a data: [DONE] message when the job is finished (succeeded, cancelled, or failed).
# If set to false, only events generated so far will be returned..
# + apiVersion - The requested API version.
# + return - Success
remote isolated function fineTunes_GetEvents(string fineTuneId, string apiVersion, boolean? 'stream = ()) returns EventList|error {
string resourcePath = string `/fine-tunes/${getEncodedUri(fineTuneId)}/events`;
map<anydata> queryParam = {"stream": 'stream, "api-version": apiVersion};
resourcePath = resourcePath + check getPathForQueryParam(queryParam);
map<any> headerValues = {"api-key": self.apiKeyConfig.apiKey};
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
EventList response = check self.clientEp->get(resourcePath, httpHeaders);
return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
openapi: 3.0.1
info:
title: Azure OpenAI API version 2022-12-01
description: APIs for fine-tuning and managing deployments of OpenAI models.
version: 2022-12-01
servers:
- url: /
security:
- api-key: []
paths:
/fine-tunes/{fine-tune-id}/events:
get:
tags:
- 'Fine-tunes:'
summary: "Gets the events for the fine-tune job specified by the given fine-tune-id.\r\
\nEvents are created when the job status changes, e.g. running or complete,\
\ and when results are uploaded."
operationId: FineTunes_GetEvents
parameters:
- name: fine-tune-id
in: path
description: The identifier of the fine-tune job.
required: true
schema:
type: string
- name: stream
in: query
description: "A flag indicating whether to stream events for the fine-tune\
\ job. If set to true,\r\n events will be sent as data-only server-sent\
\ events as they become available. The stream will terminate with\r\n \
\ a data: [DONE] message when the job is finished (succeeded, cancelled,\
\ or failed).\r\n If set to false, only events generated so far\
\ will be returned.."
schema:
type: boolean
- name: api-version
in: query
description: The requested API version.
required: true
schema:
type: string
x-ms-client-default: 2022-12-01
x-ms-parameter-location: client
x-ms-client-default: 2022-12-01
x-ms-parameter-location: client
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/EventList'
text/event-stream:
schema:
$ref: '#/components/schemas/EventList'
components:
schemas:
Event:
title: Event
required:
- created_at
- level
- message
type: object
properties:
object:
$ref: '#/components/schemas/TypeDiscriminator'
created_at:
type: integer
description: A timestamp when this event was created (in unix epochs).
format: unixtime
level:
$ref: '#/components/schemas/LogLevel'
message:
minLength: 1
type: string
description: The message describing the event. This can be a change of state,
e.g., enqueued, started, failed or completed, or other events like uploaded
results.
EventList:
title: EventList
type: object
properties:
object:
$ref: '#/components/schemas/TypeDiscriminator'
data:
type: array
description: The list of items.
items:
$ref: '#/components/schemas/Event'
description: Represents a list of events.
InnerError:
title: InnerError
type: object
properties:
code:
$ref: '#/components/schemas/InnerErrorCode'
innererror:
$ref: '#/components/schemas/InnerError'
description: "Inner error as defined in the Microsoft REST guidelines\r\n(https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses)."
InnerErrorCode:
title: InnerErrorCode
type: string
description: "Inner error codes as defined in the Microsoft REST guidelines\r\
\n(https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses)."
enum:
- invalidPayload
x-ms-enum:
name: InnerErrorCode
modelAsString: true
values:
- value: invalidPayload
description: The request data is invalid for this operation.
LogLevel:
title: LogLevel
type: string
description: The verbosity level of an event.
enum:
- info
- warning
- error
x-ms-enum:
name: LogLevel
modelAsString: true
values:
- value: info
description: This event is for information only.
- value: warning
description: This event represents a mitigated issue.
- value: error
description: This message represents a non recoverable issue.
TypeDiscriminator:
title: TypeDiscriminator
type: string
description: Defines the type of an object.
enum:
- list
- fine-tune
- file
- fine-tune-event
- model
- deployment
x-ms-enum:
name: TypeDiscriminator
modelAsString: true
values:
- value: list
description: This object represents a list of other objects.
- value: fine-tune
description: This object represents a fine tune job.
- value: file
description: This object represents a file.
- value: fine-tune-event
description: This object represents an event of a fine tune job.
- value: model
description: This object represents a model (can be a base models or fine
tune job result).
- value: deployment
description: This object represents a deployment.
securitySchemes:
api-key:
type: apiKey
description: Provide your Cognitive Services Azure OpenAI account key here.
name: api-key
in: header
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ public static MarkdownDocumentationNode createAPIParamDocFromSring(String paramN
StringBuilder docComment = new StringBuilder("# + " + paramName + " - " +
paramDescriptionLines[0] + System.lineSeparator());
for (int i = 1; i < paramDescriptionLines.length; i++) {
// String line = paramDescriptionLines[i].replaceAll("[\\r\\n\\t]", "");
String line = paramDescriptionLines[i];
String line = paramDescriptionLines[i].replaceAll("[\\r\\n\\t]", "");
if (!line.isBlank()) {
docComment.append("# ").append(line).append(System.lineSeparator());
}
Expand Down

0 comments on commit ee17986

Please sign in to comment.