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

Commit

Permalink
Implemented missing API for issue #366: No Retrieve file content api (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
costescuandrei authored Oct 22, 2023
1 parent 442cf13 commit 4420830
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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
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
10 changes: 10 additions & 0 deletions service/src/test/java/com/theokanning/openai/service/FileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -52,6 +55,13 @@ void retrieveFile() {

@Test
@Order(4)
void retrieveFileContent() throws IOException {
String fileBytesToString = service.retrieveFileContent(fileId).string();
assertEquals(Files.readString(Path.of(filePath)), fileBytesToString);
}

@Test
@Order(5)
void deleteFile() {
DeleteResult result = service.deleteFile(fileId);
assertTrue(result.isDeleted());
Expand Down

0 comments on commit 4420830

Please sign in to comment.