From aa8f7813adc4075bb2e71c77f1183a5ed0488258 Mon Sep 17 00:00:00 2001
From: magic chen <418379149@qq.com>
Date: Wed, 15 Mar 2023 11:56:16 +0800
Subject: [PATCH] =?UTF-8?q?-=20Optimize:=20Add=20GptModel.class=20list=20s?=
=?UTF-8?q?ome=20available=20models=20for=20request;=20You=20can=20choose?=
=?UTF-8?q?=20models=20instead=20of=20type=20the=20model=20name=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 10 ++
pom.xml | 2 +-
.../Audio/CreateTranscriptionRequest.java | 5 +-
.../Audio/CreateTranslationRequest.java | 5 +-
.../Chat/CreateChatCompletionRequest.java | 4 +-
.../Completions/CreateCompletionRequest.java | 4 +-
.../gptApi/Edits/CreateEditRequest.java | 5 +-
.../Embeddings/CreateEmbeddingsRequest.java | 3 +-
.../FineTunes/CreateFineTuneRequest.java | 3 +-
.../WhiteMagic2014/gptApi/GptModel.java | 152 ++++++++++++++++++
.../Moderations/CreateModerationRequest.java | 11 +-
11 files changed, 189 insertions(+), 15 deletions(-)
create mode 100644 src/main/java/com/github/WhiteMagic2014/gptApi/GptModel.java
diff --git a/README.md b/README.md
index b75cb4c..396d055 100644
--- a/README.md
+++ b/README.md
@@ -115,5 +115,15 @@ String key = "sk-your key";
### 1.3
- New: chat apis
- New: audio apis
+### 1.3.1
+- Optimize: Add GptModel.class list some available models for request; You can choose models instead of type the model name。
+```
+version before 1.3.1
+new CreateCompletionRequest().model("text-davinci-003");
+
+version after 1.3.1
+ new CreateCompletionRequest().model(GptModel.text_davinci_003);
+```
+
## License
This project is an open-sourced software licensed under the [MIT license](LICENSE).
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index ec0db38..dd35cda 100755
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
https://github.com/WhiteMagic2014/gpt-magic.git
io.github.whitemagic2014
gpt-magic
- 1.3
+ 1.3.1
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/Audio/CreateTranscriptionRequest.java b/src/main/java/com/github/WhiteMagic2014/gptApi/Audio/CreateTranscriptionRequest.java
index 6f1ccae..a802a4a 100644
--- a/src/main/java/com/github/WhiteMagic2014/gptApi/Audio/CreateTranscriptionRequest.java
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/Audio/CreateTranscriptionRequest.java
@@ -1,5 +1,6 @@
package com.github.WhiteMagic2014.gptApi.Audio;
+import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;
@@ -46,9 +47,9 @@ public CreateTranscriptionRequest file(File file) {
/**
* Required
- * ID of the model to use. Only whisper-1 is currently available.
+ * ID of the model to use.
*/
- private String model = "whisper-1";
+ private String model = GptModel.whisper_1;
public CreateTranscriptionRequest model(String model) {
this.model = model;
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/Audio/CreateTranslationRequest.java b/src/main/java/com/github/WhiteMagic2014/gptApi/Audio/CreateTranslationRequest.java
index 918fbb0..5a7f6ba 100644
--- a/src/main/java/com/github/WhiteMagic2014/gptApi/Audio/CreateTranslationRequest.java
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/Audio/CreateTranslationRequest.java
@@ -1,5 +1,6 @@
package com.github.WhiteMagic2014.gptApi.Audio;
+import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;
@@ -46,9 +47,9 @@ public CreateTranslationRequest file(File file) {
/**
* Required
- * ID of the model to use. Only whisper-1 is currently available.
+ * ID of the model to use.
*/
- private String model = "whisper-1";
+ private String model = GptModel.whisper_1;
public CreateTranslationRequest model(String model) {
this.model = model;
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/Chat/CreateChatCompletionRequest.java b/src/main/java/com/github/WhiteMagic2014/gptApi/Chat/CreateChatCompletionRequest.java
index 3424876..e79c40f 100644
--- a/src/main/java/com/github/WhiteMagic2014/gptApi/Chat/CreateChatCompletionRequest.java
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/Chat/CreateChatCompletionRequest.java
@@ -5,6 +5,7 @@
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.Chat.pojo.ChatCompletionChoice;
import com.github.WhiteMagic2014.gptApi.Chat.pojo.ChatMessage;
+import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;
@@ -43,9 +44,8 @@ public CreateChatCompletionRequest organization(String organization) {
/**
* Required
* ID of the model to use.
- * Currently, only gpt-3.5-turbo and gpt-3.5-turbo-0301 are supported.
*/
- private String model = "gpt-3.5-turbo";
+ private String model = GptModel.gpt_3p5_turbo;
public CreateChatCompletionRequest model(String model) {
this.model = model;
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/Completions/CreateCompletionRequest.java b/src/main/java/com/github/WhiteMagic2014/gptApi/Completions/CreateCompletionRequest.java
index 2f31811..71137e7 100755
--- a/src/main/java/com/github/WhiteMagic2014/gptApi/Completions/CreateCompletionRequest.java
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/Completions/CreateCompletionRequest.java
@@ -4,6 +4,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.Completions.pojo.CompletionChoice;
+import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;
@@ -11,6 +12,7 @@
/**
* Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
+ *
* @Description: Creates a completion for the provided prompt and parameters
* @author: magic chen
* @date: 2023/2/22 17:52
@@ -42,7 +44,7 @@ public CreateCompletionRequest organization(String organization) {
* ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.
* https://platform.openai.com/docs/models/overview
*/
- private String model = "text-davinci-003";
+ private String model = GptModel.text_davinci_003;
public CreateCompletionRequest model(String model) {
this.model = model;
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/Edits/CreateEditRequest.java b/src/main/java/com/github/WhiteMagic2014/gptApi/Edits/CreateEditRequest.java
index a2d7fef..7021c59 100755
--- a/src/main/java/com/github/WhiteMagic2014/gptApi/Edits/CreateEditRequest.java
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/Edits/CreateEditRequest.java
@@ -4,6 +4,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.Edits.pojo.EditChoice;
+import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;
@@ -39,9 +40,9 @@ public CreateEditRequest organization(String organization) {
// params
/**
* Required
- * ID of the model to use. You can use the text-davinci-edit-001 or code-davinci-edit-001 model with this endpoint.
+ * ID of the model to use.
*/
- private String model = "text-davinci-edit-001";// or code-davinci-edit-001
+ private String model = GptModel.text_davinci_edit_001;
public CreateEditRequest model(String model) {
this.model = model;
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/Embeddings/CreateEmbeddingsRequest.java b/src/main/java/com/github/WhiteMagic2014/gptApi/Embeddings/CreateEmbeddingsRequest.java
index efdca13..12785a9 100755
--- a/src/main/java/com/github/WhiteMagic2014/gptApi/Embeddings/CreateEmbeddingsRequest.java
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/Embeddings/CreateEmbeddingsRequest.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;
@@ -43,7 +44,7 @@ public CreateEmbeddingsRequest organization(String organization) {
* ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.
* https://platform.openai.com/docs/models/overview
*/
- private String model = "text-embedding-ada-002";
+ private String model = GptModel.text_embedding_ada_002;
public CreateEmbeddingsRequest model(String model) {
this.model = model;
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/FineTunes/CreateFineTuneRequest.java b/src/main/java/com/github/WhiteMagic2014/gptApi/FineTunes/CreateFineTuneRequest.java
index 1f24030..1196342 100644
--- a/src/main/java/com/github/WhiteMagic2014/gptApi/FineTunes/CreateFineTuneRequest.java
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/FineTunes/CreateFineTuneRequest.java
@@ -1,6 +1,7 @@
package com.github.WhiteMagic2014.gptApi.FineTunes;
import com.alibaba.fastjson.JSONObject;
+import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;
@@ -68,7 +69,7 @@ public CreateFineTuneRequest validationFile(String validationFile) {
* To learn more about these models, see the Models documentation.
* https://platform.openai.com/docs/models
*/
- private String model = "curie";
+ private String model = GptModel.ada;
public CreateFineTuneRequest model(String model) {
this.model = model;
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/GptModel.java b/src/main/java/com/github/WhiteMagic2014/gptApi/GptModel.java
new file mode 100644
index 0000000..3ef520c
--- /dev/null
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/GptModel.java
@@ -0,0 +1,152 @@
+package com.github.WhiteMagic2014.gptApi;
+
+/**
+ * @Description: some models
+ * @author: magic chen
+ * @date: 2023/3/15 11:09
+ * https://platform.openai.com/docs/models/model-endpoint-compatibility
+ **/
+public class GptModel {
+
+
+ /**
+ * Models for CreateChatCompletionRequest
+ */
+ /**
+ * More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. Will be updated with our latest model iteration.
+ * 8192 max tokens
+ */
+ public final static String gpt4 = "gpt-4";
+
+ /**
+ * Snapshot of gpt-4 from March 14th 2023. Unlike gpt-4, this model will not receive updates, and will only be supported for a three month period ending on June 14th 2023.
+ * 8192 max tokens
+ */
+ public final static String gpt_4_0314 = "gpt-4-0314";
+
+ /**
+ * Same capabilities as the base gpt-4 mode but with 4x the context length. Will be updated with our latest model iteration.
+ * 32768 max tokens
+ */
+ public final static String gpt_4_32k = "gpt-4-32k";
+
+ /**
+ * Snapshot of gpt-4-32 from March 14th 2023. Unlike gpt-4-32k, this model will not receive updates, and will only be supported for a three month period ending on June 14th 2023.
+ * 32768 max tokens
+ */
+ public final static String gpt_4_32k_0314 = "gpt-4-32k-0314";
+
+ /**
+ * Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with our latest model iteration.
+ * 4096 max tokens
+ */
+ public final static String gpt_3p5_turbo = "gpt-3.5-turbo";
+
+ /**
+ * Snapshot of gpt-3.5-turbo from March 1st 2023. Unlike gpt-3.5-turbo, this model will not receive updates, and will only be supported for a three month period ending on June 1st 2023.
+ * 4096 max tokens
+ */
+ public final static String gpt_3p5_turbo_0301 = "gpt-3.5-turbo-0301";
+
+
+
+
+
+ /*
+ * Models for CreateCompletionRequest
+ */
+ /**
+ * Can do any language task with better quality, longer output, and consistent instruction-following than the curie, babbage, or ada models. Also supports inserting completions within text.
+ * 4097 max tokens
+ */
+ public final static String text_davinci_003 = "text-davinci-003";
+
+ /**
+ * Similar capabilities to text-davinci-003 but trained with supervised fine-tuning instead of reinforcement learning
+ * 4097 max tokens
+ */
+ public final static String text_davinci_002 = "text-davinci-002";
+
+ /**
+ * Very capable, faster and lower cost than Davinci.
+ * 2049 max tokens
+ */
+ public final static String text_curie_001 = "text-curie-001";
+
+ /**
+ * Capable of straightforward tasks, very fast, and lower cost.
+ * 2049 max tokens
+ */
+ public final static String text_babbage_001 = "text-babbage-001";
+
+ /**
+ * Capable of very simple tasks, usually the fastest model in the GPT-3 series, and lowest cost.
+ * 2049 max tokens
+ */
+ public final static String text_ada_001 = "text-ada-001";
+
+ /**
+ * Most capable GPT-3 model. Can do any task the other models can do, often with higher quality.
+ * 2049 max tokens
+ */
+ public final static String davinci = "davinci";
+
+ /**
+ * Very capable, but faster and lower cost than Davinci.
+ * 2049 max tokens
+ */
+ public final static String curie = "curie";
+
+ /**
+ * Capable of straightforward tasks, very fast, and lower cost.
+ * 2049 max tokens
+ */
+ public final static String babbage = "babbage";
+
+ /**
+ * Capable of very simple tasks, usually the fastest model in the GPT-3 series, and lowest cost.
+ * 2049 max tokens
+ */
+ public final static String ada = "ada";
+
+
+ /**
+ * Models for CreateEditRequest
+ */
+ public final static String text_davinci_edit_001 = "text-davinci-edit-001";
+ public final static String code_davinci_edit_001 = "code-davinci-edit-001";
+
+
+ /**
+ * Models for CreateTranslationRequest and CreateTranscriptionRequest
+ * https://platform.openai.com/docs/models/whisper
+ */
+ public final static String whisper_1 = "whisper-1";
+
+
+ /**
+ * Models for FileTunes
+ * davinci, curie, babbage, ada
+ */
+
+ /**
+ * Models for CreateEmbeddingsRequest
+ * https://platform.openai.com/docs/models/embeddings
+ */
+ public final static String text_embedding_ada_002 = "text-embedding-ada-002";
+ public final static String text_search_ada_doc_001 = "text-search-ada-doc-001";
+
+
+ /**
+ * Models for CreateModerationRequest
+ * https://platform.openai.com/docs/models/moderation
+ */
+ /**
+ * Most capable moderation model. Accuracy will be slighlty higher than the stable model
+ */
+ public final static String text_moderation_latest = "text-moderation-latest";
+ /**
+ * Almost as capable as the latest model, but slightly older.
+ */
+ public final static String text_moderation_stable = "text-moderation-stable";
+}
diff --git a/src/main/java/com/github/WhiteMagic2014/gptApi/Moderations/CreateModerationRequest.java b/src/main/java/com/github/WhiteMagic2014/gptApi/Moderations/CreateModerationRequest.java
index c82f858..0c125ca 100755
--- a/src/main/java/com/github/WhiteMagic2014/gptApi/Moderations/CreateModerationRequest.java
+++ b/src/main/java/com/github/WhiteMagic2014/gptApi/Moderations/CreateModerationRequest.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.gptApi.Moderations.pojo.ModerationCategory;
import com.github.WhiteMagic2014.util.GptHttpUtil;
@@ -65,18 +66,22 @@ public CreateModerationRequest inputs(String... inputs) {
* If you use text-moderation-stable, we will provide advanced notice before updating the model.
* Accuracy of text-moderation-stable may be slightly lower than for text-moderation-latest.
*/
- private String model = "text-moderation-latest";
+ private String model = GptModel.text_moderation_latest;
public CreateModerationRequest modelLatest() {
- this.model = "text-moderation-latest";
+ this.model = GptModel.text_moderation_latest;
return this;
}
public CreateModerationRequest modelStable() {
- this.model = "text-moderation-stable";
+ this.model = GptModel.text_moderation_stable;
return this;
}
+ public CreateModerationRequest model(String model) {
+ this.model = model;
+ return this;
+ }
@Override
protected String sendHook() {