Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaSerpentis authored Nov 8, 2023
2 parents de086d1 + dc51a5b commit 2456ce5
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 9 deletions.
12 changes: 12 additions & 0 deletions api/src/main/java/com/theokanning/openai/file/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ public class File {
* Description of the file's purpose.
*/
String purpose;

/**
* The current status of the file, which can be either uploaded, processed, pending, error, deleting or deleted.
*/
String status;

/**
* Additional details about the status of the file.
* If the file is in the error state, this will include a message describing the error.
*/
@JsonProperty("status_details")
String statusDetails;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class FineTuningEvent {
*/
String object;

/**
* The ID of the fine-tuning event.
*/
String id;

/**
* The creation time in epoch seconds.
*/
Expand Down
8 changes: 6 additions & 2 deletions api/src/test/java/com/theokanning/openai/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import com.theokanning.openai.embedding.EmbeddingResult;
import com.theokanning.openai.engine.Engine;
import com.theokanning.openai.file.File;
import com.theokanning.openai.fine_tuning.FineTuningEvent;
import com.theokanning.openai.fine_tuning.FineTuningJob;
import com.theokanning.openai.fine_tuning.FineTuningJobRequest;
import com.theokanning.openai.finetune.FineTuneEvent;
import com.theokanning.openai.finetune.FineTuneResult;
import com.theokanning.openai.image.CreateImageEditRequest;
import com.theokanning.openai.image.CreateImageRequest;
import com.theokanning.openai.image.ImageResult;
import com.theokanning.openai.model.Model;
import com.theokanning.openai.moderation.ModerationRequest;
Expand Down Expand Up @@ -43,6 +44,9 @@ public class JsonTest {
File.class,
FineTuneEvent.class,
FineTuneResult.class,
FineTuningEvent.class,
FineTuningJob.class,
FineTuningJobRequest.class,
ImageResult.class,
TranscriptionResult.class,
TranslationResult.class,
Expand Down
6 changes: 4 additions & 2 deletions api/src/test/resources/fixtures/File.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"bytes": 175,
"created_at": 1613677385,
"filename": "train.jsonl",
"purpose": "search"
}
"purpose": "search",
"status": "error",
"status_details": "File is too large."
}
8 changes: 8 additions & 0 deletions api/src/test/resources/fixtures/FineTuningEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"object": "fine_tuning.job.event",
"id": "ft-event-ddTJfwuMVpfLXseO0Am0Gqjm",
"created_at": 1692407401,
"level": "info",
"message": "Fine tuning job successfully completed",
"type": "message"
}
19 changes: 19 additions & 0 deletions api/src/test/resources/fixtures/FineTuningJob.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id": "ftjob-abc123",
"object": "fine_tuning.job",
"model": "davinci-002",
"status": "succeeded",
"hyperparameters": {
"n_epochs": 4
},
"created_at": 1692661014,
"finished_at": 1692661190,
"fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy",
"organization_id": "org-123",
"training_file": "file-abc123",
"result_files": [
"file-abc123"
],
"validation_file": "validation-file",
"trained_tokens": 5768
}
9 changes: 9 additions & 0 deletions api/src/test/resources/fixtures/FineTuningJobRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"model": "davinci-002",
"validation_file": "file-abc123",
"training_file": "file-abc123",
"hyperparameters": {
"n_epochs": 4
},
"suffix": "test"
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public interface OpenAiApi {
@GET("/v1/files/{file_id}")
Single<File> retrieveFile(@Path("file_id") String fileId);

@Streaming
@GET("/v1/files/{file_id}/content")
Single<ResponseBody> retrieveFileContent(@Path("file_id") String fileId);

@POST("/v1/fine_tuning/jobs")
Single<FineTuningJob> createFineTuningJob(@Body FineTuningJobRequest request);

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.theokanning.openai-gpt3-java
VERSION_NAME=0.16.0
VERSION_NAME=0.16.1

POM_URL=https://github.com/theokanning/openai-java
POM_SCM_URL=https://github.com/theokanning/openai-java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public File retrieveFile(String fileId) {
return execute(api.retrieveFile(fileId));
}

public ResponseBody retrieveFileContent(String fileId) {
return execute(api.retrieveFileContent(fileId));
}

public FineTuningJob createFineTuningJob(FineTuningJobRequest request) {
return execute(api.createFineTuningJob(request));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand All @@ -18,7 +22,7 @@ public class FileTest {
static String filePath = "src/test/resources/fine-tuning-data.jsonl";

String token = System.getenv("OPENAI_TOKEN");
com.theokanning.openai.service.OpenAiService service = new OpenAiService(token);
OpenAiService service = new OpenAiService(token);
static String fileId;

@Test
Expand Down Expand Up @@ -52,6 +56,14 @@ void retrieveFile() {

@Test
@Order(4)
void retrieveFileContent() throws IOException {
String fileBytesToString = service.retrieveFileContent(fileId).string();
String contents = new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8);
assertEquals(contents, fileBytesToString);
}

@Test
@Order(5)
void deleteFile() {
DeleteResult result = service.deleteFile(fileId);
assertTrue(result.isDeleted());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.theokanning.openai.fine_tuning.FineTuningJob;
import com.theokanning.openai.fine_tuning.FineTuningJobRequest;
import com.theokanning.openai.fine_tuning.Hyperparameters;
import com.theokanning.openai.finetune.FineTuneResult;
import org.junit.jupiter.api.*;

import java.util.List;
Expand All @@ -31,7 +30,11 @@ static void setup() throws Exception {

@AfterAll
static void teardown() {
service.deleteFile(fileId);
try {
service.deleteFile(fileId);
} catch (Exception e) {
// ignore
}
}

@Test
Expand All @@ -49,7 +52,7 @@ void createFineTuningJob() {
FineTuningJob fineTuningJob = service.createFineTuningJob(request);
fineTuningJobId = fineTuningJob.getId();

assertEquals("created", fineTuningJob.getStatus());
assertNotNull(fineTuningJob);
}

@Test
Expand Down

0 comments on commit 2456ce5

Please sign in to comment.