From 2417191474aa5eb7db49329b197506c4fc9f31a0 Mon Sep 17 00:00:00 2001 From: KATTA-00 Date: Fri, 9 Aug 2024 10:25:23 +0530 Subject: [PATCH] Add test for fine-tuning job cancellation and file deletion endpoints --- ballerina/tests/openapi_service.bal | 67 +++++++++++++++++++++++------ ballerina/tests/test.bal | 54 +++++++++++++---------- 2 files changed, 86 insertions(+), 35 deletions(-) diff --git a/ballerina/tests/openapi_service.bal b/ballerina/tests/openapi_service.bal index c87e6c4..7c7c764 100644 --- a/ballerina/tests/openapi_service.bal +++ b/ballerina/tests/openapi_service.bal @@ -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. // # @@ -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. @@ -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 { - // } }; diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index d4be8fa..cf286c1 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -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(); @@ -58,7 +56,7 @@ isolated function testRetrieveModel() returns error? { } // @test:Config { -// dependsOn: [testCreateFineTuningJob, testListModels] +// dependsOn: [testCreateFineTuningJob, testListModels, testRetrieveModel] // } // isolated function testDeleteModel() returns error? { @@ -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 { @@ -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 @@ -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? { @@ -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 { @@ -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 { @@ -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 { @@ -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 {