From 7636f024b42c26405e357432cc858df29fb892a5 Mon Sep 17 00:00:00 2001 From: HamaWhiteGG Date: Thu, 7 Dec 2023 22:33:11 +0800 Subject: [PATCH] Optimize code variables #146 --- .../src/main/java/com/hw/openai/OpenAiClient.java | 4 ++-- .../{CreateImageRequest.java => CreateImageReq.java} | 4 ++-- .../{ImageResponseFormat.java => ImageRespFormat.java} | 8 ++++---- .../main/java/com/hw/openai/service/OpenAiService.java | 4 ++-- .../src/test/java/com/hw/openai/images/ImageTest.java | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) rename openai-client/src/main/java/com/hw/openai/entity/image/{CreateImageRequest.java => CreateImageReq.java} (96%) rename openai-client/src/main/java/com/hw/openai/entity/image/{ImageResponseFormat.java => ImageRespFormat.java} (86%) diff --git a/openai-client/src/main/java/com/hw/openai/OpenAiClient.java b/openai-client/src/main/java/com/hw/openai/OpenAiClient.java index d47754cb..df0d560f 100644 --- a/openai-client/src/main/java/com/hw/openai/OpenAiClient.java +++ b/openai-client/src/main/java/com/hw/openai/OpenAiClient.java @@ -30,7 +30,7 @@ import com.hw.openai.entity.completions.CompletionResp; import com.hw.openai.entity.embeddings.Embedding; import com.hw.openai.entity.embeddings.EmbeddingResp; -import com.hw.openai.entity.image.CreateImageRequest; +import com.hw.openai.entity.image.CreateImageReq; import com.hw.openai.entity.image.ImageResp; import com.hw.openai.entity.models.Model; import com.hw.openai.entity.models.ModelResp; @@ -321,7 +321,7 @@ public EmbeddingResp createEmbedding(Embedding embedding) { * @param request the create image request * @return the image result response */ - public ImageResp createImage(CreateImageRequest request) { + public ImageResp createImage(CreateImageReq request) { return execute(service.createImage(request)); } diff --git a/openai-client/src/main/java/com/hw/openai/entity/image/CreateImageRequest.java b/openai-client/src/main/java/com/hw/openai/entity/image/CreateImageReq.java similarity index 96% rename from openai-client/src/main/java/com/hw/openai/entity/image/CreateImageRequest.java rename to openai-client/src/main/java/com/hw/openai/entity/image/CreateImageReq.java index 6d09dba6..cf2a92ce 100644 --- a/openai-client/src/main/java/com/hw/openai/entity/image/CreateImageRequest.java +++ b/openai-client/src/main/java/com/hw/openai/entity/image/CreateImageReq.java @@ -31,7 +31,7 @@ @Data @Builder @JsonInclude(JsonInclude.Include.NON_NULL) -public class CreateImageRequest { +public class CreateImageReq { /** * A text description of the desired image(s). @@ -64,7 +64,7 @@ public class CreateImageRequest { */ @JsonProperty("response_format") @Builder.Default - private ImageResponseFormat responseFormat = ImageResponseFormat.URL; + private ImageRespFormat responseFormat = ImageRespFormat.URL; /** * The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 for dall-e-2. diff --git a/openai-client/src/main/java/com/hw/openai/entity/image/ImageResponseFormat.java b/openai-client/src/main/java/com/hw/openai/entity/image/ImageRespFormat.java similarity index 86% rename from openai-client/src/main/java/com/hw/openai/entity/image/ImageResponseFormat.java rename to openai-client/src/main/java/com/hw/openai/entity/image/ImageRespFormat.java index f31b94fe..05917b9a 100644 --- a/openai-client/src/main/java/com/hw/openai/entity/image/ImageResponseFormat.java +++ b/openai-client/src/main/java/com/hw/openai/entity/image/ImageRespFormat.java @@ -24,7 +24,7 @@ /** * @author HamaWhite */ -public enum ImageResponseFormat { +public enum ImageRespFormat { URL("url"), @@ -32,7 +32,7 @@ public enum ImageResponseFormat { private final String value; - ImageResponseFormat(String value) { + ImageRespFormat(String value) { this.value = value; } @@ -42,8 +42,8 @@ public String getValue() { } @JsonCreator - public static ImageResponseFormat fromValue(String value) { - for (ImageResponseFormat item : ImageResponseFormat.values()) { + public static ImageRespFormat fromValue(String value) { + for (ImageRespFormat item : ImageRespFormat.values()) { if (item.value.equalsIgnoreCase(value)) { return item; } diff --git a/openai-client/src/main/java/com/hw/openai/service/OpenAiService.java b/openai-client/src/main/java/com/hw/openai/service/OpenAiService.java index a09839a4..6f3559e5 100644 --- a/openai-client/src/main/java/com/hw/openai/service/OpenAiService.java +++ b/openai-client/src/main/java/com/hw/openai/service/OpenAiService.java @@ -24,7 +24,7 @@ import com.hw.openai.entity.completions.CompletionResp; import com.hw.openai.entity.embeddings.Embedding; import com.hw.openai.entity.embeddings.EmbeddingResp; -import com.hw.openai.entity.image.CreateImageRequest; +import com.hw.openai.entity.image.CreateImageReq; import com.hw.openai.entity.image.ImageResp; import com.hw.openai.entity.models.Model; import com.hw.openai.entity.models.ModelResp; @@ -150,5 +150,5 @@ Single createEmbedding(@Path("deploymentId") String deploymentId, * @return A Single emitting the response containing the generated image. */ @POST("images/generations") - Single createImage(@Body CreateImageRequest request); + Single createImage(@Body CreateImageReq request); } diff --git a/openai-client/src/test/java/com/hw/openai/images/ImageTest.java b/openai-client/src/test/java/com/hw/openai/images/ImageTest.java index e11637ec..dc26ce61 100644 --- a/openai-client/src/test/java/com/hw/openai/images/ImageTest.java +++ b/openai-client/src/test/java/com/hw/openai/images/ImageTest.java @@ -19,7 +19,7 @@ package com.hw.openai.images; import com.hw.openai.OpenAiClientTest; -import com.hw.openai.entity.image.CreateImageRequest; +import com.hw.openai.entity.image.CreateImageReq; import com.hw.openai.entity.image.Image; import org.junit.jupiter.api.Disabled; @@ -42,7 +42,7 @@ public class ImageTest extends OpenAiClientTest { @Test void testCreateImage() { - CreateImageRequest request = CreateImageRequest.builder() + CreateImageReq request = CreateImageReq.builder() .model("dall-e-3") .prompt("A cute baby sea otter") .n(1)