diff --git a/client/src/main/java/com/theokanning/openai/OpenAiService.java b/client/src/main/java/com/theokanning/openai/OpenAiService.java deleted file mode 100644 index 21d6de81..00000000 --- a/client/src/main/java/com/theokanning/openai/OpenAiService.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.theokanning.openai; - -import static java.time.Duration.*; - -import java.time.Duration; - -/** - * Use the OpenAiService from the new 'service' library. See README for more details. - * - * @deprecated Has moved to {@link com.theokanning.openai.client.OpenAiService}. - */ -@Deprecated -public class OpenAiService extends com.theokanning.openai.client.OpenAiService { - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - */ - public OpenAiService(final String token) { - this(token, BASE_URL, ofSeconds(10)); - } - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - * @param timeout http read timeout in seconds, 0 means no timeout - * @deprecated use {@link OpenAiService(String, Duration)} - */ - @Deprecated - public OpenAiService(final String token, final int timeout) { - this(token, BASE_URL, ofSeconds(timeout)); - } - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - * @param timeout http read timeout, Duration.ZERO means no timeout - */ - public OpenAiService(final String token, final Duration timeout) { - this(token, BASE_URL, timeout); - } - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - * @param timeout http read timeout, Duration.ZERO means no timeout - */ - public OpenAiService(final String token, final String baseUrl, final Duration timeout) { - super(token, baseUrl, timeout); - } - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param api OpenAiApi instance to use for all methods - */ - public OpenAiService(final OpenAiApi api) { - super(api); - } -} diff --git a/client/src/main/java/com/theokanning/openai/client/OpenAiService.java b/client/src/main/java/com/theokanning/openai/client/OpenAiService.java deleted file mode 100644 index 85a69d14..00000000 --- a/client/src/main/java/com/theokanning/openai/client/OpenAiService.java +++ /dev/null @@ -1,288 +0,0 @@ -package com.theokanning.openai.client; - -import static java.time.Duration.*; - -import java.time.Duration; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.PropertyNamingStrategy; -import com.theokanning.openai.DeleteResult; -import com.theokanning.openai.completion.CompletionRequest; -import com.theokanning.openai.completion.CompletionResult; -import com.theokanning.openai.completion.chat.ChatCompletionRequest; -import com.theokanning.openai.completion.chat.ChatCompletionResult; -import com.theokanning.openai.edit.EditRequest; -import com.theokanning.openai.edit.EditResult; -import com.theokanning.openai.embedding.EmbeddingRequest; -import com.theokanning.openai.embedding.EmbeddingResult; -import com.theokanning.openai.engine.Engine; -import com.theokanning.openai.file.File; -import com.theokanning.openai.finetune.FineTuneEvent; -import com.theokanning.openai.finetune.FineTuneRequest; -import com.theokanning.openai.finetune.FineTuneResult; -import com.theokanning.openai.image.CreateImageEditRequest; -import com.theokanning.openai.image.CreateImageRequest; -import com.theokanning.openai.image.CreateImageVariationRequest; -import com.theokanning.openai.image.ImageResult; -import com.theokanning.openai.model.Model; -import com.theokanning.openai.moderation.ModerationRequest; -import com.theokanning.openai.moderation.ModerationResult; - -import okhttp3.ConnectionPool; -import okhttp3.MediaType; -import okhttp3.MultipartBody; -import okhttp3.OkHttpClient; -import okhttp3.RequestBody; -import retrofit2.Retrofit; -import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; -import retrofit2.converter.jackson.JacksonConverterFactory; - -/** - * Use the OpenAiService from the new 'service' library. See README for more details. - */ -@Deprecated -public class OpenAiService { - - protected static final String BASE_URL = "https://api.openai.com/"; - - final OpenAiApi api; - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - */ - public OpenAiService(final String token) { - this(token, BASE_URL, ofSeconds(10)); - } - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - * @param timeout http read timeout in seconds, 0 means no timeout - * @deprecated use {@link OpenAiService(String, Duration)} - */ - @Deprecated - public OpenAiService(final String token, final int timeout) { - this(token, BASE_URL, ofSeconds(timeout)); - } - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - * @param timeout http read timeout, Duration.ZERO means no timeout - */ - public OpenAiService(final String token, final Duration timeout) { - this(token, BASE_URL, timeout); - } - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - * @param timeout http read timeout, Duration.ZERO means no timeout - */ - public OpenAiService(final String token, final String baseUrl, final Duration timeout) { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); - - OkHttpClient client = new OkHttpClient.Builder() - .addInterceptor(new AuthenticationInterceptor(token)) - .connectionPool(new ConnectionPool(5, 1, TimeUnit.SECONDS)) - .readTimeout(timeout.toMillis(), TimeUnit.MILLISECONDS) - .build(); - - Retrofit retrofit = new Retrofit.Builder() - .baseUrl(baseUrl) - .client(client) - .addConverterFactory(JacksonConverterFactory.create(mapper)) - .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) - .build(); - - this.api = retrofit.create(OpenAiApi.class); - } - - /** - * Creates a new OpenAiService that wraps OpenAiApi - * - * @param api OpenAiApi instance to use for all methods - */ - public OpenAiService(final OpenAiApi api) { - this.api = api; - } - - public List listModels() { - return api.listModels().blockingGet().data; - } - - public Model getModel(String modelId) { - return api.getModel(modelId).blockingGet(); - } - - public CompletionResult createCompletion(CompletionRequest request) { - return api.createCompletion(request).blockingGet(); - } - - public ChatCompletionResult createChatCompletion(ChatCompletionRequest request) { - return api.createChatCompletion(request).blockingGet(); - } - - /** - * Use {@link OpenAiService#createCompletion(CompletionRequest)} and {@link CompletionRequest#model}instead - */ - @Deprecated - public CompletionResult createCompletion(String engineId, CompletionRequest request) { - return api.createCompletion(engineId, request).blockingGet(); - } - - public EditResult createEdit(EditRequest request) { - return api.createEdit(request).blockingGet(); - } - - /** - * Use {@link OpenAiService#createEdit(EditRequest)} and {@link EditRequest#model}instead - */ - @Deprecated - public EditResult createEdit(String engineId, EditRequest request) { - return api.createEdit(engineId, request).blockingGet(); - } - - public EmbeddingResult createEmbeddings(EmbeddingRequest request) { - return api.createEmbeddings(request).blockingGet(); - } - - /** - * Use {@link OpenAiService#createEmbeddings(EmbeddingRequest)} and {@link EmbeddingRequest#model}instead - */ - @Deprecated - public EmbeddingResult createEmbeddings(String engineId, EmbeddingRequest request) { - return api.createEmbeddings(engineId, request).blockingGet(); - } - - public List listFiles() { - return api.listFiles().blockingGet().data; - } - - public File uploadFile(String purpose, String filepath) { - java.io.File file = new java.io.File(filepath); - RequestBody purposeBody = RequestBody.create(okhttp3.MultipartBody.FORM, purpose); - RequestBody fileBody = RequestBody.create(MediaType.parse("text"), file); - MultipartBody.Part body = MultipartBody.Part.createFormData("file", filepath, fileBody); - - return api.uploadFile(purposeBody, body).blockingGet(); - } - - public DeleteResult deleteFile(String fileId) { - return api.deleteFile(fileId).blockingGet(); - } - - public File retrieveFile(String fileId) { - return api.retrieveFile(fileId).blockingGet(); - } - - public FineTuneResult createFineTune(FineTuneRequest request) { - return api.createFineTune(request).blockingGet(); - } - - public CompletionResult createFineTuneCompletion(CompletionRequest request) { - return api.createFineTuneCompletion(request).blockingGet(); - } - - public List listFineTunes() { - return api.listFineTunes().blockingGet().data; - } - - public FineTuneResult retrieveFineTune(String fineTuneId) { - return api.retrieveFineTune(fineTuneId).blockingGet(); - } - - public FineTuneResult cancelFineTune(String fineTuneId) { - return api.cancelFineTune(fineTuneId).blockingGet(); - } - - public List listFineTuneEvents(String fineTuneId) { - return api.listFineTuneEvents(fineTuneId).blockingGet().data; - } - - public DeleteResult deleteFineTune(String fineTuneId) { - return api.deleteFineTune(fineTuneId).blockingGet(); - } - - public ImageResult createImage(CreateImageRequest request) { - return api.createImage(request).blockingGet(); - } - - public ImageResult createImageEdit(CreateImageEditRequest request, String imagePath, String maskPath) { - java.io.File image = new java.io.File(imagePath); - java.io.File mask = null; - if (maskPath != null) { - mask = new java.io.File(maskPath); - } - return createImageEdit(request, image, mask); - } - - public ImageResult createImageEdit(CreateImageEditRequest request, java.io.File image, java.io.File mask) { - RequestBody imageBody = RequestBody.create(MediaType.parse("image"), image); - - MultipartBody.Builder builder = new MultipartBody.Builder() - .setType(MediaType.get("multipart/form-data")) - .addFormDataPart("prompt", request.getPrompt()) - .addFormDataPart("size", request.getSize()) - .addFormDataPart("response_format", request.getResponseFormat()) - .addFormDataPart("image", "image", imageBody); - - if (request.getN() != null) { - builder.addFormDataPart("n", request.getN().toString()); - } - - if (mask != null) { - RequestBody maskBody = RequestBody.create(MediaType.parse("image"), mask); - builder.addFormDataPart("mask", "mask", maskBody); - } - - return api.createImageEdit(builder.build()).blockingGet(); - } - - public ImageResult createImageVariation(CreateImageVariationRequest request, String imagePath) { - java.io.File image = new java.io.File(imagePath); - return createImageVariation(request, image); - } - - public ImageResult createImageVariation(CreateImageVariationRequest request, java.io.File image) { - RequestBody imageBody = RequestBody.create(MediaType.parse("image"), image); - - MultipartBody.Builder builder = new MultipartBody.Builder() - .setType(MediaType.get("multipart/form-data")) - .addFormDataPart("size", request.getSize()) - .addFormDataPart("response_format", request.getResponseFormat()) - .addFormDataPart("image", "image", imageBody); - - if (request.getN() != null) { - builder.addFormDataPart("n", request.getN().toString()); - } - - return api.createImageVariation(builder.build()).blockingGet(); - } - - public ModerationResult createModeration(ModerationRequest request) { - return api.createModeration(request).blockingGet(); - } - - @Deprecated - public List getEngines() { - return api.getEngines().blockingGet().data; - } - - @Deprecated - public Engine getEngine(String engineId) { - return api.getEngine(engineId).blockingGet(); - } -} diff --git a/client/src/test/java/com/theokanning/openai/ChatCompletionTest.java b/client/src/test/java/com/theokanning/openai/ChatCompletionTest.java deleted file mode 100644 index 41e3c76f..00000000 --- a/client/src/test/java/com/theokanning/openai/ChatCompletionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.theokanning.openai; -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.completion.CompletionChoice; -import com.theokanning.openai.completion.CompletionRequest; -import com.theokanning.openai.completion.chat.ChatCompletionChoice; -import com.theokanning.openai.completion.chat.ChatCompletionRequest; -import com.theokanning.openai.completion.chat.ChatMessage; -import com.theokanning.openai.completion.chat.ChatMessageRole; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class ChatCompletionTest { - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token); - - @Test - void createChatCompletion() { - final List messages = new ArrayList<>(); // java version agnostic - final ChatMessage systemMessage = new ChatMessage(ChatMessageRole.SYSTEM.value(), "You are a dog and will speak as such."); - messages.add(systemMessage); - - ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest - .builder() - .model("gpt-3.5-turbo") - .messages(messages) - .n(5) - .maxTokens(50) - .logitBias(new HashMap<>()) - .build(); - - List choices = service.createChatCompletion(chatCompletionRequest).getChoices(); - assertEquals(5, choices.size()); - - } -} diff --git a/client/src/test/java/com/theokanning/openai/CompletionTest.java b/client/src/test/java/com/theokanning/openai/CompletionTest.java deleted file mode 100644 index 2b3024b6..00000000 --- a/client/src/test/java/com/theokanning/openai/CompletionTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.completion.CompletionChoice; -import com.theokanning.openai.completion.CompletionRequest; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - - -public class CompletionTest { - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token); - - @Test - void createCompletion() { - CompletionRequest completionRequest = CompletionRequest.builder() - .model("ada") - .prompt("Somebody once told me the world is gonna roll me") - .echo(true) - .n(5) - .maxTokens(50) - .user("testing") - .logitBias(new HashMap<>()) - .build(); - - List choices = service.createCompletion(completionRequest).getChoices(); - assertEquals(5, choices.size()); - } - - @Test - void createCompletionDeprecated() { - CompletionRequest completionRequest = CompletionRequest.builder() - .prompt("Somebody once told me the world is gonna roll me") - .echo(true) - .user("testing") - .build(); - - List choices = service.createCompletion("ada", completionRequest).getChoices(); - assertFalse(choices.isEmpty()); - } -} diff --git a/client/src/test/java/com/theokanning/openai/EditTest.java b/client/src/test/java/com/theokanning/openai/EditTest.java deleted file mode 100644 index 11d14439..00000000 --- a/client/src/test/java/com/theokanning/openai/EditTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.edit.EditRequest; -import com.theokanning.openai.edit.EditResult; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class EditTest { - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token); - - @Test - void edit() { - EditRequest request = EditRequest.builder() - .model("text-davinci-edit-001") - .input("What day of the wek is it?") - .instruction("Fix the spelling mistakes") - .build(); - - EditResult result = service.createEdit(request); - assertNotNull(result.getChoices().get(0).getText()); - } - - @Test - void editDeprecated() { - EditRequest request = EditRequest.builder() - .input("What day of the wek is it?") - .instruction("Fix the spelling mistakes") - .build(); - - EditResult result = service.createEdit("text-davinci-edit-001", request); - - assertNotNull(result.getChoices().get(0).getText()); - } -} diff --git a/client/src/test/java/com/theokanning/openai/EmbeddingTest.java b/client/src/test/java/com/theokanning/openai/EmbeddingTest.java deleted file mode 100644 index e2ddbda8..00000000 --- a/client/src/test/java/com/theokanning/openai/EmbeddingTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.embedding.Embedding; -import com.theokanning.openai.embedding.EmbeddingRequest; -import org.junit.jupiter.api.Test; - -import java.util.Collections; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertFalse; - - -public class EmbeddingTest { - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token); - - @Test - void createEmbeddings() { - EmbeddingRequest embeddingRequest = EmbeddingRequest.builder() - .model("text-similarity-babbage-001") - .input(Collections.singletonList("The food was delicious and the waiter...")) - .build(); - - List embeddings = service.createEmbeddings(embeddingRequest).getData(); - - assertFalse(embeddings.isEmpty()); - assertFalse(embeddings.get(0).getEmbedding().isEmpty()); - } - - @Test - void createEmbeddingsDeprecated() { - EmbeddingRequest embeddingRequest = EmbeddingRequest.builder() - .input(Collections.singletonList("The food was delicious and the waiter...")) - .build(); - - List embeddings = service.createEmbeddings("text-similarity-babbage-001", embeddingRequest).getData(); - - assertFalse(embeddings.isEmpty()); - assertFalse(embeddings.get(0).getEmbedding().isEmpty()); - } -} diff --git a/client/src/test/java/com/theokanning/openai/EngineTest.java b/client/src/test/java/com/theokanning/openai/EngineTest.java deleted file mode 100644 index 2e047ab2..00000000 --- a/client/src/test/java/com/theokanning/openai/EngineTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.engine.Engine; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - - -public class EngineTest { - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token); - - @Test - void getEngines() { - List engines = service.getEngines(); - - assertFalse(engines.isEmpty()); - } - - @Test - void getEngine() { - Engine ada = service.getEngine("ada"); - - assertEquals("ada", ada.id); - } -} diff --git a/client/src/test/java/com/theokanning/openai/FileTest.java b/client/src/test/java/com/theokanning/openai/FileTest.java deleted file mode 100644 index 998b27a2..00000000 --- a/client/src/test/java/com/theokanning/openai/FileTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.file.File; -import org.junit.jupiter.api.*; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class FileTest { - static String filePath = "src/test/resources/fine-tuning-data.jsonl"; - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token); - static String fileId; - - @Test - @Order(1) - void uploadFile() throws Exception { - File file = service.uploadFile("fine-tune", filePath); - fileId = file.getId(); - - assertEquals("fine-tune", file.getPurpose()); - assertEquals(filePath, file.getFilename()); - - // wait for file to be processed - TimeUnit.SECONDS.sleep(10); - } - - @Test - @Order(2) - void listFiles() { - List files = service.listFiles(); - - assertTrue(files.stream().anyMatch(file -> file.getId().equals(fileId))); - } - - @Test - @Order(3) - void retrieveFile() { - File file = service.retrieveFile(fileId); - - assertEquals(filePath, file.getFilename()); - } - - @Test - @Order(4) - void deleteFile() { - DeleteResult result = service.deleteFile(fileId); - assertTrue(result.isDeleted()); - } -} diff --git a/client/src/test/java/com/theokanning/openai/FineTuneTest.java b/client/src/test/java/com/theokanning/openai/FineTuneTest.java deleted file mode 100644 index 54d805ce..00000000 --- a/client/src/test/java/com/theokanning/openai/FineTuneTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.finetune.FineTuneRequest; -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.finetune.FineTuneEvent; -import com.theokanning.openai.finetune.FineTuneResult; -import org.junit.jupiter.api.*; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static org.junit.jupiter.api.Assertions.*; - -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class FineTuneTest { - static OpenAiService service; - static String fileId; - static String fineTuneId; - - - @BeforeAll - static void setup() throws Exception { - String token = System.getenv("OPENAI_TOKEN"); - service = new OpenAiService(token); - fileId = service.uploadFile("fine-tune", "src/test/resources/fine-tuning-data.jsonl").getId(); - - // wait for file to be processed - TimeUnit.SECONDS.sleep(10); - } - - @AfterAll - static void teardown() { - service.deleteFile(fileId); - } - - @Test - @Order(1) - void createFineTune() { - FineTuneRequest request = FineTuneRequest.builder() - .trainingFile(fileId) - .model("ada") - .nEpochs(4) - .build(); - - FineTuneResult fineTune = service.createFineTune(request); - fineTuneId = fineTune.getId(); - - assertEquals("pending", fineTune.getStatus()); - } - - @Test - @Order(2) - void listFineTunes() { - List fineTunes = service.listFineTunes(); - - assertTrue(fineTunes.stream().anyMatch(fineTune -> fineTune.getId().equals(fineTuneId))); - } - - @Test - @Order(3) - void listFineTuneEvents() { - List events = service.listFineTuneEvents(fineTuneId); - - assertFalse(events.isEmpty()); - } - - @Test - @Order(3) - void retrieveFineTune() { - FineTuneResult fineTune = service.retrieveFineTune(fineTuneId); - - assertEquals("ada", fineTune.getModel()); - } - - @Test - @Order(4) - void cancelFineTune() { - FineTuneResult fineTune = service.cancelFineTune(fineTuneId); - - assertEquals("cancelled", fineTune.getStatus()); - } -} diff --git a/client/src/test/java/com/theokanning/openai/ImageTest.java b/client/src/test/java/com/theokanning/openai/ImageTest.java deleted file mode 100644 index 304ea0bf..00000000 --- a/client/src/test/java/com/theokanning/openai/ImageTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.image.CreateImageEditRequest; -import com.theokanning.openai.image.CreateImageRequest; -import com.theokanning.openai.image.CreateImageVariationRequest; -import com.theokanning.openai.image.Image; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - - -public class ImageTest { - - static String filePath = "src/test/resources/penguin.png"; - static String fileWithAlphaPath = "src/test/resources/penguin_with_alpha.png"; - static String maskPath = "src/test/resources/mask.png"; - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token, 30); - - - @Test - void createImageUrl() { - CreateImageRequest createImageRequest = CreateImageRequest.builder() - .prompt("penguin") - .n(3) - .size("256x256") - .user("testing") - .build(); - - List images = service.createImage(createImageRequest).getData(); - assertEquals(3, images.size()); - assertNotNull(images.get(0).getUrl()); - } - - @Test - void createImageBase64() { - CreateImageRequest createImageRequest = CreateImageRequest.builder() - .prompt("penguin") - .responseFormat("b64_json") - .user("testing") - .build(); - - List images = service.createImage(createImageRequest).getData(); - assertEquals(1, images.size()); - assertNotNull(images.get(0).getB64Json()); - } - - @Test - void createImageEdit() { - CreateImageEditRequest createImageRequest = CreateImageEditRequest.builder() - .prompt("a penguin with a red background") - .responseFormat("url") - .size("256x256") - .user("testing") - .n(2) - .build(); - - List images = service.createImageEdit(createImageRequest, fileWithAlphaPath, null).getData(); - assertEquals(2, images.size()); - assertNotNull(images.get(0).getUrl()); - } - - @Test - void createImageEditWithMask() { - CreateImageEditRequest createImageRequest = CreateImageEditRequest.builder() - .prompt("a penguin with a red hat") - .responseFormat("url") - .size("256x256") - .user("testing") - .n(2) - .build(); - - List images = service.createImageEdit(createImageRequest, filePath, maskPath).getData(); - assertEquals(2, images.size()); - assertNotNull(images.get(0).getUrl()); - } - - @Test - void createImageVariation() { - CreateImageVariationRequest createImageVariationRequest = CreateImageVariationRequest.builder() - .responseFormat("url") - .size("256x256") - .user("testing") - .n(2) - .build(); - - List images = service.createImageVariation(createImageVariationRequest, filePath).getData(); - assertEquals(2, images.size()); - assertNotNull(images.get(0).getUrl()); - } -} diff --git a/client/src/test/java/com/theokanning/openai/ModelTest.java b/client/src/test/java/com/theokanning/openai/ModelTest.java deleted file mode 100644 index 095433ba..00000000 --- a/client/src/test/java/com/theokanning/openai/ModelTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.model.Model; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - - -public class ModelTest { - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token); - - @Test - void listModels() { - List models = service.listModels(); - - assertFalse(models.isEmpty()); - } - - @Test - void getModel() { - Model ada = service.getModel("ada"); - - assertEquals("ada", ada.id); - assertEquals("openai", ada.ownedBy); - assertFalse(ada.permission.isEmpty()); - } -} diff --git a/client/src/test/java/com/theokanning/openai/ModerationTest.java b/client/src/test/java/com/theokanning/openai/ModerationTest.java deleted file mode 100644 index f5c21738..00000000 --- a/client/src/test/java/com/theokanning/openai/ModerationTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.theokanning.openai; - -import com.theokanning.openai.moderation.ModerationRequest; -import com.theokanning.openai.client.OpenAiService; -import com.theokanning.openai.moderation.Moderation; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertTrue; - - -public class ModerationTest { - - String token = System.getenv("OPENAI_TOKEN"); - OpenAiService service = new OpenAiService(token); - - @Test - void createModeration() { - ModerationRequest moderationRequest = ModerationRequest.builder() - .input("I want to kill them") - .model("text-moderation-latest") - .build(); - - Moderation moderationScore = service.createModeration(moderationRequest).getResults().get(0); - - assertTrue(moderationScore.isFlagged()); - } -} diff --git a/client/src/test/resources/fine-tuning-data.jsonl b/client/src/test/resources/fine-tuning-data.jsonl deleted file mode 100644 index 2f0e4c79..00000000 --- a/client/src/test/resources/fine-tuning-data.jsonl +++ /dev/null @@ -1,2 +0,0 @@ -{"prompt": "prompt", "completion": "text"} -{"prompt": "prompt", "completion": "text"} \ No newline at end of file diff --git a/client/src/test/resources/mask.png b/client/src/test/resources/mask.png deleted file mode 100644 index 84fcfb35..00000000 Binary files a/client/src/test/resources/mask.png and /dev/null differ diff --git a/client/src/test/resources/penguin.png b/client/src/test/resources/penguin.png deleted file mode 100644 index 91b023c3..00000000 Binary files a/client/src/test/resources/penguin.png and /dev/null differ diff --git a/client/src/test/resources/penguin_with_alpha.png b/client/src/test/resources/penguin_with_alpha.png deleted file mode 100644 index 4636c4f4..00000000 Binary files a/client/src/test/resources/penguin_with_alpha.png and /dev/null differ