Skip to content

Commit

Permalink
Add test for fine-tuning job cancellation and file deletion endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
KATTA-00 committed Aug 9, 2024
1 parent 67d4796 commit 2417191
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 35 deletions.
67 changes: 55 additions & 12 deletions ballerina/tests/openapi_service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ listener http:Listener httpListener = new (9090);

http:Service mockService = service object {

// # Delete a file.
// #
// # + file_id - The ID of the file to use for this request.
// # + return - OK
// resource function delete files/[string file_id]() returns DeleteFileResponse {
// }

// # Delete a fine-tuned model. You must have the Owner role in your organization to delete a model.
// #
Expand All @@ -38,6 +32,61 @@ http:Service mockService = service object {
// resource function delete models/[string model]() returns DeleteModelResponse {
// }

# Immediately cancel a fine-tune job.
#
# + fine_tuning_job_id - The ID of the fine-tuning job to cancel.
# + return - OK
resource function post fine_tuning/jobs/[string fine_tuning_job_id]/cancel() returns OkFineTuningJob {

OkFineTuningJob response = {
body:{
"object": "fine_tuning.job",
"id": fine_tuning_job_id,
"model": "gpt-3.5-turbo-0125",
"created_at": 1723110882,
"finished_at": null,
"fine_tuned_model": null,
"organization_id": "org-Gzp0rlPk9gw4JaNXmPqDJ1H4",
"result_files": [],
"status": "validating_files",
"validation_file": null,
"training_file": "file-JZMH9Xxnt7Hg2io6N2kzmlzM",
"hyperparameters": {
"n_epochs": "auto",
"batch_size": "auto",
"learning_rate_multiplier": "auto"
},
"trained_tokens": null,
"error": {},
"user_provided_suffix": null,
"seed": 1776549854,
"estimated_finish": null,
"integrations": []
},
headers: {
"Content-Type": "application/json"
}
};

return response;
}

# Delete a file.
#
# + file_id - The ID of the file to use for this request.
# + return - OK
resource function delete files/[string file_id]() returns DeleteFileResponse {

DeleteFileResponse response = {
'object: "file",
id: file_id,
deleted: true
};

return response;

}

# Returns a list of files that belong to the user's organization.
#
# + purpose - Only return files with the given purpose.
Expand Down Expand Up @@ -369,12 +418,6 @@ http:Service mockService = service object {

}

// # Immediately cancel a fine-tune job.
// #
// # + fine_tuning_job_id - The ID of the fine-tuning job to cancel.
// # + return - OK
// resource function post fine_tuning/jobs/[string fine_tuning_job_id]/cancel() returns OkFineTuningJob {
// }
};


Expand Down
54 changes: 31 additions & 23 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ isolated function testListModels() returns error? {
test:assertTrue(modelsResponse.hasKey("data"), "Response does not have the key 'data'");
}

@test:Config {
dependsOn: [testListModels]
}
@test:Config {}
isolated function testRetrieveModel() returns error? {

ListModelsResponse modelsResponse = check baseClient->/models.get();
Expand All @@ -58,7 +56,7 @@ isolated function testRetrieveModel() returns error? {
}

// @test:Config {
// dependsOn: [testCreateFineTuningJob, testListModels]
// dependsOn: [testCreateFineTuningJob, testListModels, testRetrieveModel]
// }
// isolated function testDeleteModel() returns error? {

Expand Down Expand Up @@ -121,6 +119,13 @@ isolated function testCreateFile() returns error? {

test:assertEquals(fileResponse.purpose, "fine-tune", "Purpose mismatched");
test:assertTrue(fileResponse.id !is "", "File id is empty");

string fileId = fileResponse.id;

DeleteFileResponse fileResponseDelete = check baseClient->/files/[fileId].delete();

test:assertEquals(fileResponseDelete.id, fileId, "File id mismatched");
test:assertTrue(fileResponseDelete.hasKey("object"), "Response does not have the key 'object'");
}

@test:Config {
Expand Down Expand Up @@ -157,27 +162,27 @@ isolated function testDownloadFile() returns error? {
byte[] fileContentDownload = check baseClient->/files/[fileId]/content.get();
}

// @test:Config {
// dependsOn: [testCreateFile, testRetrieveFile, testListFiles]
// }
// isolated function testDeleteFile() returns error? {
@test:Config {
dependsOn: [testCreateFile, testRetrieveFile, testListFiles, testDownloadFile]
}
isolated function testDeleteFile() returns error? {

// byte[] fileContent = check io:fileReadBytes(fileName);
byte[] fileContent = check io:fileReadBytes(fileName);

// CreateFileRequest fileRequest = {
// file: {fileContent, fileName},
// purpose: "fine-tune"
// };
CreateFileRequest fileRequest = {
file: {fileContent, fileName},
purpose: "fine-tune"
};

// OpenAIFile fileResponse = check baseClient->/files.post(fileRequest);
OpenAIFile fileResponse = check baseClient->/files.post(fileRequest);

// string fileId = fileResponse.id;
string fileId = fileResponse.id;

// DeleteFileResponse fileResponseDelete = check baseClient->/files/[fileId].delete();
DeleteFileResponse fileResponseDelete = check baseClient->/files/[fileId].delete();

// test:assertEquals(fileResponseDelete.id, fileId, "File id mismatched");
// test:assertTrue(fileResponseDelete.hasKey("object"), "Response does not have the key 'object'");
// }
test:assertEquals(fileResponseDelete.id, fileId, "File id mismatched");
test:assertTrue(fileResponseDelete.hasKey("object"), "Response does not have the key 'object'");
}

// // Fine Tuning Jobs

Expand All @@ -191,7 +196,7 @@ isolated function testListPaginatedFineTuningJobs() returns error? {
}

@test:Config {
dependsOn: [testListPaginatedFineTuningJobs, testListModels, testCreateFile, testRetrieveFile, testListFiles]
dependsOn: [testListPaginatedFineTuningJobs, testListModels, testCreateFile, testRetrieveFile, testListFiles, testDownloadFile, testDeleteFile]
}
isolated function testCreateFineTuningJob() returns error? {

Expand Down Expand Up @@ -221,6 +226,12 @@ isolated function testCreateFineTuningJob() returns error? {
test:assertTrue(fineTuneResponse.hasKey("object"), "Response does not have the key 'object'");
test:assertTrue(fineTuneResponse.hasKey("id"), "Response does not have the key 'id'");

string fine_tuning_job_id = fineTuneResponse.id;

FineTuningJob jobResponse = check baseClient->/fine_tuning/jobs/[fine_tuning_job_id]/cancel.post();

test:assertEquals(jobResponse.id, fine_tuning_job_id, "Job id mismatched");
test:assertTrue(jobResponse.hasKey("object"), "Response does not have the key 'object'");
}

@test:Config {
Expand All @@ -236,7 +247,6 @@ isolated function testRetrieveFineTuningJob() returns error? {

test:assertEquals(jobResponse.id, jobId, "Job id mismatched");
test:assertTrue(jobResponse.hasKey("object"), "Response does not have the key 'object'");

}

@test:Config {
Expand All @@ -254,7 +264,6 @@ isolated function testListFineTuningEvents() returns error? {

test:assertEquals(eventsResponse.'object, "list", "Object type mismatched");
test:assertTrue(eventsResponse.hasKey("data"), "Response does not have the key 'data'");

}

@test:Config {
Expand All @@ -272,7 +281,6 @@ isolated function testListFineTuningJobCheckpoints() returns error? {

test:assertEquals(checkpointsResponse.'object, "list", "Object type mismatched");
test:assertTrue(checkpointsResponse.hasKey("data"), "Response does not have the key 'data'");

}

// @test:Config {
Expand Down

0 comments on commit 2417191

Please sign in to comment.